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
chore: remove deadcode
Aldino Kemal3a9a18ac4483
diff --git a/AGENTS.md b/AGENTS.mdindex 6da3224f..f1954f86 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -29,9 +29,9 @@ go-whatsapp-web-multidevice/| |-- views/ # Embedded Vue 3 plain JS UI| |-- statics/ # Runtime media, QR codes, send items| `-- storages/ # Runtime SQLite DBs and history dumps-|-- docs/ # OpenAPI, webhook payload docs, SDK config+|-- docs/ # OpenAPI, webhook payload, Chatwoot docs|-- docker/ # Multi-stage Alpine image and entrypoint-|-- gallery/ # Static screenshots and project images+|-- gallery/ # Project logo assets`-- .github/workflows/ # Docker publish, release, latest promotion```diff --git a/docs/agent-progress.md b/docs/agent-progress.mddeleted file mode 100644index bc866c53..00000000--- a/docs/agent-progress.md+++ /dev/null@@ -1,36 +0,0 @@-# Agent Progress--_Recurring `/loop` task: triage open GitHub issues, fix the highest-priority bug, run tests, open a draft PR._--## Run 2 — 2026-06-09 (iteration 2)--Iteration 1 shipped #688 (PR #714, since **merged** to main as `9266165`). This run picked the next actionable bug.--### Selected issue: #675 item A — chat-list name shows blank--> "On the conversation list, the 'name' column should display the phone number when the contact name is empty. Currently this mapping doesn't work, making it hard to identify the sender."--### Root cause--`ListChats` and `GetChatMessages` ([src/usecase/chat.go](../src/usecase/chat.go)) mapped `chatInfo.Name = chat.Name` verbatim. `GetChats` reads the stored name straight from sqlite with no fallback, so a chat persisted before a pushname/group subject is known (or with a stale empty name) returns `"name": ""` to the API and the web UI — the row shows blank.--### Fix--Added `chatDisplayName(jid, name)` — returns the stored name when present, else a JID-derived fallback mirroring the storage-layer convention in `GetChatNameWithPushNameByDevice`: `"Status"` for `status@broadcast`, phone number for 1:1, `Group <id>` / `Newsletter <id>` for those address spaces. Applied in both `ListChats` and `GetChatMessages`.--### Review follow-up (PR #715)--- `kilo-code-bot` flagged that the fallback returned the lowercase local part `"status"` for `status@broadcast` instead of the contracted `"Status"`. **Fixed** in `e0a462e` by adding the `status@broadcast` → `"Status"` special case before the local-part fallback, with test coverage. Replied on the thread and resolved it.--### Verification--- `gofmt` clean; `go build ./...` clean.-- `go test ./...` — all packages pass (post-merge with main).-- `TestChatDisplayName` covers: non-empty passthrough (1:1 + group), empty→phone, empty→`Group <id>`, empty→`Newsletter <id>`, empty→lid local part, empty→`Status`, non-empty `status@broadcast`.--Status: **done** — draft PR [#715](https://github.com/aldinokemal/go-whatsapp-web-multidevice/pull/715), review feedback addressed.--### Note for future iterations--- #674 (Chatwoot 401) turned out to be a **real bug** (whitespace in API token/URL), fixed by the maintainer in PR #713 — not user config as first triaged. Lesson: verify "config" hunches against the code before dismissing.-- The cleanly-fixable bug backlog is now thin; remaining open bugs are WhatsApp/whatsmeow-side or already addressed pending close.diff --git a/docs/per-device-webhook-plan.md b/docs/per-device-webhook-plan.mddeleted file mode 100644index cbcd2d30..00000000--- a/docs/per-device-webhook-plan.md+++ /dev/null@@ -1,157 +0,0 @@-# Per-Device Webhook Implementation Plan--## Status: IMPLEMENTED--## Overview--Add per-device webhook support where each device can have its own webhook URL. If a device has no custom webhook URL, it falls back to the global webhook.--## Flow Diagram--```text-┌─────────────────────────────────────────────────────────────────────────────┐-│ WHATSAPP EVENT RECEIVED │-└─────────────────────────────────────────────────────────────────────────────┘- │- ▼-┌─────────────────────────────────────────────────────────────────────────────┐-│ event_handler.go :: handler() │-│ - Routes event to appropriate handler (message, receipt, etc.) │-└─────────────────────────────────────────────────────────────────────────────┘- │- ▼-┌─────────────────────────────────────────────────────────────────────────────┐-│ Event-specific handler (e.g., event_message_handler.go) │-│ - Creates webhook payload with device_id │-│ - Calls forwardMessageToWebhook() │-└─────────────────────────────────────────────────────────────────────────────┘- │- ▼-┌─────────────────────────────────────────────────────────────────────────────┐-│ webhook_forward.go :: forwardPayloadToConfiguredWebhooks() │-│ ┌───────────────────────────────────────────────────────────────────────┐ │-│ │ STEP 1: Extract device JID from payload["device_id"] │ │-│ │ STEP 2: Call getWebhookConfigForDevice(deviceJID) │ │-│ │ - Looks up device record by JID │ │-│ │ - If device has custom webhook_url, return device config │ │-│ │ - Otherwise return global config.WhatsappWebhook settings │ │-│ └───────────────────────────────────────────────────────────────────────┘ │-└─────────────────────────────────────────────────────────────────────────────┘- │- ▼- ┌───────────────┴───────────────┐- │ │- ▼ ▼- ┌──────────────────┐ ┌────────────────────────┐- │ Device has custom │ │ Device webhook URL is │- │ webhook config? │ │ NULL or empty? │- └──────────────────────┘ └─────────────────────────┘- │ │- YES │ │ YES- ▼ ▼- ┌────────────────────────┐ ┌─────────────────────────┐- │ Use device webhook │ │ Use global config │- │ config (override) │ │ WhatsappWebhook[] │- └────────────────────────┘ └─────────────────────────┘- │ │- └───────────────┬───────────────┘- │- ▼-┌─────────────────────────────────────────────────────────────────────────────┐-│ webhook_forward.go :: forwardToWebhooks() │-│ - Iterates webhook URLs │-│ - For each URL: submitWebhook() with HMAC signature │-│ - 5 retries with exponential backoff │-└─────────────────────────────────────────────────────────────────────────────┘- │- ▼- ┌───────────────┴───────────────┐- │ │- ▼ ▼- ┌──────────────────┐ ┌────────────────────────┐- │ All webhooks │ │ Some webhooks failed │- │ succeeded │ │ (partial failure OK) │- └──────────────────┘ └────────────────────────┘-```--## API Flow: Set Device Webhook--```text-Client REST API UseCase Repository- │ │ │ │- │ PATCH /devices/:id/webhook│ │ │- │ { "webhook_url": "...", │ │ │- │ "webhook_secret": "..."} │ │- │─────────────────────────>│ │ │- │ │ SetDeviceWebhookConfig() │ │- │ │──────────────────────────>│ │- │ │ │ SetDeviceWebhookConfig() │- │ │ │────────────────────────>│- │ │ │ │- │ │ │ │- │ 200 OK │ │ │- │<─────────────────────────│ │ │- │ │ │ │-```--## Files Modified--| File | Change |-|------|--------|-| `domains/chatstorage/chatstorage.go` | Added webhook URL, secret, event whitelist, and TLS-skip fields plus `DeviceWebhookConfig` |-| `domains/chatstorage/interfaces.go` | Added `GetDeviceRecordByJID`, URL-only helpers, and full webhook config helpers |-| `infrastructure/chatstorage/sqlite_repository.go` | Added migrations #31-#34, updated queries, implemented new methods |-| `infrastructure/whatsapp/chatstorage_wrapper.go` | Added wrapper methods for new interface methods |-| `infrastructure/whatsapp/webhook_forward.go` | Added `getWebhookConfigForDevice()`, device event filtering, and updated forwarding logic |-| `infrastructure/whatsapp/device_manager.go` | Added `GetStorage()` method |-| `domains/device/interfaces.go` | Added URL-only and full-config webhook methods to `IDeviceUsecase` |-| `usecase/device.go` | Implemented URL-only and full-config webhook methods |-| `ui/rest/device.go` | Added `PATCH /devices/:device_id/webhook`, `GET /devices/:device_id/webhook` |-| `infrastructure/whatsapp/webhook_forward_test.go` | Added per-device webhook tests |-| `usecase/device_test.go` | Added device service tests |-| `docs/openapi.yaml` | Added webhook API documentation |--## Database Changes--Migrations #31-#34 add the per-device webhook fields to the `devices` table:--- `webhook_url TEXT DEFAULT NULL`-- `webhook_secret TEXT DEFAULT ''`-- `webhook_events TEXT DEFAULT ''`-- `webhook_insecure_skip_verify BOOLEAN DEFAULT FALSE`--## API Endpoints--- `PATCH /devices/{device_id}/webhook` - Set device-specific webhook configuration- - Body: `{ "webhook_url": "https://example.com/webhook", "webhook_secret": "secret", "webhook_events": "message,message.ack", "webhook_insecure_skip_verify": false }`- - Set to empty string `""` to clear and use global webhook--- `GET /devices/{device_id}/webhook` - Get device-specific webhook configuration- - Returns empty values if not set (use global)--## Testing--### Unit Tests--**`infrastructure/whatsapp/webhook_forward_test.go`:**-- `TestGetWebhookConfigForDevice_NoDeviceID` - Returns global webhook config when device JID is empty-- `TestGetWebhookConfigForDevice_DeviceNotFound` - Falls back to global when device not found-- `TestGetWebhookConfigForDevice_FallbackToGlobal` - Falls back to global when device has no custom webhook-- `TestGetWebhookConfigForDevice_DeviceSpecificOverride` - Uses the full device-specific webhook config when set-- `TestForwardPayloadToConfiguredWebhooks_WithDeviceSpecificWebhook` - Uses device-specific webhook when set-- `TestForwardPayloadToConfiguredWebhooks_DeviceWebhookCleared_FallsBackToGlobal` - Falls back to global when device webhook is cleared-- `TestForwardPayloadToConfiguredWebhooks_DeviceWebhookOnly_NoGlobal` - Uses device-specific webhook with no global webhook-- `TestSQLiteRepositoryGetsDeviceWebhookConfigByJID` - Persists and resolves the full device webhook config-- `TestAddDevice_ForwardsFullWebhookConfig` - Accepts full webhook config when creating a device--**`usecase/device_test.go`:**-- `TestDeviceServiceInterface` - Verifies interface implementation-- `TestSetDeviceWebhook_InvalidManager` - Error handling for nil manager-- `TestGetDeviceWebhook_InvalidManager` - Error handling for nil manager--## OpenAPI Documentation--Added to `docs/openapi.yaml`:--- `GET /devices/{device_id}/webhook` - Get device webhook configuration-- `PATCH /devices/{device_id}/webhook` - Set device webhook configurationdiff --git a/src/infrastructure/chatwoot/client.go b/src/infrastructure/chatwoot/client.goindex 7b82a9a3..8e1bc154 100644--- a/src/infrastructure/chatwoot/client.go+++ b/src/infrastructure/chatwoot/client.go@@ -422,9 +422,8 @@ type conversationListItem struct {}// listContactConversations fetches all conversations for a contact via the-// contact-specific endpoint. Shared by FindConversation (which wants the-// active one) and FindLatestConversation (which wants the most recent one to-// reopen).+// contact-specific endpoint. Used by FindOrCreateConversation to pick an open+// conversation or the latest one for reopen.func (c *Client) listContactConversations(contactID int) ([]conversationListItem, error) {endpoint := fmt.Sprintf("%s/api/v1/accounts/%d/contacts/%d/conversations", c.BaseURL, c.AccountID, contactID)req, err := http.NewRequest("GET", endpoint, nil)@@ -479,26 +478,6 @@ func selectLatestConversation(items []conversationListItem, inboxID, contactID ireturn latest}-func (c *Client) FindConversation(contactID int) (*Conversation, error) {- items, err := c.listContactConversations(contactID)- if err != nil {- return nil, err- }- return selectOpenConversation(items, c.InboxID, contactID), nil-}--// FindLatestConversation returns the most recent conversation for the contact-// in this client's inbox, regardless of status. The reopen path uses it to-// resurrect a resolved conversation instead of opening a new thread. Returns-// (nil, nil) when the contact has no conversation in this inbox.-func (c *Client) FindLatestConversation(contactID int) (*Conversation, error) {- items, err := c.listContactConversations(contactID)- if err != nil {- return nil, err- }- return selectLatestConversation(items, c.InboxID, contactID), nil-}-// ToggleConversationStatus sets a conversation's status (open/resolved/pending)// via POST /conversations/{id}/toggle_status.func (c *Client) ToggleConversationStatus(conversationID int, status string) error {diff --git a/src/infrastructure/chatwoot/client_inbox_test.go b/src/infrastructure/chatwoot/client_inbox_test.goindex 14726548..907a09e6 100644--- a/src/infrastructure/chatwoot/client_inbox_test.go+++ b/src/infrastructure/chatwoot/client_inbox_test.go@@ -249,33 +249,20 @@ func TestCreateInbox_ZeroIDOrUndecodable(t *testing.T) {}}-// --- FindLatestConversation --------------------------------------------------func TestFindLatestConversation_ReturnsHighestIDRegardlessOfStatus(t *testing.T) {- // Unlike FindConversation, this returns the highest-id conversation in this- // inbox EVEN IF it is resolved — that is the conversation the reopen path- // resurrects. A higher-id conversation in a different inbox must be skipped- // so we never resurrect the wrong thread, and a lower-id open conversation- // in the right inbox must lose to the higher-id resolved one.- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- if r.Method != http.MethodGet || r.URL.Path != "/api/v1/accounts/1/contacts/7/conversations" {- t.Fatalf("unexpected request: %s %s", r.Method, r.URL.String())- }- writeJSON(t, w, http.StatusOK, map[string]any{- "payload": []map[string]any{- {"id": 10, "inbox_id": 2, "status": "open"}, // right inbox, lower id- {"id": 99, "inbox_id": 88, "status": "open"}, // higher id but wrong inbox -> skip- {"id": 20, "inbox_id": 2, "status": "resolved"}, // right inbox, highest -> winner- },- })- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindLatestConversation(7)- if err != nil {- t.Fatalf("FindLatestConversation: %v", err)- }+// --- selectLatestConversation ----------------------------------------------++func TestSelectLatestConversation_ReturnsHighestIDRegardlessOfStatus(t *testing.T) {+ // Returns the highest-id conversation in this inbox EVEN IF it is resolved+ // — that is the conversation the reopen path resurrects. A higher-id+ // conversation in a different inbox must be skipped so we never resurrect+ // the wrong thread, and a lower-id open conversation in the right inbox+ // must lose to the higher-id resolved one.+ items := []conversationListItem{+ {ID: 10, InboxID: 2, Status: "open"}, // right inbox, lower id+ {ID: 99, InboxID: 88, Status: "open"}, // higher id but wrong inbox -> skip+ {ID: 20, InboxID: 2, Status: "resolved"}, // right inbox, highest -> winner+ }+ conv := selectLatestConversation(items, 2, 7)if conv == nil || conv.ID != 20 {t.Fatalf("conv = %+v, want ID 20 (highest in inbox 2, even though resolved)", conv)}@@ -290,69 +277,27 @@ func TestFindLatestConversation_ReturnsHighestIDRegardlessOfStatus(t *testing.T)}}-func TestFindLatestConversation_SkipsOtherInboxesEntirely(t *testing.T) {+func TestSelectLatestConversation_SkipsOtherInboxesEntirely(t *testing.T) {// When every conversation belongs to another inbox, there is no latest for- // THIS inbox -> (nil, nil), so the reopen path falls through to creating a+ // THIS inbox -> nil, so the reopen path falls through to creating a// fresh conversation in our inbox.- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- writeJSON(t, w, http.StatusOK, map[string]any{- "payload": []map[string]any{- {"id": 50, "inbox_id": 88, "status": "open"},- {"id": 51, "inbox_id": 89, "status": "resolved"},- },- })- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindLatestConversation(7)- if err != nil {- t.Fatalf("FindLatestConversation: %v", err)+ items := []conversationListItem{+ {ID: 50, InboxID: 88, Status: "open"},+ {ID: 51, InboxID: 89, Status: "resolved"},}+ conv := selectLatestConversation(items, 2, 7)if conv != nil {t.Fatalf("conv = %+v, want nil (no conversation in our inbox)", conv)}}-func TestFindLatestConversation_EmptyPayloadReturnsNil(t *testing.T) {- // No conversations at all -> (nil, nil).- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- writeJSON(t, w, http.StatusOK, map[string]any{"payload": []map[string]any{}})- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindLatestConversation(7)- if err != nil {- t.Fatalf("FindLatestConversation: %v", err)- }+func TestSelectLatestConversation_EmptyPayloadReturnsNil(t *testing.T) {+ conv := selectLatestConversation(nil, 2, 7)if conv != nil {t.Fatalf("conv = %+v, want nil", conv)}}-func TestFindLatestConversation_Non200(t *testing.T) {- // Shares listContactConversations with FindConversation, so the error Op is- // the same "list contact conversations".- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- writeJSON(t, w, http.StatusBadGateway, map[string]any{"error": "down"})- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindLatestConversation(7)- if conv != nil {- t.Fatalf("conv = %+v, want nil", conv)- }- var httpErr *HTTPStatusError- if !errors.As(err, &httpErr) {- t.Fatalf("err = %v, want *HTTPStatusError", err)- }- if httpErr.StatusCode != http.StatusBadGateway || httpErr.Op != "list contact conversations" {- t.Errorf("err = %+v, want 502 'list contact conversations'", httpErr)- }-}-// --- ToggleConversationStatus ----------------------------------------------func TestToggleConversationStatus_PostsStatus(t *testing.T) {diff --git a/src/infrastructure/chatwoot/client_methods_test.go b/src/infrastructure/chatwoot/client_methods_test.goindex 62d5275c..d37ca490 100644--- a/src/infrastructure/chatwoot/client_methods_test.go+++ b/src/infrastructure/chatwoot/client_methods_test.go@@ -535,33 +535,20 @@ func TestUpdateContactName(t *testing.T) {}}-// --- FindConversation ------------------------------------------------------+// --- selectOpenConversation -------------------------------------------------func TestFindConversation_ReturnsFirstOpenMatchingInbox(t *testing.T) {+func TestSelectOpenConversation_ReturnsFirstOpenMatchingInbox(t *testing.T) {// The first conversation that is both in this client's inbox AND not// resolved wins. Earlier entries that fail either condition are skipped:// a resolved conversation in the right inbox, and an open conversation// in a different inbox, both come before the valid one.- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- if r.Method != http.MethodGet || r.URL.Path != "/api/v1/accounts/1/contacts/7/conversations" {- t.Fatalf("unexpected request: %s %s", r.Method, r.URL.String())- }- writeJSON(t, w, http.StatusOK, map[string]any{- "payload": []map[string]any{- {"id": 10, "inbox_id": 2, "status": "resolved"}, // right inbox, resolved -> skip- {"id": 11, "inbox_id": 99, "status": "open"}, // wrong inbox -> skip- {"id": 12, "inbox_id": 2, "status": "open"}, // match- {"id": 13, "inbox_id": 2, "status": "pending"}, // also valid but later- },- })- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindConversation(7)- if err != nil {- t.Fatalf("FindConversation: %v", err)+ items := []conversationListItem{+ {ID: 10, InboxID: 2, Status: "resolved"}, // right inbox, resolved -> skip+ {ID: 11, InboxID: 99, Status: "open"}, // wrong inbox -> skip+ {ID: 12, InboxID: 2, Status: "open"}, // match+ {ID: 13, InboxID: 2, Status: "pending"}, // also valid but later}+ conv := selectOpenConversation(items, 2, 7)if conv == nil || conv.ID != 12 {t.Fatalf("conv = %+v, want ID 12", conv)}@@ -573,70 +560,30 @@ func TestFindConversation_ReturnsFirstOpenMatchingInbox(t *testing.T) {}}-func TestFindConversation_NonResolvedNonResolvedStatuses(t *testing.T) {+func TestSelectOpenConversation_AcceptsNonResolvedStatuses(t *testing.T) {// "resolved" is the only excluded status; any other status (here// "pending") for the right inbox is considered an active conversation.- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- writeJSON(t, w, http.StatusOK, map[string]any{- "payload": []map[string]any{- {"id": 20, "inbox_id": 2, "status": "pending"},- },- })- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindConversation(7)- if err != nil {- t.Fatalf("FindConversation: %v", err)+ items := []conversationListItem{+ {ID: 20, InboxID: 2, Status: "pending"},}+ conv := selectOpenConversation(items, 2, 7)if conv == nil || conv.ID != 20 {t.Fatalf("conv = %+v, want ID 20", conv)}}-func TestFindConversation_NoneMatch(t *testing.T) {- // All candidates are either resolved or in the wrong inbox -> nil, nil.- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- writeJSON(t, w, http.StatusOK, map[string]any{- "payload": []map[string]any{- {"id": 30, "inbox_id": 2, "status": "resolved"},- {"id": 31, "inbox_id": 99, "status": "open"},- },- })- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindConversation(7)- if err != nil {- t.Fatalf("FindConversation: %v", err)+func TestSelectOpenConversation_NoneMatch(t *testing.T) {+ // All candidates are either resolved or in the wrong inbox -> nil.+ items := []conversationListItem{+ {ID: 30, InboxID: 2, Status: "resolved"},+ {ID: 31, InboxID: 99, Status: "open"},}+ conv := selectOpenConversation(items, 2, 7)if conv != nil {t.Fatalf("conv = %+v, want nil", conv)}}-func TestFindConversation_Non200(t *testing.T) {- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- writeJSON(t, w, http.StatusBadGateway, map[string]any{"error": "down"})- }))- defer server.Close()-- c := newTestClient(t, server.URL)- conv, err := c.FindConversation(7)- if conv != nil {- t.Fatalf("conv = %+v, want nil", conv)- }- var httpErr *HTTPStatusError- if !errors.As(err, &httpErr) {- t.Fatalf("err = %v, want *HTTPStatusError", err)- }- if httpErr.StatusCode != http.StatusBadGateway || httpErr.Op != "list contact conversations" {- t.Errorf("err = %+v, want 502 'list contact conversations'", httpErr)- }-}-// --- CreateConversation ----------------------------------------------------func TestCreateConversation_PostsOpenStatus(t *testing.T) {@@ -740,7 +687,7 @@ func TestCreateConversation_ZeroID(t *testing.T) {// --- FindOrCreateConversation ---------------------------------------------func TestFindOrCreateConversation_ReturnsFoundWithoutCreating(t *testing.T) {- // When FindConversation returns an existing conversation, no POST is made.+ // When an open conversation already exists, no POST is made.createCalls := 0server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {switch {@@ -771,8 +718,7 @@ func TestFindOrCreateConversation_ReturnsFoundWithoutCreating(t *testing.T) {}func TestFindOrCreateConversation_CreatesWhenNotFound(t *testing.T) {- // FindConversation returns (nil, nil) -> the method falls through to- // CreateConversation.+ // No open conversation -> the method falls through to CreateConversation.server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {switch {case r.Method == http.MethodGet:@@ -796,8 +742,8 @@ func TestFindOrCreateConversation_CreatesWhenNotFound(t *testing.T) {}func TestFindOrCreateConversation_SwallowsFindErrorThenCreates(t *testing.T) {- // FindConversation failing is logged but NOT propagated: the method still- // proceeds to create. This codifies the current swallow-and-create+ // Listing conversations failing is logged but NOT propagated: the method+ // still proceeds to create. This codifies the current swallow-and-create// behavior — a find error must not block conversation creation.server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {switch {diff --git a/src/infrastructure/chatwoot/client_reopen_test.go b/src/infrastructure/chatwoot/client_reopen_test.goindex 2a09ccac..3dedc82b 100644--- a/src/infrastructure/chatwoot/client_reopen_test.go+++ b/src/infrastructure/chatwoot/client_reopen_test.go@@ -10,8 +10,8 @@ import ()// reopenCounters tallies the calls FindOrCreateConversation makes against the-// fake Chatwoot server so each case can assert exactly which paths ran. Both-// FindConversation and FindLatestConversation hit the same GET endpoint, so we+// fake Chatwoot server so each case can assert exactly which paths ran. Listing+// conversations hits the same GET endpoint for open and latest selection, so we// only distinguish create POSTs from toggle POSTs (the behaviorally meaningful// branches).type reopenCounters struct {@@ -21,7 +21,7 @@ type reopenCounters struct {}// reopenServer builds an httptest server that serves the contact's-// conversation list (for both Find and FindLatest), a toggle_status endpoint,+// conversation list (for open and latest selection), a toggle_status endpoint,// and a conversation-create endpoint, recording calls into the returned// counters. listPayload is the conversation list returned by the GET; toggleOK// controls whether toggle_status succeeds.@@ -55,9 +55,9 @@ func reopenServer(t *testing.T, listPayload []map[string]any, toggleOK bool, cre}func TestFindOrCreateConversation_ReopenReturnsOpenWithoutReopening(t *testing.T) {- // (a) When FindConversation finds an OPEN conversation, it is returned- // immediately: no FindLatest, no create, no toggle — even with reopen- // enabled. There is nothing to resurrect.+ // (a) When an OPEN conversation exists, it is returned immediately: no+ // create, no toggle — even with reopen enabled. There is nothing to+ // resurrect.origReopen := config.ChatwootReopenConversationconfig.ChatwootReopenConversation = truedefer func() { config.ChatwootReopenConversation = origReopen }()@@ -85,8 +85,8 @@ func TestFindOrCreateConversation_ReopenReturnsOpenWithoutReopening(t *testing.Tfunc TestFindOrCreateConversation_ReopenResolvedTogglesOpen(t *testing.T) {// (b) No OPEN conversation, but a RESOLVED one exists and reopen=true:- // FindLatestConversation returns the resolved conv, ToggleConversationStatus- // is called with "open", and the returned conv carries the UPDATED status.+ // the latest conversation is selected, ToggleConversationStatus is called+ // with "open", and the returned conv carries the UPDATED status.// No new conversation is created.origReopen := config.ChatwootReopenConversationorigPending := config.ChatwootConversationPending@@ -160,7 +160,7 @@ func TestFindOrCreateConversation_ReopenResolvedTogglesPendingWhenConfigured(t *func TestFindOrCreateConversation_ReopenNoConversationFallsThroughToCreate(t *testing.T) {// (c) reopen=true but the contact has NO conversation at all in our inbox:- // FindLatestConversation returns nil, so the method falls through to+ // latest selection returns nil, so the method falls through to// CreateConversation. No toggle happens.origReopen := config.ChatwootReopenConversationconfig.ChatwootReopenConversation = true@@ -187,9 +187,9 @@ func TestFindOrCreateConversation_ReopenNoConversationFallsThroughToCreate(t *tefunc TestFindOrCreateConversation_ReopenDisabledSkipsLatestAndToggles(t *testing.T) {// (d) reopen=false: even though a resolved conversation exists for the- // contact, the reopen branch is skipped entirely — FindLatest is never- // consulted and no toggle happens. With no OPEN conversation found, the- // method goes straight to creating a new one.+ // contact, the reopen branch is skipped entirely — latest selection is+ // never consulted and no toggle happens. With no OPEN conversation found,+ // the method goes straight to creating a new one.origReopen := config.ChatwootReopenConversationconfig.ChatwootReopenConversation = falsedefer func() { config.ChatwootReopenConversation = origReopen }()diff --git a/src/pkg/error/whatsapp_error.go b/src/pkg/error/whatsapp_error.goindex 2e62607c..e9f8c7fa 100644--- a/src/pkg/error/whatsapp_error.go+++ b/src/pkg/error/whatsapp_error.go@@ -88,7 +88,6 @@ func (e WaReachoutTimelockError) StatusCode() int {}const (- ErrInvalidJID = InvalidJID("your JID is invalid")ErrUserNotRegistered = InvalidJID("user is not registered")ErrWaCLI = WaCliError("your WhatsApp CLI is invalid or empty")ErrWaReachoutTimelock = WaReachoutTimelockError("WhatsApp rejected this send with error 463 (reach-out timelock). This is WhatsApp's server-side anti-spam restriction on starting new chats and cannot be bypassed by the API. It usually means there is no prior conversation with this recipient, or the sending account is temporarily restricted from reaching new contacts. To get through: ask the recipient to message you first, reply within an already-established conversation, or open and send the chat once from the phone linked to this session, then reduce your sending rate and wait for the restriction to clear. Newly-linked or low-activity numbers are affected most.")