Skip to content

feat(channels): add whatsapp token refresh and unify channel refresh jobs - #937

Merged
sung17 merged 2 commits into
mainfrom
feat/whatsapp-token-refresh
Aug 11, 2026
Merged

feat(channels): add whatsapp token refresh and unify channel refresh jobs#937
sung17 merged 2 commits into
mainfrom
feat/whatsapp-token-refresh

Conversation

@sung17

@sung17 sung17 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add automatic long-lived-token refresh for WhatsApp integrations (daily cron via refreshWhatsappTokens), tracking failures in a new tokenRefreshError column, plus a manual "refresh all channel tokens" builder action covering zalo/tiktok/instagram/messenger/whatsapp.
  • Consolidate the five separate per-channel cron schedulers (refreshZaloTokens, refreshTiktokTokens, refreshInstagramTokens, refreshMessengerTokens, refreshInstagramFacebookTokens) into a single refreshChannelTokens dispatcher.
  • Dedupe IntegrationWhatsappService/IntegrationWhatsappRepository by removing findWorkspaceIntegration in favor of the findByIdForWorkspace naming convention already shared with the messenger/instagram services.

Changes

  • apps/worker/src/schedule/handlers/refresh-channel-tokens.ts (new) — dispatches to a per-channel refresh function via a Record<ChannelType, ...> adapter.
  • apps/worker/src/schedule/handlers/refresh-whatsapp-tokens.ts (new) — batched, lock-guarded WhatsApp token refresh.
  • apps/worker/src/schedule/{handlers/register-schedules.ts,worker.ts} — replace 5 per-channel schedulers/cases with the unified refreshChannelTokens job.
  • packages/worker-config/src/queues/schedule/index.ts — replace the 5 per-channel ScheduleJobData entries with refreshChannelTokens.
  • apps/builder/src/features/workspaces/actions/refresh-all-channel-tokens.action.ts (new) — manual trigger action.
  • integrations/whatsapp/src/{api/auth.ts,integration.ts} — expose refreshAuth for WhatsApp.
  • packages/database/src/schema/integration-whatsapp.ts + packages/database/drizzle/20260811025220_add_whatsapp_token_refresh_error/ — add tokenRefreshError column.
  • packages/database/src/repositories/integration-whatsapp/repository.ts, packages/business/src/integration-whatsapp/service.ts — add findAllForTokenRefresh, findForTokenRefreshByWorkspaceIds, updateAuth, markTokenRefreshError; remove duplicate findWorkspaceIntegration in favor of findByIdForWorkspace.
  • apps/builder/src/features/integration-whatsapp/verification/actions.ts + its test — migrated off the removed findWorkspaceIntegration.

Test plan

  • pnpm lint
  • pnpm --filter worker check-types
  • pnpm --filter builder check-types
  • pnpm --filter @chatbotx.io/business check-types
  • pnpm --filter @chatbotx.io/database check-types
  • pnpm --filter @chatbotx.io/integration-whatsapp check-types
  • pnpm --filter builder test whatsapp-verification-actions (13/13 passing)
  • Manual: verify no lingering legacy BullMQ schedulers on an environment that already ran the previous per-channel jobs (known follow-up, out of scope for this PR)

…jobs

Adds automatic long-lived-token refresh for WhatsApp integrations
(daily cron + a new manual "refresh all channel tokens" builder
action), tracked via a new tokenRefreshError column. Consolidates the
five separate per-channel cron schedulers (zalo/tiktok/instagram/
messenger) into a single refreshChannelTokens dispatcher that now also
covers whatsapp, and dedupes IntegrationWhatsappService by removing
findWorkspaceIntegration in favor of the existing findByIdForWorkspace
naming convention shared with the other channel services.
…ings

Adds a red warning icon before the integration name on the
settings/channels manage tables (Zalo, TikTok, Instagram, Messenger,
WhatsApp) when tokenRefreshError is set, with the error message shown
on hover. Also exposes tokenRefreshError on IntegrationWhatsappResource,
which previously only picked id/name/inboxId/displayPhoneNumber.
@sung17
sung17 merged commit 90db316 into main Aug 11, 2026
15 checks passed
viethung0o0 pushed a commit that referenced this pull request Sep 7, 2026
…jobs (#937)

* feat(channels): add whatsapp token refresh and unify channel refresh jobs

Adds automatic long-lived-token refresh for WhatsApp integrations
(daily cron + a new manual "refresh all channel tokens" builder
action), tracked via a new tokenRefreshError column. Consolidates the
five separate per-channel cron schedulers (zalo/tiktok/instagram/
messenger) into a single refreshChannelTokens dispatcher that now also
covers whatsapp, and dedupes IntegrationWhatsappService by removing
findWorkspaceIntegration in favor of the existing findByIdForWorkspace
naming convention shared with the other channel services.

* feat(channels): show token refresh error warning icon in channel settings

Adds a red warning icon before the integration name on the
settings/channels manage tables (Zalo, TikTok, Instagram, Messenger,
WhatsApp) when tokenRefreshError is set, with the error message shown
on hover. Also exposes tokenRefreshError on IntegrationWhatsappResource,
which previously only picked id/name/inboxId/displayPhoneNumber.

---------

Co-authored-by: Deathgiver <anonymous@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant