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:
@@ -27,6 +27,8 @@ Single Node.js process that connects to WhatsApp, routes messages to Claude Agen
|
|||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
|
Run commands directly—don't tell the user to run them.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev # Run with hot reload
|
npm run dev # Run with hot reload
|
||||||
npm run build # Compile TypeScript
|
npm run build # Compile TypeScript
|
||||||
|
|||||||
11
src/index.ts
11
src/index.ts
@@ -36,6 +36,14 @@ let sessions: Session = {};
|
|||||||
let registeredGroups: Record<string, RegisteredGroup> = {};
|
let registeredGroups: Record<string, RegisteredGroup> = {};
|
||||||
let lastAgentTimestamp: Record<string, string> = {};
|
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 {
|
function loadJson<T>(filePath: string, defaultValue: T): T {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
@@ -107,7 +115,10 @@ async function processMessage(msg: NewMessage): Promise<void> {
|
|||||||
if (!prompt) return;
|
if (!prompt) return;
|
||||||
|
|
||||||
logger.info({ group: group.name, messageCount: missedMessages.length }, 'Processing message');
|
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);
|
const response = await runAgent(group, prompt, msg.chat_jid);
|
||||||
|
await setTyping(msg.chat_jid, false);
|
||||||
|
|
||||||
// Update last agent timestamp
|
// Update last agent timestamp
|
||||||
lastAgentTimestamp[msg.chat_jid] = msg.timestamp;
|
lastAgentTimestamp[msg.chat_jid] = msg.timestamp;
|
||||||
|
|||||||
Reference in New Issue
Block a user