Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat: forward incoming ChatPresence (typing) events via webhook (#547)

Aldino Kemalc428afaf9b2a
diff --git a/docs/webhook-payload.md b/docs/webhook-payload.md
index 9801afb3..3999ca66 100644
--- a/docs/webhook-payload.md
+++ b/docs/webhook-payload.md
@@ -20,6 +20,7 @@ The following events can be received via webhook:
| `message.edited` | Edited messages |
| `message.ack` | Delivery and read receipts |
| `message.deleted` | Messages deleted for the user |
+| `chat_presence` | Typing and recording indicators from contacts |
| `group.participants` | Group member join/leave/promote/demote events |
| `group.joined` | You were added to a group |
| `newsletter.joined` | You subscribed to a newsletter/channel |
@@ -138,7 +139,7 @@ All webhook payloads follow a consistent top-level structure:
| **Field** | **Type** | **Description** |
|-------------|----------|---------------------------------------------------------------------------------------------------------------------|
-| `event` | string | Event type: `message`, `message.reaction`, `message.revoked`, `message.edited`, `message.ack`, `message.deleted`, `group.participants`, `group.joined`, `newsletter.joined`, `newsletter.left`, `newsletter.message`, `newsletter.mute`, `call.offer` |
+| `event` | string | Event type: `message`, `message.reaction`, `message.revoked`, `message.edited`, `message.ack`, `message.deleted`, `chat_presence`, `group.participants`, `group.joined`, `newsletter.joined`, `newsletter.left`, `newsletter.message`, `newsletter.mute`, `call.offer` |
| `device_id` | string | JID of the device that received this event (e.g., `[email protected]`) |
| `payload` | object | Event-specific payload data |
@@ -278,6 +279,105 @@ Triggered when a message is read by the recipient (they opened the chat and saw
| `payload.receipt_type` | string | Type of receipt: `"delivered"`, `"read"`, etc. |
| `payload.receipt_type_description` | string | Human-readable description of the receipt type |
+## Chat Presence Events
+
+Chat presence events are triggered when a contact starts or stops typing (or recording audio) in a chat.
+These events use the `chat_presence` event type and are useful for implementing message batching strategies.
+
+**Note:** WhatsApp only sends chat presence updates when the client is marked as online. GOWA automatically marks
+itself as online upon connection, so no additional configuration is needed.
+
+### User Typing
+
+Triggered when a user starts typing a text message.
+
+```json
+{
+ "event": "chat_presence",
+ "device_id": "[email protected]",
+ "timestamp": "2026-01-22T12:00:00Z",
+ "payload": {
+ "from": "[email protected]",
+ "chat_id": "[email protected]",
+ "state": "composing",
+ "media": "",
+ "is_group": false
+ }
+}
+```
+
+### User Stopped Typing
+
+Triggered when a user stops typing (pauses or clears the input field).
+
+```json
+{
+ "event": "chat_presence",
+ "device_id": "[email protected]",
+ "timestamp": "2026-01-22T12:00:05Z",
+ "payload": {
+ "from": "[email protected]",
+ "chat_id": "[email protected]",
+ "state": "paused",
+ "media": "",
+ "is_group": false
+ }
+}
+```
+
+### User Recording Audio
+
+Triggered when a user starts recording a voice message.
+
+```json
+{
+ "event": "chat_presence",
+ "device_id": "[email protected]",
+ "timestamp": "2026-01-22T12:01:00Z",
+ "payload": {
+ "from": "[email protected]",
+ "chat_id": "[email protected]",
+ "state": "composing",
+ "media": "audio",
+ "is_group": false
+ }
+}
+```
+
+### Group Typing
+
+Triggered when a user starts typing in a group chat.
+
+```json
+{
+ "event": "chat_presence",
+ "device_id": "[email protected]",
+ "timestamp": "2026-01-22T12:02:00Z",
+ "payload": {
+ "from": "[email protected]",
+ "from_lid": "251556368777322@lid",
+ "chat_id": "[email protected]",
+ "state": "composing",
+ "media": "",
+ "is_group": true
+ }
+}
+```
+
+### Chat Presence Event Fields
+
+| **Field** | **Type** | **Description** |
+|--------------------|----------|--------------------------------------------------------------------|
+| `event` | string | Always `"chat_presence"` for typing events |
+| `device_id` | string | JID of the device that received this event |
+| `timestamp` | string | RFC3339 formatted timestamp when the event was processed |
+| `payload.from` | string | JID of the user who is typing (e.g., `[email protected]`)|
+| `payload.from_lid` | string | LID of the user (if available, typically in group chats) |
+| `payload.chat_id` | string | Chat identifier (individual or group) |
+| `payload.state` | string | Typing state: `"composing"` (typing) or `"paused"` (stopped) |
+| `payload.media` | string | Media type: `""` (text message) or `"audio"` (voice recording) |
+| `payload.is_group` | boolean | Whether this is a group chat |
+
## Group Events
Group events are triggered when group metadata changes, including member join/leave events, admin promotions/demotions,
diff --git a/src/infrastructure/whatsapp/event_chat_presence.go b/src/infrastructure/whatsapp/event_chat_presence.go
new file mode 100644
index 00000000..bcd3cef0
--- /dev/null
+++ b/src/infrastructure/whatsapp/event_chat_presence.go
@@ -0,0 +1,80 @@
+package whatsapp
+
+import (
+ "context"
+ "time"
+
+ "github.com/aldinokemal/go-whatsapp-web-multidevice/config"
+ "github.com/sirupsen/logrus"
+ "go.mau.fi/whatsmeow"
+ "go.mau.fi/whatsmeow/types"
+ "go.mau.fi/whatsmeow/types/events"
+)
+
+// handleChatPresence handles incoming chat presence (typing notification) events.
+// These events are emitted when a user starts or stops typing in a chat.
+// Note: WhatsApp only sends these updates when the client is marked as online.
+func handleChatPresence(ctx context.Context, evt *events.ChatPresence, deviceID string, client *whatsmeow.Client) {
+ if evt.State == types.ChatPresenceComposing {
+ if evt.Media == types.ChatPresenceMediaAudio {
+ log.Infof("%s is recording audio in %s", evt.Sender.ToNonAD(), evt.Chat.ToNonAD())
+ } else {
+ log.Infof("%s is typing in %s", evt.Sender.ToNonAD(), evt.Chat.ToNonAD())
+ }
+ } else {
+ log.Infof("%s stopped typing in %s", evt.Sender.ToNonAD(), evt.Chat.ToNonAD())
+ }
+
+ // Forward chat presence event to webhook if configured
+ if len(config.WhatsappWebhook) > 0 {
+ go func(e *events.ChatPresence, c *whatsmeow.Client) {
+ webhookCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ defer cancel()
+ if err := forwardChatPresenceToWebhook(webhookCtx, e, deviceID, c); err != nil {
+ logrus.Errorf("Failed to forward chat_presence event to webhook: %v", err)
+ }
+ }(evt, client)
+ }
+}
+
+// createChatPresencePayload creates a webhook payload for chat presence (typing) events.
+func createChatPresencePayload(ctx context.Context, evt *events.ChatPresence, deviceID string, client *whatsmeow.Client) map[string]any {
+ body := make(map[string]any)
+ payload := make(map[string]any)
+
+ // Resolve sender JID (convert LID to phone number if needed)
+ senderJID := evt.Sender
+ if senderJID.Server == "lid" {
+ payload["from_lid"] = senderJID.ToNonAD().String()
+ }
+ normalizedSenderJID := NormalizeJIDFromLID(ctx, senderJID, client)
+ payload["from"] = normalizedSenderJID.ToNonAD().String()
+
+ // Chat where the presence event occurred
+ payload["chat_id"] = evt.Chat.ToNonAD().String()
+
+ // Typing state: "composing" or "paused"
+ payload["state"] = string(evt.State)
+
+ // Media type: "" (text) or "audio" (recording voice message)
+ payload["media"] = string(evt.Media)
+
+ // Whether this is a group chat
+ payload["is_group"] = evt.IsGroup
+
+ // Wrap in body structure
+ body["event"] = "chat_presence"
+ body["timestamp"] = time.Now().Format(time.RFC3339)
+ if deviceID != "" {
+ body["device_id"] = deviceID
+ }
+ body["payload"] = payload
+
+ return body
+}
+
+// forwardChatPresenceToWebhook forwards chat presence events to the configured webhook URLs.
+func forwardChatPresenceToWebhook(ctx context.Context, evt *events.ChatPresence, deviceID string, client *whatsmeow.Client) error {
+ payload := createChatPresencePayload(ctx, evt, deviceID, client)
+ return forwardPayloadToConfiguredWebhooks(ctx, payload, "chat_presence")
+}
diff --git a/src/infrastructure/whatsapp/event_handler.go b/src/infrastructure/whatsapp/event_handler.go
index 09ff4638..0e01ee7b 100644
--- a/src/infrastructure/whatsapp/event_handler.go
+++ b/src/infrastructure/whatsapp/event_handler.go
@@ -51,6 +51,8 @@ func handler(ctx context.Context, instance *DeviceInstance, rawEvt any) {
handleArchive(ctx, evt, chatStorageRepo, client)
case *events.Presence:
handlePresence(ctx, evt)
+ case *events.ChatPresence:
+ handleChatPresence(ctx, evt, instance.JID(), client)
case *events.HistorySync:
handleHistorySync(ctx, evt, chatStorageRepo, client)
case *events.AppState: