From cbe33f4ba6d7e8b02353aa9b143b90df1f0f8096 Mon Sep 17 00:00:00 2001 From: gavrielc Date: Sat, 31 Jan 2026 19:30:32 +0200 Subject: [PATCH] Keep trigger in prompt, simplify message formatting Include the full message with @trigger so agent sees exactly what was written. Current message is already in missedMessages query so no need to add separately. Co-Authored-By: Claude Opus 4.5 --- src/index.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8c0f367..fad0456 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,24 +88,19 @@ async function processMessage(msg: NewMessage): Promise { if (!TRIGGER_PATTERN.test(content)) return; - const userMessage = content.replace(TRIGGER_PATTERN, '').trim(); - if (!userMessage) return; - // Get messages since last agent interaction to catch up the session const sinceTimestamp = lastAgentTimestamp[msg.chat_jid] || ''; const missedMessages = getMessagesSince(msg.chat_jid, sinceTimestamp); // Build prompt with conversation history - let prompt = ''; - for (const m of missedMessages) { - if (m.id === msg.id) continue; // Skip current message, we'll add it at the end + const lines = missedMessages.map(m => { const time = new Date(m.timestamp).toLocaleTimeString(); - const sender = m.sender.split('@')[0]; // Extract phone number or name - prompt += `[${time}] ${sender}: ${m.content}\n`; - } - const time = new Date(msg.timestamp).toLocaleTimeString(); - const sender = msg.sender.split('@')[0]; - prompt += `[${time}] ${sender}: ${userMessage}`; + const sender = m.sender.split('@')[0]; + return `[${time}] ${sender}: ${m.content}`; + }); + const prompt = lines.join('\n'); + + if (!prompt) return; logger.info({ group: group.name, messageCount: missedMessages.length }, 'Processing message'); const response = await runAgent(group, prompt);