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 <noreply@anthropic.com>
This commit is contained in:
Gavriel
2026-02-01 15:10:42 +02:00
parent 2026eaf53d
commit aa6dcf39d7
2 changed files with 13 additions and 0 deletions

View File

@@ -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

View File

@@ -36,6 +36,14 @@ let sessions: Session = {};
let registeredGroups: Record<string, RegisteredGroup> = {};
let lastAgentTimestamp: Record<string, string> = {};
async function setTyping(jid: string, isTyping: boolean): Promise<void> {
try {
await sock.sendPresenceUpdate(isTyping ? 'composing' : 'paused', jid);
} catch (err) {
logger.debug({ jid, err }, 'Failed to update typing status');
}
}
function loadJson<T>(filePath: string, defaultValue: T): T {
try {
if (fs.existsSync(filePath)) {
@@ -107,7 +115,10 @@ async function processMessage(msg: NewMessage): Promise<void> {
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;