From aa6dcf39d72ae5db24d18cd8514442dfcdc660ee Mon Sep 17 00:00:00 2001 From: Gavriel Date: Sun, 1 Feb 2026 15:10:42 +0200 Subject: [PATCH] Add typing indicator while agent is processing Shows "typing..." in WhatsApp while the agent container is running. Uses Baileys sendPresenceUpdate with 'composing' and 'paused' states. Co-Authored-By: Claude Opus 4.5 --- CLAUDE.md | 2 ++ src/index.ts | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 8182e2d..1139cae 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -27,6 +27,8 @@ Single Node.js process that connects to WhatsApp, routes messages to Claude Agen ## Development +Run commands directly—don't tell the user to run them. + ```bash npm run dev # Run with hot reload npm run build # Compile TypeScript diff --git a/src/index.ts b/src/index.ts index 461246e..11f5c13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,6 +36,14 @@ let sessions: Session = {}; let registeredGroups: Record = {}; let lastAgentTimestamp: Record = {}; +async function setTyping(jid: string, isTyping: boolean): Promise { + try { + await sock.sendPresenceUpdate(isTyping ? 'composing' : 'paused', jid); + } catch (err) { + logger.debug({ jid, err }, 'Failed to update typing status'); + } +} + function loadJson(filePath: string, defaultValue: T): T { try { if (fs.existsSync(filePath)) { @@ -107,7 +115,10 @@ async function processMessage(msg: NewMessage): Promise { if (!prompt) return; logger.info({ group: group.name, messageCount: missedMessages.length }, 'Processing message'); + + await setTyping(msg.chat_jid, true); const response = await runAgent(group, prompt, msg.chat_jid); + await setTyping(msg.chat_jid, false); // Update last agent timestamp lastAgentTimestamp[msg.chat_jid] = msg.timestamp;