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:
10
src/db.ts
10
src/db.ts
@@ -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[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user