Skip to content

9.4. Multi-Channel Messaging

Multi-Channel Messaging lets your agents respond to messages from external chat platforms — Telegram, Slack, Discord, and WhatsApp. Once configured, messages sent to your bot are routed to the appropriate Squad group for processing, and the agent's reply is sent back through the same channel.

Architecture

flowchart LR
    subgraph Channels
        TG[Telegram]
        SL[Slack]
        DC[Discord]
        WA[WhatsApp]
    end

    subgraph Backend.AI GO
        CR[Channel Registry]
        AL[Sender Allowlist]
        MR[Message Router]
        SQ[Squad Groups]
    end

    TG & SL & DC & WA --> CR
    CR --> AL
    AL -- allowed --> MR
    AL -- blocked --> X[Rejected]
    MR --> SQ
    SQ --> MR
    MR --> TG & SL & DC & WA

General Setup Process

For each channel:

  1. Create a bot or app in the platform's developer portal
  2. Copy the required tokens/credentials
  3. Connect the channel in Backend.AI GO
  4. Map the channel's chats to Squad groups
  5. (Optional) Configure the sender allowlist

Telegram

Create a Telegram Bot

  1. Open Telegram and start a chat with @BotFather.

  2. Send /newbot and follow the prompts:

    • Choose a display name (e.g., "My AI Assistant")
    • Choose a username ending in bot (e.g., myai_assistant_bot)
  3. BotFather replies with your Bot Token (format: 1234567890:ABCdef...). Copy it.

Connect Telegram in Backend.AI GO

  1. Go to Settings > Channels > Telegram.

  2. Paste your Bot Token into the token field.

  3. Click Validate Token to verify the token is valid.

  4. Click Connect.

  5. The status indicator turns green when the bot is connected.

Telegram Trigger Behavior

Chat Type Trigger
Direct message (DM) All messages trigger the bot
Group chat Messages that @mention the bot trigger it

JID Format

Telegram chat identifiers use the format tg:{chat_id} (e.g., tg:123456789).

Slack

Create a Slack App

  1. Go to api.slack.com/apps and click Create New App.

  2. Choose From scratch, enter an app name and select your workspace.

  3. In the left sidebar, click OAuth & Permissions.

  4. Under Bot Token Scopes, add these scopes:

    • app_mentions:read
    • channels:history
    • chat:write
    • groups:history
    • im:history
    • im:read
    • im:write
  5. Click Install to Workspace and authorize. Copy the Bot User OAuth Token (xoxb-...).

  6. In the left sidebar, click Socket Mode and enable it. Create an App-Level Token with connections:write scope. Copy the App Token (xapp-...).

  7. Under Event Subscriptions, enable events and subscribe to:

    • app_mention
    • message.im

Connect Slack in Backend.AI GO

  1. Go to Settings > Channels > Slack.

  2. Paste your Bot Token (xoxb-...) and App Token (xapp-...).

  3. Click Validate Tokens to verify both tokens.

  4. Click Connect.

Slack Trigger Behavior

Event Trigger
app_mention @mentioning the bot in a channel
message.im Any direct message to the bot

JID Format

Slack chat identifiers use the format slack:{channel_id} (e.g., slack:C01234567).

Discord

Create a Discord Bot

  1. Go to the Discord Developer Portal and click New Application.

  2. Give it a name and click Create.

  3. Click Bot in the left sidebar.

  4. Click Add Bot and confirm.

  5. Under Token, click Reset Token and copy the token.

  6. Under Privileged Gateway Intents, enable:

    • Message Content Intent (required to read message text)
  7. Click OAuth2 > URL Generator. Under Scopes, select bot. Under Bot Permissions, select:

    • Read Messages/View Channels
    • Send Messages
    • Read Message History
  8. Copy the generated OAuth2 URL and open it in a browser to invite the bot to your server.

Connect Discord in Backend.AI GO

  1. Go to Settings > Channels > Discord.

  2. Paste your Bot Token.

  3. Click Validate Token.

  4. Click Connect.

Discord Trigger Behavior

Chat Type Trigger
Guild text channel @mentioning the bot
Direct message All messages trigger the bot

JID Format

Discord chat identifiers use the format discord:{channel_id} (e.g., discord:123456789012345678).

WhatsApp Business

WhatsApp uses the WhatsApp Business Cloud API and requires a verified Meta business account.

Prerequisites

Configure WhatsApp Business API

  1. Go to developers.facebook.com and create a new app of type Business.

  2. Add the WhatsApp product to your app.

  3. In the WhatsApp setup, note your:

    • Phone Number ID (numeric ID of your WhatsApp phone number)
    • WhatsApp Business Account ID
  4. Generate a Permanent Access Token (or a temporary token for testing):

    • Go to Meta Business Suite > System Users
    • Create a system user with whatsapp_business_messaging permission
    • Generate a token for the system user
  5. Configure the Webhook:

    • Webhook URL: https://{your-domain}/api/v1/channels/whatsapp/webhook
    • Verify Token: any string you choose (used during webhook verification)
    • Subscribe to messages events

Public Webhook Required

WhatsApp requires a publicly accessible HTTPS webhook URL. Use a reverse proxy (nginx, Caddy) or a tunneling service (ngrok, Cloudflare Tunnel) to expose Backend.AI GO's Management API.

Connect WhatsApp in Backend.AI GO

  1. Go to Settings > Channels > WhatsApp.

  2. Fill in:

    • Phone Number ID: Your WhatsApp phone number ID
    • Access Token: Your permanent access token
    • Webhook Verify Token: The verify token you set in Meta's developer portal
  3. Click Validate Configuration.

  4. Click Connect.

  5. Trigger the webhook verification from Meta's developer portal by clicking Verify and Save.

WhatsApp Trigger Behavior

All incoming direct messages trigger the bot. Group messages are supported when the phone number is added to the group.

JID Format

WhatsApp chat identifiers use the format wa:{phone_number} (e.g., wa:15551234567).

Managing Connected Channels

View Channel Status

curl http://localhost:55765/api/v1/channels

Response:

{
  "channels": [
    {"name": "telegram", "connected": true, "statusMessage": "Connected"},
    {"name": "slack", "connected": true, "statusMessage": "Connected"},
    {"name": "discord", "connected": false, "statusMessage": "Not configured"},
    {"name": "whatsapp", "connected": false, "statusMessage": "Not configured"}
  ]
}

Disconnect a Channel

  1. Go to Settings > Channels > {Channel Name}.

  2. Click Disconnect.

Send a Message

curl -X POST http://localhost:55765/api/v1/channels/messages \
  -H "Content-Type: application/json" \
  -d '{"chatJid": "tg:123456789", "content": "Hello from Backend.AI GO!"}'

View Message History

# List all chats
curl http://localhost:55765/api/v1/channels/chats

# Get messages from a specific chat
curl "http://localhost:55765/api/v1/channels/chats/tg:123456789/messages?limit=50"

Sender Allowlist

The sender allowlist restricts which external users can interact with your agents. When configured, messages from senders not on the list are silently dropped.

Configure via Management API

curl -X PUT http://localhost:55765/api/v1/channels/sender-allowlist \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": true,
    "entries": [
      {"chatJid": "tg:123456789", "label": "Alice"},
      {"chatJid": "slack:U01ABCDEF", "label": "Bob"}
    ]
  }'

Behavior

Allowlist State Incoming Message Action
Disabled Any Process and route
Enabled Sender on list Process and route
Enabled Sender not on list Drop silently

Next Steps