Include missed messages when catching up the agent

When a triggered message comes in, fetch all messages in that chat
since the last agent interaction and include them in the prompt.
Each message is formatted with timestamp and sender.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gavrielc
2026-01-31 19:29:09 +02:00
parent 4ec74e9120
commit f2afb11e71
2 changed files with 38 additions and 6 deletions

View File

@@ -72,3 +72,13 @@ export function getNewMessages(jids: string[], lastTimestamp: string): { message
return { messages: rows, newTimestamp };
}
export function getMessagesSince(chatJid: string, sinceTimestamp: string): NewMessage[] {
const sql = `
SELECT id, chat_jid, sender, content, timestamp
FROM messages
WHERE chat_jid = ? AND timestamp > ?
ORDER BY timestamp
`;
return db.prepare(sql).all(chatJid, sinceTimestamp) as NewMessage[];
}