Skip to content

fix(whatsapp): stop reconnect failing when the token lists several WABAs - #1094

Draft
viethung0o0 wants to merge 1 commit into
mainfrom
fix/whatsapp-reconnect-waba-match
Draft

fix(whatsapp): stop reconnect failing when the token lists several WABAs#1094
viethung0o0 wants to merge 1 commit into
mainfrom
fix/whatsapp-reconnect-waba-match

Conversation

@viethung0o0

Copy link
Copy Markdown
Contributor

Summary

  • WhatsApp Reconnect (Ads Optimization → Automatic Events) failed at random with "Reconnect returned a different WhatsApp Business Account" for businesses that own several WABAs, even when the user re-authorised the same account every time.
  • Root cause: the WABA was read from debug_token as granular_scopes[whatsapp_business_management].target_ids[0]. A system-user token lists every WABA the business has shared with the app, and Meta does not keep that order stable between tokens, so the first entry only matched by luck.
  • Fix: read the full list of granted WABAs and match the expected WABA by membership. Connect keeps the same behaviour for a fresh signup (first grant), but now validates a client-selected wabaId against the whole list instead of the first entry.

Changes

  • integrations/whatsapp/src/api/auth.ts: getSharedWabaIdgetSharedWabaIds, returning every granted WABA id (the single-id helper had no remaining callers).
  • New apps/builder/src/features/integration-whatsapp/libs/waba-grant.ts: resolveGrantedWabaId / requireGrantedWabaId with a WABA_GRANT_FAILURES map, shared by connect and reconnect so the selection rule lives in one place.
  • actions/reconnect.action.ts: accepts the reconnect when the existing WABA is anywhere in the grant list; still rejects when the token does not cover it.
  • actions/connect.action.ts: deriveSignupTargets takes the requested wabaId and uses the same helper; the separate first-entry mismatch check is removed.
  • Tests: whatsapp-waba-grant.test.ts (new), multi-WABA cases in whatsapp-reconnect-action.test.ts, whatsapp-connect-action-registration.test.ts, and integrations/whatsapp/__tests__/auth.test.ts.

Test plan

  • pnpm lint
  • pnpm --filter builder check-types && test (402 files / 2704 tests)
  • pnpm --filter @chatbotx.io/integration-whatsapp check-types && test (24 files / 217 tests)
  • Manual: on a business with several WABAs, press Reconnect on the WhatsApp Ads Optimization tab several times in a row — no more random "different WhatsApp Business Account" error; reconnecting with a different WABA selected still fails with that error.
  • Manual: fresh WhatsApp connect (single-WABA and multi-WABA business) still reaches phone-number selection.

@github-actions github-actions Bot added the bug Something isn't working as expected label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants