openclaw icon indicating copy to clipboard operation
openclaw copied to clipboard

[Feature]: WhatsApp Message Debouncing for Batching Rapid Messages

Open juanpablodlc opened this issue 10 months ago • 0 comments

Summary

Allow users to configure a debounce window that batches rapid consecutive messages from the same sender into a single response.

Problem

Users who send multiple short messages in quick succession (e.g., "Hey!", "how are you?", "I was wondering...") trigger separate agent runs for each message instead of having them combined into one coherent conversation turn.

Proposed Solution

Add a debounceMs configuration option to WhatsApp channel settings:

{
  "channels": {
    "whatsapp": {
      "debounceMs": 5000  // wait 5 seconds for more messages before responding
    }
  }
}


When enabled, messages from the same sender within the debounce window are combined with newlines.

Implementation Hints
See the conversation in Discord #batch-processing-of-messages for details. The implementation involves:
  1. Adding debounceMs to WhatsApp config schema/types
  2. Adding message buffering in src/web/inbound/monitor.ts
  3. Wiring it through src/web/auto-reply/monitor.ts and src/web/accounts.ts

Krill initial thoughts

Implement something like this:

Changes Made

Config Schema (src/config/zod-schema.providers-whatsapp.ts) Added debounceMs field (default: 0, meaning disabled)

Config Types (src/config/types.whatsapp.ts) Added debounceMs?: number to both WhatsAppConfig and WhatsAppAccountConfig

UI Hints (src/config/schema.ts) Added label and help text for the new config option

Message Buffering (src/web/inbound/monitor.ts) Added debounce logic that buffers messages from the same sender Combines multiple messages into one with \n separators For DMs: batches by sender (from) For Groups: batches by chatId

Account Resolution (src/web/accounts.ts) Added debounceMs to ResolvedWhatsAppAccount type Wires config through to the monitor

Usage
{
  "channels": {
    "whatsapp": {
      "debounceMs": 5000  // wait 5 seconds for more messages before responding
    }
  }
}
Or per-account:
{
  "channels": {
    "whatsapp": {
      "accounts": {
        "default": {
          "debounceMs": 5000
        }
      }
    }
  }
}

juanpablodlc avatar Jan 15 '26 17:01 juanpablodlc