GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
feat: add comprehensive Chatwoot integration documentation
Aldino Kemal909b6e6c8fd4
diff --git a/docs/chatwoot.md b/docs/chatwoot.mdnew file mode 100644index 00000000..ef663a2a--- /dev/null+++ b/docs/chatwoot.md@@ -0,0 +1,353 @@+# Chatwoot Integration++This document provides comprehensive documentation for integrating Go WhatsApp Web Multidevice with Chatwoot for customer support.++## Overview++The Chatwoot integration allows you to:+- Receive WhatsApp messages in your Chatwoot inbox+- Reply to WhatsApp messages directly from Chatwoot+- Support text messages, images, audio, video, and file attachments+- Handle both individual chats and group conversations++## Prerequisites++Before setting up the integration, ensure you have:++1. **Go WhatsApp Web Multidevice** running and accessible via a public URL+2. **Chatwoot** instance (self-hosted or cloud) with admin access+3. **API Channel** inbox created in Chatwoot+4. At least one WhatsApp device connected and logged in++## Configuration++### Environment Variables++| Variable | Required | Default | Description |+|----------|----------|---------|-------------|+| `CHATWOOT_ENABLED` | Yes | `false` | Enable Chatwoot integration |+| `CHATWOOT_URL` | Yes | - | Your Chatwoot instance URL (e.g., `https://app.chatwoot.com`) |+| `CHATWOOT_API_TOKEN` | Yes | - | API access token from Chatwoot |+| `CHATWOOT_ACCOUNT_ID` | Yes | - | Your Chatwoot account ID |+| `CHATWOOT_INBOX_ID` | Yes | - | The inbox ID for WhatsApp messages |+| `CHATWOOT_DEVICE_ID` | No | - | Specific device ID for outbound messages (required for multi-device setups) |++### Configuration Examples++**Environment File (.env):**+```bash+CHATWOOT_ENABLED=true+CHATWOOT_URL=https://app.chatwoot.com+CHATWOOT_API_TOKEN=your_api_token_here+CHATWOOT_ACCOUNT_ID=12345+CHATWOOT_INBOX_ID=67890+CHATWOOT_DEVICE_ID=my-whatsapp-device+```++**CLI Flags:**+```bash+./whatsapp rest \+ --chatwoot-enabled=true \+ --chatwoot-device-id="my-device-id"+```++**Docker Compose:**+```yaml+services:+ whatsapp-api:+ image: aldinokemal2104/go-whatsapp-web-multidevice:latest+ environment:+ - CHATWOOT_ENABLED=true+ - CHATWOOT_URL=https://app.chatwoot.com+ - CHATWOOT_API_TOKEN=your_api_token+ - CHATWOOT_ACCOUNT_ID=12345+ - CHATWOOT_INBOX_ID=67890+ - CHATWOOT_DEVICE_ID=my-device+ command: rest+```++## Chatwoot Setup++### Step 1: Create an API Channel Inbox++1. Log in to your Chatwoot dashboard+2. Navigate to **Settings** > **Inboxes**+3. Click **Add Inbox**+4. Select **API** as the channel type+5. Configure the inbox:+ - **Name**: WhatsApp (or any descriptive name)+ - **Webhook URL**: Leave empty for now (we'll configure this in Step 4)+6. Click **Create Inbox**+7. Note down the **Inbox ID** (visible in the URL or inbox settings)++### Step 2: Get Your API Token++1. Navigate to **Settings** > **Profile Settings**+2. Scroll to **Access Token** section+3. Copy your API access token++### Step 3: Find Your Account ID++Your account ID is visible in the URL when logged into Chatwoot:+```+https://app.chatwoot.com/app/accounts/[ACCOUNT_ID]/dashboard+```++### Step 4: Configure the Webhook++1. Navigate to **Settings** > **Integrations** > **Webhooks**+2. Click **Add new webhook**+3. Configure:+ - **URL**: `https://your-whatsapp-api.com/chatwoot/webhook`+ - **Events**: Select `message_created`+4. Click **Create**++> **Important:** The webhook URL must be publicly accessible. If you're running locally, use a tunneling service like ngrok.++## Multi-Device Setup++When running with multiple WhatsApp devices, you **must** specify which device should handle Chatwoot outbound messages using `CHATWOOT_DEVICE_ID`.++### Finding Your Device ID++1. Access your WhatsApp API at `http://your-api:3000`+2. Navigate to the device management section+3. Note the Device ID of the device you want to use for Chatwoot++Alternatively, use the API:+```bash+curl http://your-api:3000/devices+```++### Configuration++```bash+# Using JID format++# Or using custom device ID+CHATWOOT_DEVICE_ID=my-support-device+```++### Important Notes++- If `CHATWOOT_DEVICE_ID` is **not set** and **only one device** is registered, that device will be used automatically+- If `CHATWOOT_DEVICE_ID` is **not set** and **multiple devices** exist, outbound messages will **fail**+- If the specified device is not found or not connected, outbound messages will fail with a `DEVICE_NOT_AVAILABLE` error++## Supported Features++### Incoming Messages (WhatsApp → Chatwoot)++| Message Type | Supported | Notes |+|--------------|-----------|-------|+| Text | ✅ | Full text content preserved |+| Images | ✅ | Displayed as attachments |+| Audio | ✅ | Displayed as attachments |+| Video | ✅ | Displayed as attachments |+| Documents | ✅ | Displayed as attachments |+| Stickers | ✅ | Displayed as image attachments |+| Location | ✅ | Shown as text with coordinates |+| Contacts | ✅ | vCard information preserved |++### Outgoing Messages (Chatwoot → WhatsApp)++| Message Type | Supported | Notes |+|--------------|-----------|-------|+| Text | ✅ | - |+| Images | ✅ | Sent with optional caption |+| Audio | ✅ | Sent as voice note (PTT) |+| Video | ✅ | - |+| Files | ✅ | Any file type supported |++### Group Support++- Groups are automatically detected by JID format (`@g.us`)+- Group name is used as contact name in Chatwoot+- Replies go to the correct group chat+- Group messages include sender name prefix++## Architecture++```+┌─────────────────────┐ ┌──────────────────────┐+│ WhatsApp User │ │ Chatwoot │+│ │ │ │+└─────────┬───────────┘ └───────────┬──────────┘+ │ │+ │ Incoming │ Outgoing+ │ Message │ Message+ ▼ ▼+┌─────────────────────────────────────────────────────────┐+│ Go WhatsApp Web Multidevice │+│ │+│ ┌─────────────────┐ ┌─────────────────────────┐ │+│ │ Event Handler │ │ /chatwoot/webhook │ │+│ │ (Message Event) │ │ (POST endpoint) │ │+│ └────────┬────────┘ └───────────┬─────────────┘ │+│ │ │ │+│ │ Forward to │ Resolve Device │+│ │ Chatwoot API │ & Send Message │+│ ▼ ▼ │+│ ┌─────────────────┐ ┌─────────────────────────┐ │+│ │ Chatwoot Client │ │ Device Manager │ │+│ │ (Create Message)│ │ (CHATWOOT_DEVICE_ID) │ │+│ └─────────────────┘ └─────────────────────────┘ │+└─────────────────────────────────────────────────────────┘+```++### Message Flow++1. **Incoming (WhatsApp → Chatwoot)**:+ - WhatsApp message received by connected device+ - Event handler processes the message+ - Message forwarded to Chatwoot API+ - Contact/conversation created if needed+ - Message appears in Chatwoot inbox++2. **Outgoing (Chatwoot → WhatsApp)**:+ - Agent replies in Chatwoot+ - Chatwoot sends webhook to `/chatwoot/webhook`+ - Handler resolves device from `CHATWOOT_DEVICE_ID` or default+ - Message sent via WhatsApp+ - Delivery confirmed++## Troubleshooting++### Outbound Messages Not Sending++**Symptoms:** Messages typed in Chatwoot are not delivered to WhatsApp++**Possible Causes & Solutions:**++1. **Device not specified or not found**+ - Check logs for "Failed to resolve device" errors+ - Ensure `CHATWOOT_DEVICE_ID` is set correctly+ - Verify the device is registered: `curl http://your-api:3000/devices`++2. **Webhook not configured**+ - Verify the webhook URL in Chatwoot settings+ - Ensure the URL is publicly accessible+ - Check that `message_created` event is selected++3. **Device not logged in**+ - Check device status: `curl http://your-api:3000/devices/{device_id}/status`+ - Reconnect the device if disconnected++4. **CHATWOOT_ENABLED not set**+ - Verify `CHATWOOT_ENABLED=true` in your configuration++### Incoming Messages Not Appearing in Chatwoot++**Symptoms:** WhatsApp messages are not showing in Chatwoot inbox++**Possible Causes & Solutions:**++1. **Chatwoot not enabled**+ - Verify `CHATWOOT_ENABLED=true` in configuration++2. **Invalid API credentials**+ - Double-check `CHATWOOT_API_TOKEN`+ - Verify `CHATWOOT_ACCOUNT_ID` and `CHATWOOT_INBOX_ID`++3. **Contact/Conversation issues**+ - Check API logs for contact creation errors+ - Verify Chatwoot inbox is properly configured++4. **Network connectivity**+ - Ensure the API server can reach Chatwoot URL+ - Check for firewall rules blocking outbound connections++### Debug Logging++Enable debug mode to see detailed Chatwoot integration logs:++```bash+./whatsapp rest --debug=true+```++Or via environment variable:+```bash+APP_DEBUG=true ./whatsapp rest+```++Look for log entries starting with:+- `Chatwoot Webhook:` - Webhook processing+- `Chatwoot:` - API operations (contact/conversation/message creation)++### Common Error Messages++| Error | Meaning | Solution |+|-------|---------|----------|+| `DEVICE_NOT_AVAILABLE` | No device found for sending | Set `CHATWOOT_DEVICE_ID` or ensure one device is registered |+| `device not found` | Specified device ID doesn't exist | Check device ID spelling and registration |+| `device id is required` | No device ID and multiple devices exist | Set `CHATWOOT_DEVICE_ID` |+| `failed to create contact` | Chatwoot API error | Verify API token and account permissions |+| `Invalid payload` | Malformed webhook request | Check Chatwoot webhook configuration |++### Verifying Webhook Connectivity++Test your webhook endpoint:++```bash+curl -X POST https://your-api.com/chatwoot/webhook \+ -H "Content-Type: application/json" \+ -d '{+ "event": "message_created",+ "message_type": "outgoing",+ "content": "Test message",+ "private": false,+ "conversation": {+ "id": 1,+ "meta": {+ "sender": {+ "id": 1,+ "phone_number": "+1234567890"+ }+ }+ }+ }'+```++Expected response: `200 OK` or error with details++## Best Practices++1. **Use a dedicated device** for Chatwoot integration in production+2. **Set up monitoring** for device connection status+3. **Configure auto-reconnect** to maintain service availability+4. **Test webhook connectivity** before going live+5. **Use HTTPS** for webhook URLs in production+6. **Set `CHATWOOT_DEVICE_ID`** explicitly in multi-device environments+7. **Monitor logs** for failed message deliveries++## Security Considerations++- Keep `CHATWOOT_API_TOKEN` secure and rotate periodically+- Use HTTPS for all webhook communications+- Consider network-level restrictions on the webhook endpoint+- Monitor for unusual activity in Chatwoot logs+- Use strong authentication for the WhatsApp API (`APP_BASIC_AUTH`)++## API Reference++### Webhook Endpoint++**URL:** `POST /chatwoot/webhook`++**Headers:**+- `Content-Type: application/json`++**Request Body:** Standard Chatwoot webhook payload++**Response Codes:**+- `200 OK` - Message processed (or skipped)+- `503 Service Unavailable` - No device available++### Related Endpoints++| Endpoint | Method | Description |+|----------|--------|-------------|+| `/devices` | GET | List all registered devices |+| `/devices/{id}` | GET | Get device details |+| `/devices/{id}/status` | GET | Check device connection status |diff --git a/src/.env.example b/src/.env.exampleindex 70b9b435..9001706c 100644--- a/src/.env.example+++ b/src/.env.example@@ -19,6 +19,7 @@ WHATSAPP_WEBHOOK=https://webhook.site/07b69616-5943-4c7f-a8be-db4819df699e,httpsWHATSAPP_WEBHOOK_SECRET=super-secret-keyWHATSAPP_WEBHOOK_INSECURE_SKIP_VERIFY=falseWHATSAPP_WEBHOOK_EVENTS=message,message.reaction,message.revoked,message.edited,message.ack,message.deleted,group.participants+WHATSAPP_WEBHOOK_INCLUDE_OUTGOING=falseWHATSAPP_ACCOUNT_VALIDATION=trueWHATSAPP_CHAT_STORAGE=true@@ -28,3 +29,4 @@ CHATWOOT_URL=https://app.chatwoot.comCHATWOOT_API_TOKEN=xxxxxxxxCHATWOOT_ACCOUNT_ID=111111CHATWOOT_INBOX_ID=000000+CHATWOOT_DEVICE_ID=diff --git a/src/cmd/rest.go b/src/cmd/rest.goindex 6bb003e3..3f9f12ae 100644--- a/src/cmd/rest.go+++ b/src/cmd/rest.go@@ -109,11 +109,6 @@ func restServer(_ *cobra.Command, _ []string) {rest.InitRestGroup(r, groupUsecase)rest.InitRestNewsletter(r, newsletterUsecase)websocket.RegisterRoutes(r, appUsecase)-- if config.ChatwootEnabled {- chatwootHandler := rest.NewChatwootHandler(appUsecase, sendUsecase)- r.Post("/chatwoot/webhook", chatwootHandler.HandleWebhook)- }}// Device management routes (no device_id required)@@ -123,6 +118,12 @@ func restServer(_ *cobra.Command, _ []string) {headerDeviceGroup := apiGroup.Group("", middleware.DeviceMiddleware(dm))registerDeviceScopedRoutes(headerDeviceGroup)+ // Chatwoot webhook - handles device resolution internally (not device-scoped)+ if config.ChatwootEnabled {+ chatwootHandler := rest.NewChatwootHandler(appUsecase, sendUsecase, dm)+ apiGroup.Post("/chatwoot/webhook", chatwootHandler.HandleWebhook)+ }+apiGroup.Get("/", func(c *fiber.Ctx) error {return c.Render("views/index", fiber.Map{"AppHost": fmt.Sprintf("%s://%s", c.Protocol(), c.Hostname()),diff --git a/src/cmd/root.go b/src/cmd/root.goindex 23be9efb..3d5d3c10 100644--- a/src/cmd/root.go+++ b/src/cmd/root.go@@ -137,6 +137,9 @@ func initEnvConfig() {events := strings.Split(envWebhookEvents, ",")config.WhatsappWebhookEvents = events}+ if viper.IsSet("whatsapp_webhook_include_outgoing") {+ config.WhatsappWebhookIncludeOutgoing = viper.GetBool("whatsapp_webhook_include_outgoing")+ }if viper.IsSet("whatsapp_account_validation") {config.WhatsappAccountValidation = viper.GetBool("whatsapp_account_validation")}@@ -157,6 +160,9 @@ func initEnvConfig() {if viper.IsSet("chatwoot_inbox_id") {config.ChatwootInboxID = viper.GetInt("chatwoot_inbox_id")}+ if envChatwootDeviceID := viper.GetString("chatwoot_device_id"); envChatwootDeviceID != "" {+ config.ChatwootDeviceID = envChatwootDeviceID+ }}func initFlags() {@@ -263,6 +269,12 @@ func initFlags() {config.WhatsappWebhookEvents,`whitelist of events to forward to webhook (empty = all events) --webhook-events <string> | example: --webhook-events="message,message.ack,group.participants"`,)+ rootCmd.PersistentFlags().BoolVarP(+ &config.WhatsappWebhookIncludeOutgoing,+ "webhook-include-outgoing", "",+ config.WhatsappWebhookIncludeOutgoing,+ `include outgoing messages (sent from phone) in webhook notifications --webhook-include-outgoing <true/false> | example: --webhook-include-outgoing=true`,+ )rootCmd.PersistentFlags().BoolVarP(&config.WhatsappAccountValidation,"account-validation", "",@@ -277,6 +289,12 @@ func initFlags() {config.ChatwootEnabled,`enable Chatwoot integration --chatwoot-enabled <true/false> | example: --chatwoot-enabled=true`,)+ rootCmd.PersistentFlags().StringVarP(+ &config.ChatwootDeviceID,+ "chatwoot-device-id", "",+ config.ChatwootDeviceID,+ `device ID for Chatwoot outbound messages --chatwoot-device-id <string> | example: --chatwoot-device-id="my-device"`,+ )}func initChatStorage() (*sql.DB, error) {diff --git a/src/config/settings.go b/src/config/settings.goindex d17d1579..e2a8a7d9 100644--- a/src/config/settings.go+++ b/src/config/settings.go@@ -5,7 +5,7 @@ import ()var (- AppVersion = "v8.2.0"+ AppVersion = "v8.2.1"AppPort = "3000"AppHost = "0.0.0.0"AppDebug = false@@ -31,8 +31,9 @@ var (WhatsappAutoDownloadMedia = true // Auto-download media from incoming messagesWhatsappWebhook []stringWhatsappWebhookSecret = "secret"- WhatsappWebhookInsecureSkipVerify = false // Skip TLS certificate verification for webhooks (insecure)- WhatsappWebhookEvents []string // Whitelist of events to forward to webhook (empty = all events)+ 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 notificationsWhatsappLogLevel = "ERROR"WhatsappSettingMaxImageSize int64 = 20000000 // 20MBWhatsappSettingMaxFileSize int64 = 50000000 // 50MB@@ -51,4 +52,5 @@ var (ChatwootAPIToken = ""ChatwootAccountID = 0ChatwootInboxID = 0+ ChatwootDeviceID = "" // Device ID for outbound messages (required for multi-device))diff --git a/src/go.mod b/src/go.modindex 6cfe823c..eb55a9ef 100644--- a/src/go.mod+++ b/src/go.mod@@ -7,11 +7,11 @@ require (github.com/disintegration/imaging v1.6.2github.com/dustin/go-humanize v1.0.1github.com/go-ozzo/ozzo-validation/v4 v4.3.0- github.com/gofiber/fiber/v2 v2.52.10+ github.com/gofiber/fiber/v2 v2.52.11github.com/gofiber/template/html/v2 v2.1.3github.com/gofiber/websocket/v2 v2.2.1github.com/google/uuid v1.6.0- github.com/lib/pq v1.10.9+ github.com/lib/pq v1.11.1github.com/mark3labs/mcp-go v0.43.2github.com/mattn/go-sqlite3 v1.14.33github.com/sirupsen/logrus v1.9.4@@ -21,7 +21,7 @@ require (github.com/stretchr/testify v1.11.1github.com/valyala/fasthttp v1.69.0go.mau.fi/libsignal v0.2.1- go.mau.fi/whatsmeow v0.0.0-20260126173513-4dbbef8d4d4a+ go.mau.fi/whatsmeow v0.0.0-20260129212019-7787ab952245golang.org/x/image v0.35.0google.golang.org/protobuf v1.36.11)@@ -35,7 +35,7 @@ require (github.com/beeper/argo-go v1.1.2 // indirectgithub.com/buger/jsonparser v1.1.1 // indirectgithub.com/clipperhouse/stringish v0.1.1 // indirect- github.com/clipperhouse/uax29/v2 v2.4.0 // indirect+ github.com/clipperhouse/uax29/v2 v2.5.0 // indirectgithub.com/coder/websocket v1.8.14 // indirectgithub.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirectgithub.com/elliotchance/orderedmap/v3 v3.1.0 // indirectdiff --git a/src/go.sum b/src/go.sumindex ea50c557..5d2d558d 100644--- a/src/go.sum+++ b/src/go.sum@@ -23,8 +23,8 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUgithub.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=-github.com/clipperhouse/uax29/v2 v2.4.0 h1:RXqE/l5EiAbA4u97giimKNlmpvkmz+GrBVTelsoXy9g=-github.com/clipperhouse/uax29/v2 v2.4.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=+github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=+github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=@@ -50,8 +50,8 @@ github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRigithub.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=-github.com/gofiber/fiber/v2 v2.52.10 h1:jRHROi2BuNti6NYXmZ6gbNSfT3zj/8c0xy94GOU5elY=-github.com/gofiber/fiber/v2 v2.52.10/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=+github.com/gofiber/fiber/v2 v2.52.11 h1:5f4yzKLcBcF8ha1GQTWB+mpblWz3Vz6nSAbTL31HkWs=+github.com/gofiber/fiber/v2 v2.52.11/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=github.com/gofiber/template/html/v2 v2.1.3 h1:n1LYBtmr9C0V/k/3qBblXyMxV5B0o/gpb6dFLp8ea+o=@@ -78,8 +78,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=-github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=-github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=+github.com/lib/pq v1.11.1 h1:wuChtj2hfsGmmx3nf1m7xC2XpK6OtelS2shMY+bGMtI=+github.com/lib/pq v1.11.1/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=github.com/mailru/easyjson v0.9.1 h1:LbtsOm5WAswyWbvTEOqhypdPeZzHavpZx96/n553mR8=github.com/mailru/easyjson v0.9.1/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=github.com/mark3labs/mcp-go v0.43.2 h1:21PUSlWWiSbUPQwXIJ5WKlETixpFpq+WBpbMGDSVy/I=@@ -153,8 +153,8 @@ go.mau.fi/libsignal v0.2.1 h1:vRZG4EzTn70XY6Oh/pVKrQGuMHBkAWlGRC22/85m9L0=go.mau.fi/libsignal v0.2.1/go.mod h1:iVvjrHyfQqWajOUaMEsIfo3IqgVMrhWcPiiEzk7NgoU=go.mau.fi/util v0.9.5 h1:7AoWPCIZJGv4jvtFEuCe3GhAbI7uF9ckIooaXvwlIR4=go.mau.fi/util v0.9.5/go.mod h1:g1uvZ03VQhtTt2BgaRGVytS/Zj67NV0YNIECch0sQCQ=-go.mau.fi/whatsmeow v0.0.0-20260126173513-4dbbef8d4d4a h1:NYDCB/nhr4JBe9d15vzPe8GzRXRJAvEms2nESWQ0Wbg=-go.mau.fi/whatsmeow v0.0.0-20260126173513-4dbbef8d4d4a/go.mod h1:jDLOQLLiYXcm4vMB6vtPcBLU387sRY+P3vOElxX8srA=+go.mau.fi/whatsmeow v0.0.0-20260129212019-7787ab952245 h1:Pdrwc7vLH6DrWa2Tk19pBTwlUfV0vJLU6V9xNZ2UwGE=+go.mau.fi/whatsmeow v0.0.0-20260129212019-7787ab952245/go.mod h1:jDLOQLLiYXcm4vMB6vtPcBLU387sRY+P3vOElxX8srA=go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=diff --git a/src/infrastructure/whatsapp/event_message_handler.go b/src/infrastructure/whatsapp/event_message_handler.goindex d38b7c5a..61c88a2f 100644--- a/src/infrastructure/whatsapp/event_message_handler.go+++ b/src/infrastructure/whatsapp/event_message_handler.go@@ -114,11 +114,11 @@ func handleWebhookForward(ctx context.Context, evt *events.Message, client *what}}- // Skip webhook for outgoing messages (IsFromMe) to avoid duplicate webhooks- // when multiple devices are connected. The sender's device receives an echo- // of the sent message, but we only want the recipient's device to trigger webhook.+ // Skip webhook for outgoing messages (IsFromMe) unless explicitly configured to include them.+ // By default, we skip to avoid duplicate webhooks when multiple devices are connected.+ // The sender's device receives an echo of the sent message.// Note: Protocol messages (REVOKE, MESSAGE_EDIT) are allowed through above.- if evt.Info.IsFromMe {+ if evt.Info.IsFromMe && !config.WhatsappWebhookIncludeOutgoing {log.Debugf("Skipping webhook for outgoing message %s (IsFromMe=true)", evt.Info.ID)return}diff --git a/src/ui/rest/chatwoot.go b/src/ui/rest/chatwoot.goindex c0db5ba9..5322afe6 100644--- a/src/ui/rest/chatwoot.go+++ b/src/ui/rest/chatwoot.go@@ -1,29 +1,50 @@package restimport (+ "fmt"++ "github.com/aldinokemal/go-whatsapp-web-multidevice/config"domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app"domainSend "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/send""github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatwoot"+ "github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp""github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils""github.com/gofiber/fiber/v2""github.com/sirupsen/logrus")type ChatwootHandler struct {- AppUsecase domainApp.IAppUsecase- SendUsecase domainSend.ISendUsecase+ AppUsecase domainApp.IAppUsecase+ SendUsecase domainSend.ISendUsecase+ DeviceManager *whatsapp.DeviceManager}-func NewChatwootHandler(appUsecase domainApp.IAppUsecase, sendUsecase domainSend.ISendUsecase) *ChatwootHandler {+func NewChatwootHandler(appUsecase domainApp.IAppUsecase, sendUsecase domainSend.ISendUsecase, dm *whatsapp.DeviceManager) *ChatwootHandler {return &ChatwootHandler{- AppUsecase: appUsecase,- SendUsecase: sendUsecase,+ AppUsecase: appUsecase,+ SendUsecase: sendUsecase,+ DeviceManager: dm,}}func (h *ChatwootHandler) HandleWebhook(c *fiber.Ctx) error {logrus.Debugf("Chatwoot Webhook raw body: %s", string(c.Body()))+ // Resolve device for outbound messages+ instance, resolvedID, err := h.DeviceManager.ResolveDevice(config.ChatwootDeviceID)+ if err != nil {+ logrus.Errorf("Chatwoot Webhook: Failed to resolve device: %v", err)+ return c.Status(fiber.StatusServiceUnavailable).JSON(utils.ResponseData{+ Status: fiber.StatusServiceUnavailable,+ Code: "DEVICE_NOT_AVAILABLE",+ Message: fmt.Sprintf("No device available for Chatwoot: %v. Configure CHATWOOT_DEVICE_ID or ensure one device is registered.", err),+ })+ }+ logrus.Debugf("Chatwoot Webhook: Using device %s", resolvedID)++ // Set device context for send operations+ c.SetUserContext(whatsapp.ContextWithDevice(c.UserContext(), instance))+var payload chatwoot.WebhookPayloadif err := c.BodyParser(&payload); err != nil {return utils.ResponseError(c, "Invalid payload")