feat: Add external chat gateways for Telegram, WhatsApp, Slack, and Discord#1444
Merged
MODSetter merged 65 commits intoJun 1, 2026
Merged
Conversation
…hat threads and messages
…k, and Discord gateways
…tsApp, Slack, and Discord messaging channels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR integrates external messaging channels (Telegram and WhatsApp) into SurfSense. The implementation creates a gateway infrastructure that routes messages from external platforms through the same canonical chat agent used by the web UI. It adds database tables for managing external chat accounts, bindings, and inbound event queues, platform-specific adapters for Telegram and WhatsApp (both Meta Cloud API and self-hosted Baileys bridge), and an in-process FastAPI inbox worker that processes external messages and invokes the chat agent. The architecture supports webhook-based intake for production (Telegram, WhatsApp Cloud) and long-polling fallback for self-hosted deployments. The PR also includes a WhatsApp bridge Node.js service using Baileys for self-hosted WhatsApp integration, web UI components for pairing/managing channels, comprehensive observability metrics, and unit tests for core gateway components.
⏱️ Estimated Review Time: 1-3 hours
💡 Review Order Suggestion
surfsense_backend/app/config/__init__.pysurfsense_backend/app/db.pysurfsense_backend/alembic/versions/144_add_gateway_tables.pysurfsense_backend/app/gateway/base/adapter.pysurfsense_backend/app/gateway/base/translator.pysurfsense_backend/app/gateway/base/commands.pysurfsense_backend/app/gateway/telegram/adapter.pysurfsense_backend/app/gateway/telegram/translator.pysurfsense_backend/app/gateway/telegram/commands.pysurfsense_backend/app/gateway/whatsapp/adapter_cloud.pysurfsense_backend/app/gateway/whatsapp/adapter_baileys.pysurfsense_backend/app/gateway/whatsapp/translator.pysurfsense_backend/app/gateway/whatsapp/translator_baileys.pysurfsense_backend/app/gateway/whatsapp/commands.pysurfsense_backend/app/gateway/registry.pysurfsense_backend/app/gateway/inbox.pysurfsense_backend/app/gateway/inbox_processor.pysurfsense_backend/app/gateway/inbox_worker.pysurfsense_backend/app/gateway/agent_invoke.pysurfsense_backend/app/gateway/pairing.pysurfsense_backend/app/gateway/bindings.pysurfsense_backend/app/gateway/accounts.pysurfsense_backend/app/gateway/runner.pysurfsense_backend/app/gateway/byo_long_poll.pysurfsense_backend/app/routes/gateway_webhook_routes.pysurfsense_backend/app/routes/gateway_whatsapp_webhook_routes.pysurfsense_backend/app/routes/gateway_whatsapp_baileys_routes.pysurfsense_backend/app/routes/__init__.pysurfsense_backend/app/tasks/celery_tasks/gateway_tasks.pysurfsense_backend/app/celery_app.pysurfsense_backend/app/app.pysurfsense_backend/app/observability/metrics.pysurfsense_backend/scripts/whatsapp-bridge/bridge.jssurfsense_backend/scripts/whatsapp-bridge/Dockerfilesurfsense_backend/scripts/whatsapp-bridge/package.jsondocker/docker-compose.ymlsurfsense_backend/.env.examplesurfsense_backend/pyproject.tomlsurfsense_backend/scripts/docker/entrypoint.shsurfsense_backend/scripts/register_webhook.pysurfsense_web/app/dashboard/[search_space_id]/user-settings/components/MessagingChannelsContent.tsxsurfsense_web/app/dashboard/[search_space_id]/user-settings/layout-shell.tsxsurfsense_web/app/dashboard/[search_space_id]/user-settings/messaging-channels/page.tsxsurfsense_web/.env.examplesurfsense_web/zero/schema/chat.tssurfsense_web/content/docs/manual-installation.mdxsurfsense_backend/tests/unit/gateway/test_formatting.pysurfsense_backend/tests/unit/gateway/test_hitl_filter.pysurfsense_backend/tests/unit/gateway/test_pairing.pysurfsense_backend/tests/unit/gateway/test_webhook_routes.pysurfsense_backend/tests/unit/gateway/test_inbox_worker.pysurfsense_backend/tests/unit/gateway/test_byo_long_poll_lifespan.pysurfsense_backend/tests/unit/gateway/test_enqueue_received_sweep.pysurfsense_backend/tests/unit/gateway/test_process_inbound_event_task.py