Chat Channels
Architecture
Technical architecture of the Chat Channels system.
Architecture
Request Flow
┌──────────┐ Webhook ┌──────────────────────────────┐ insert ┌─────────────┐
│ Platform │ ──────────────▶│ /api/channels/[provider]/ │ ──────────▶│ agent_tasks │
│ (TG/DC/..)│ + secret │ webhook │ │ │
│ │◀──────────────│ verify → find channel by │◀────────── │ space = │
│ ✅ reply │ Bot API │ secret → create task in │ return │ default │
│ │ │ channel's defaultSpaceId │ │ space │
└──────────┘ └──────────────────────────────┘ └─────────────┘Key Design Decisions
- User-scoped — channels belong to a user, not a space. Each has a
defaultSpaceIdfor task creation. - Polymorphic adapters —
ChannelAdapterinterface withverify,registerWebhook,removeWebhook,parseMessage,reply. Adding a provider = one adapter file + register in registry. - Shared package — core schema, types, adapter interface, and all adapters live in
packages/share-domains/channels/for reuse across apps. - Webhook routing — each channel has a unique
webhookSecret; platforms send it in provider-specific headers. - Always 200 — webhook handler always returns 200 to prevent platform retries.
- Credentials server-side only — bot tokens are never exposed in API responses (VO only returns username + status).
Adding a New Provider
- Add the provider name to
CHANNEL_PROVIDERSinpackages/share-domains/channels/schema/chat-channels.ts - Create
packages/share-domains/channels/logic/adapters/{provider}.tsimplementingChannelAdapter - Register it in
packages/share-domains/channels/logic/registry.ts - Add the provider config to
PROVIDER_CONFIGin the UI component - Add documentation in
content/docs/{lang}/chat-channels/{provider}.mdx