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: add auto-reject incoming calls feature (#563)

Aldino Kemal5c193bc8afb4
diff --git a/docs/webhook-payload.md b/docs/webhook-payload.md
index faa2fb12..75864b72 100644
--- a/docs/webhook-payload.md
+++ b/docs/webhook-payload.md
@@ -26,6 +26,7 @@ The following events can be received via webhook:
| `newsletter.left` | You unsubscribed from a newsletter |
| `newsletter.message` | New message(s) posted in a newsletter |
| `newsletter.mute` | Newsletter mute setting changed |
+| `call.offer` | Incoming call received |
## Event Filtering
@@ -49,6 +50,9 @@ WHATSAPP_WEBHOOK_EVENTS=group.participants
# Receive newsletter events
WHATSAPP_WEBHOOK_EVENTS=newsletter.joined,newsletter.left,newsletter.message,newsletter.mute
+# Receive call events
+WHATSAPP_WEBHOOK_EVENTS=call.offer
+
# Receive all group and newsletter events
WHATSAPP_WEBHOOK_EVENTS=group.participants,group.joined,newsletter.joined,newsletter.left,newsletter.message
```
@@ -134,7 +138,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` |
+| `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` |
| `device_id` | string | JID of the device that received this event (e.g., `[email protected]`) |
| `payload` | object | Event-specific payload data |
@@ -463,6 +467,80 @@ Triggered when you mute or unmute a newsletter.
| `payload.messages[].views_count`| number | Number of views (if available) |
| `payload.messages[].reaction_counts`| object | Reaction emoji counts (if available) |
+## Call Events
+
+Call events are triggered when you receive an incoming WhatsApp call. You can optionally auto-reject calls using the
+`WHATSAPP_AUTO_REJECT_CALL` environment variable or `--auto-reject-call` CLI flag.
+
+### Call Offer
+
+Triggered when an incoming call is received.
+
+```json
+{
+ "event": "call.offer",
+ "device_id": "[email protected]",
+ "timestamp": "2026-02-05T12:00:00Z",
+ "payload": {
+ "call_id": "ABC123DEF456",
+ "from": "[email protected]",
+ "auto_rejected": false,
+ "remote_platform": "android",
+ "remote_version": "2.24.1.5"
+ }
+}
+```
+
+### Call Offer with Auto-Reject Enabled
+
+When `WHATSAPP_AUTO_REJECT_CALL=true`, calls are automatically rejected and the webhook includes this status:
+
+```json
+{
+ "event": "call.offer",
+ "device_id": "[email protected]",
+ "timestamp": "2026-02-05T12:00:00Z",
+ "payload": {
+ "call_id": "ABC123DEF456",
+ "from": "[email protected]",
+ "auto_rejected": true,
+ "remote_platform": "android",
+ "remote_version": "2.24.1.5",
+ "group_jid": "[email protected]"
+ }
+}
+```
+
+### Call Event Fields
+
+| **Field** | **Type** | **Description** |
+|---------------------------|----------|------------------------------------------------------------|
+| `event` | string | Always `"call.offer"` for call events |
+| `device_id` | string | JID of the device that received this event |
+| `timestamp` | string | RFC3339 formatted timestamp when the call was received |
+| `payload.call_id` | string | Unique identifier for the call |
+| `payload.from` | string | JID of the caller |
+| `payload.auto_rejected` | boolean | Whether the call was auto-rejected |
+| `payload.remote_platform` | string | Platform of the caller (e.g., `"android"`, `"ios"`) |
+| `payload.remote_version` | string | WhatsApp version of the caller |
+| `payload.group_jid` | string | Group JID if this is a group call (optional) |
+
+### Configuration
+
+**Environment Variable:**
+
+```bash
+# Auto-reject all incoming calls
+WHATSAPP_AUTO_REJECT_CALL=true
+```
+
+**CLI Flag:**
+
+```bash
+# Auto-reject all incoming calls
+./whatsapp rest --auto-reject-call=true
+```
+
## Media Messages
### Image Message
@@ -911,6 +989,15 @@ app.post('/webhook', (req, res) => {
mute: data.payload.mute
});
break;
+
+ case 'call.offer':
+ console.log('Incoming call:', {
+ call_id: data.payload.call_id,
+ from: data.payload.from,
+ auto_rejected: data.payload.auto_rejected,
+ platform: data.payload.remote_platform
+ });
+ break;
}
res.status(200).send('OK');
diff --git a/readme.md b/readme.md
index 57a30bcf..664d785d 100644
--- a/readme.md
+++ b/readme.md
@@ -127,6 +127,12 @@ Download:
| `message.ack` | Delivery and read receipts |
| `message.deleted` | Messages deleted for the user |
| `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 |
+ | `newsletter.left` | You unsubscribed from a newsletter |
+ | `newsletter.message` | New message(s) posted in a newsletter |
+ | `newsletter.mute` | Newsletter mute setting changed |
+ | `call.offer` | Incoming call received |
If not configured (empty), all events will be forwarded.
- **Webhook TLS Configuration**
diff --git a/src/cmd/root.go b/src/cmd/root.go
index 3d5d3c10..6722b7a8 100644
--- a/src/cmd/root.go
+++ b/src/cmd/root.go
@@ -143,6 +143,9 @@ func initEnvConfig() {
if viper.IsSet("whatsapp_account_validation") {
config.WhatsappAccountValidation = viper.GetBool("whatsapp_account_validation")
}
+ if viper.IsSet("whatsapp_auto_reject_call") {
+ config.WhatsappAutoRejectCall = viper.GetBool("whatsapp_auto_reject_call")
+ }
// Chatwoot settings
if viper.IsSet("chatwoot_enabled") {
@@ -281,6 +284,12 @@ func initFlags() {
config.WhatsappAccountValidation,
`enable or disable account validation --account-validation <true/false> | example: --account-validation=true`,
)
+ rootCmd.PersistentFlags().BoolVarP(
+ &config.WhatsappAutoRejectCall,
+ "auto-reject-call", "",
+ config.WhatsappAutoRejectCall,
+ `auto reject incoming calls --auto-reject-call <true/false> | example: --auto-reject-call=true`,
+ )
// Chatwoot flags
rootCmd.PersistentFlags().BoolVarP(
diff --git a/src/config/settings.go b/src/config/settings.go
index e2a8a7d9..1db89f39 100644
--- a/src/config/settings.go
+++ b/src/config/settings.go
@@ -34,6 +34,7 @@ var (
WhatsappWebhookInsecureSkipVerify = false // Skip TLS certificate verification for webhooks (insecure)
WhatsappWebhookEvents []string // Whitelist of events to forward to webhook (empty = all events)
WhatsappWebhookIncludeOutgoing = false // Include outgoing messages (sent from phone) in webhook notifications
+ WhatsappAutoRejectCall = false // Auto-reject incoming calls
WhatsappLogLevel = "ERROR"
WhatsappSettingMaxImageSize int64 = 20000000 // 20MB
WhatsappSettingMaxFileSize int64 = 50000000 // 50MB
diff --git a/src/infrastructure/whatsapp/event_call.go b/src/infrastructure/whatsapp/event_call.go
new file mode 100644
index 00000000..7bce9bc3
--- /dev/null
+++ b/src/infrastructure/whatsapp/event_call.go
@@ -0,0 +1,81 @@
+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/events"
+)
+
+// handleCallOffer handles incoming call events and optionally auto-rejects them
+func handleCallOffer(ctx context.Context, evt *events.CallOffer, deviceID string, client *whatsmeow.Client) {
+ logrus.Infof("Incoming call from %s (CallID: %s)", evt.CallCreator.String(), evt.CallID)
+
+ // Auto-reject call if configured
+ autoRejected := false
+ if config.WhatsappAutoRejectCall {
+ rejectCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
+ defer cancel()
+
+ if err := client.RejectCall(rejectCtx, evt.CallCreator, evt.CallID); err != nil {
+ logrus.Errorf("Failed to reject call from %s: %v", evt.CallCreator.String(), err)
+ } else {
+ autoRejected = true
+ logrus.Infof("Auto-rejected call from %s (CallID: %s)", evt.CallCreator.String(), evt.CallID)
+ }
+ }
+
+ // Forward call event to webhook if configured
+ if len(config.WhatsappWebhook) > 0 {
+ go func(e *events.CallOffer, c *whatsmeow.Client, rejected bool) {
+ webhookCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ defer cancel()
+ if err := forwardCallOfferToWebhook(webhookCtx, e, deviceID, c, rejected); err != nil {
+ logrus.Errorf("Failed to forward call event to webhook: %v", err)
+ }
+ }(evt, client, autoRejected)
+ }
+}
+
+// createCallOfferPayload creates a webhook payload for incoming call events
+func createCallOfferPayload(ctx context.Context, evt *events.CallOffer, deviceID string, client *whatsmeow.Client, autoRejected bool) map[string]any {
+ body := make(map[string]any)
+ payload := make(map[string]any)
+
+ // Add call details
+ payload["call_id"] = evt.CallID
+ payload["from"] = evt.CallCreator.ToNonAD().String()
+ payload["auto_rejected"] = autoRejected
+
+ // Add caller platform info if available
+ if evt.RemotePlatform != "" {
+ payload["remote_platform"] = evt.RemotePlatform
+ }
+ if evt.RemoteVersion != "" {
+ payload["remote_version"] = evt.RemoteVersion
+ }
+
+ // Add group JID if this is a group call
+ if !evt.GroupJID.IsEmpty() {
+ payload["group_jid"] = evt.GroupJID.ToNonAD().String()
+ }
+
+ // Wrap in body structure
+ body["event"] = "call.offer"
+ body["timestamp"] = evt.Timestamp.Format(time.RFC3339)
+ if deviceID != "" {
+ body["device_id"] = deviceID
+ }
+ body["payload"] = payload
+
+ return body
+}
+
+// forwardCallOfferToWebhook forwards incoming call events to the configured webhook URLs
+func forwardCallOfferToWebhook(ctx context.Context, evt *events.CallOffer, deviceID string, client *whatsmeow.Client, autoRejected bool) error {
+ payload := createCallOfferPayload(ctx, evt, deviceID, client, autoRejected)
+ return forwardPayloadToConfiguredWebhooks(ctx, payload, "call.offer")
+}
diff --git a/src/infrastructure/whatsapp/event_handler.go b/src/infrastructure/whatsapp/event_handler.go
index d45db690..70d99567 100644
--- a/src/infrastructure/whatsapp/event_handler.go
+++ b/src/infrastructure/whatsapp/event_handler.go
@@ -65,6 +65,8 @@ func handler(ctx context.Context, instance *DeviceInstance, rawEvt any) {
handleNewsletterLiveUpdate(ctx, evt, instance.JID(), client)
case *events.NewsletterMuteChange:
handleNewsletterMuteChange(ctx, evt, instance.JID(), client)
+ case *events.CallOffer:
+ handleCallOffer(ctx, evt, instance.JID(), client)
}
instance.UpdateStateFromClient()