|
| 1 | +--- |
| 2 | +title: "Channels — Slack, Telegram, Discord, WhatsApp, Messenger" |
| 3 | +description: "Connect your Atmosphere agent to external messaging platforms with zero per-channel code" |
| 4 | +sidebar: |
| 5 | + order: 23 |
| 6 | +--- |
| 7 | + |
| 8 | +Atmosphere Channels bridges your `@Agent` (or `@AiEndpoint`) to external messaging platforms. Commands, AI responses, and confirmation flows work identically on every channel — you write the logic once. |
| 9 | + |
| 10 | +## Supported Channels |
| 11 | + |
| 12 | +| Channel | Protocol | Bot Setup | Env Variable | |
| 13 | +|---------|----------|-----------|-------------| |
| 14 | +| **Telegram** | Bot API webhooks | [@BotFather](https://t.me/BotFather) | `TELEGRAM_BOT_TOKEN` | |
| 15 | +| **Slack** | Events API | [api.slack.com/apps](https://api.slack.com/apps) | `SLACK_BOT_TOKEN` | |
| 16 | +| **Discord** | Gateway WebSocket | [discord.com/developers](https://discord.com/developers/applications) | `DISCORD_BOT_TOKEN` | |
| 17 | +| **WhatsApp** | Cloud API webhooks | [Meta Business Suite](https://business.facebook.com/) | `WHATSAPP_ACCESS_TOKEN` | |
| 18 | +| **Messenger** | Webhooks | [Meta for Developers](https://developers.facebook.com/) | `MESSENGER_PAGE_TOKEN` | |
| 19 | + |
| 20 | +## Dependencies |
| 21 | + |
| 22 | +```xml |
| 23 | +<dependency> |
| 24 | + <groupId>org.atmosphere</groupId> |
| 25 | + <artifactId>atmosphere-agent</artifactId> |
| 26 | +</dependency> |
| 27 | +<dependency> |
| 28 | + <groupId>org.atmosphere</groupId> |
| 29 | + <artifactId>atmosphere-channels</artifactId> |
| 30 | +</dependency> |
| 31 | +``` |
| 32 | + |
| 33 | +Channels activate automatically when credentials are set as environment variables. No channel-specific code is needed. |
| 34 | + |
| 35 | +## Telegram |
| 36 | + |
| 37 | +### 1. Create a bot |
| 38 | + |
| 39 | +Open Telegram, message [@BotFather](https://t.me/BotFather), and send: |
| 40 | + |
| 41 | +``` |
| 42 | +/newbot |
| 43 | +``` |
| 44 | + |
| 45 | +Follow the prompts — choose a name and username. BotFather replies with a token like: |
| 46 | + |
| 47 | +``` |
| 48 | +123456789:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw |
| 49 | +``` |
| 50 | + |
| 51 | +### 2. Set environment variables |
| 52 | + |
| 53 | +```bash |
| 54 | +export TELEGRAM_BOT_TOKEN=123456789:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw |
| 55 | +export TELEGRAM_WEBHOOK_SECRET=any-random-string-you-choose |
| 56 | +``` |
| 57 | + |
| 58 | +### 3. Expose your server publicly |
| 59 | + |
| 60 | +Telegram webhooks require HTTPS. Use [Cloudflare Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/) (free) or [ngrok](https://ngrok.com/): |
| 61 | + |
| 62 | +```bash |
| 63 | +# Cloudflare (recommended — no account required for quick tunnels) |
| 64 | +cloudflared tunnel --url http://localhost:8080 |
| 65 | + |
| 66 | +# Or ngrok |
| 67 | +ngrok http 8080 |
| 68 | +``` |
| 69 | + |
| 70 | +Copy the public URL (e.g. `https://your-tunnel.trycloudflare.com`). |
| 71 | + |
| 72 | +### 4. Register the webhook |
| 73 | + |
| 74 | +```bash |
| 75 | +curl "https://api.telegram.org/bot<YOUR_TOKEN>/setWebhook?url=https://<YOUR_TUNNEL>/webhook/telegram&secret_token=<YOUR_SECRET>" |
| 76 | +``` |
| 77 | + |
| 78 | +You should see `{"ok":true,"result":true,"description":"Webhook was set"}`. |
| 79 | + |
| 80 | +### 5. Start the app and test |
| 81 | + |
| 82 | +```bash |
| 83 | +TELEGRAM_BOT_TOKEN=<token> TELEGRAM_WEBHOOK_SECRET=<secret> \ |
| 84 | +./mvnw spring-boot:run -pl samples/spring-boot-dentist-agent |
| 85 | +``` |
| 86 | + |
| 87 | +Message your bot on Telegram — `/help`, `/firstaid`, or any question. |
| 88 | + |
| 89 | +### Verification |
| 90 | + |
| 91 | +Atmosphere verifies every Telegram webhook request using the `X-Telegram-Bot-Api-Secret-Token` header with constant-time comparison. Requests with missing or invalid secrets are rejected with 403. |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Slack |
| 96 | + |
| 97 | +### 1. Create a Slack app |
| 98 | + |
| 99 | +Go to [api.slack.com/apps](https://api.slack.com/apps) and click **Create New App** → **From scratch**. |
| 100 | + |
| 101 | +### 2. Configure bot scopes |
| 102 | + |
| 103 | +Under **OAuth & Permissions**, add these **Bot Token Scopes**: |
| 104 | + |
| 105 | +- `chat:write` — send messages |
| 106 | +- `channels:history` — read messages in public channels |
| 107 | +- `groups:history` — read messages in private channels |
| 108 | +- `im:history` — read direct messages |
| 109 | + |
| 110 | +### 3. Install to workspace |
| 111 | + |
| 112 | +Click **Install to Workspace** and authorize. Copy the **Bot User OAuth Token** (`xoxb-...`). |
| 113 | + |
| 114 | +### 4. Enable Events API |
| 115 | + |
| 116 | +Under **Event Subscriptions**: |
| 117 | + |
| 118 | +1. Turn on **Enable Events** |
| 119 | +2. Set the **Request URL** to `https://<YOUR_TUNNEL>/webhook/slack` |
| 120 | +3. Atmosphere automatically responds to Slack's URL verification challenge |
| 121 | +4. Under **Subscribe to bot events**, add: `message.channels`, `message.groups`, `message.im` |
| 122 | +5. Click **Save Changes** |
| 123 | + |
| 124 | +### 5. Get the signing secret |
| 125 | + |
| 126 | +Under **Basic Information** → **App Credentials**, copy the **Signing Secret**. |
| 127 | + |
| 128 | +### 6. Set environment variables and start |
| 129 | + |
| 130 | +```bash |
| 131 | +export SLACK_BOT_TOKEN=xoxb-your-bot-token |
| 132 | +export SLACK_SIGNING_SECRET=your-signing-secret |
| 133 | +``` |
| 134 | + |
| 135 | +### Verification |
| 136 | + |
| 137 | +Atmosphere verifies Slack requests using HMAC-SHA256 with the `v0:timestamp:body` scheme. Requests older than 5 minutes are rejected to prevent replay attacks. |
| 138 | + |
| 139 | +### Invite the bot |
| 140 | + |
| 141 | +Add the bot to a channel: type `/invite @YourBotName` in the channel. Then message it. |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## Discord |
| 146 | + |
| 147 | +### 1. Create a Discord application |
| 148 | + |
| 149 | +Go to [discord.com/developers/applications](https://discord.com/developers/applications) and click **New Application**. |
| 150 | + |
| 151 | +### 2. Create a bot |
| 152 | + |
| 153 | +Under **Bot**, click **Add Bot**. Copy the **Token**. |
| 154 | + |
| 155 | +### 3. Enable required intents |
| 156 | + |
| 157 | +Under **Bot** → **Privileged Gateway Intents**, enable: |
| 158 | + |
| 159 | +- **Message Content Intent** (required to read message text) |
| 160 | +- **Server Members Intent** (optional) |
| 161 | + |
| 162 | +### 4. Invite the bot to your server |
| 163 | + |
| 164 | +Under **OAuth2** → **URL Generator**: |
| 165 | + |
| 166 | +- Scopes: `bot` |
| 167 | +- Bot permissions: `Send Messages`, `Read Message History` |
| 168 | + |
| 169 | +Copy the generated URL and open it in your browser to invite the bot. |
| 170 | + |
| 171 | +### 5. Set environment variable and start |
| 172 | + |
| 173 | +```bash |
| 174 | +export DISCORD_BOT_TOKEN=your-discord-bot-token |
| 175 | +``` |
| 176 | + |
| 177 | +Discord uses a Gateway WebSocket connection (not HTTP webhooks), so no tunnel is needed. Atmosphere connects to Discord's gateway automatically, handles heartbeats, sequence tracking, and reconnection. |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## WhatsApp |
| 182 | + |
| 183 | +### 1. Set up a Meta Business account |
| 184 | + |
| 185 | +Go to [business.facebook.com](https://business.facebook.com/) and create a business account if you don't have one. |
| 186 | + |
| 187 | +### 2. Create a WhatsApp app |
| 188 | + |
| 189 | +In [Meta for Developers](https://developers.facebook.com/), create a new app of type **Business** and add the **WhatsApp** product. |
| 190 | + |
| 191 | +### 3. Get credentials |
| 192 | + |
| 193 | +Under **WhatsApp** → **API Setup**: |
| 194 | + |
| 195 | +- Copy the **Phone Number ID** |
| 196 | +- Generate a **Permanent Access Token** (or use the temporary one for testing) |
| 197 | +- Under **App Settings** → **Basic**, copy the **App Secret** |
| 198 | + |
| 199 | +### 4. Configure webhook |
| 200 | + |
| 201 | +Under **WhatsApp** → **Configuration**: |
| 202 | + |
| 203 | +- Callback URL: `https://<YOUR_TUNNEL>/webhook/whatsapp` |
| 204 | +- Verify token: any string (used only during initial verification) |
| 205 | +- Subscribe to: `messages` |
| 206 | + |
| 207 | +### 5. Set environment variables |
| 208 | + |
| 209 | +```bash |
| 210 | +export WHATSAPP_PHONE_NUMBER_ID=your-phone-number-id |
| 211 | +export WHATSAPP_ACCESS_TOKEN=your-access-token |
| 212 | +export WHATSAPP_APP_SECRET=your-app-secret |
| 213 | +``` |
| 214 | + |
| 215 | +### Verification |
| 216 | + |
| 217 | +Atmosphere verifies WhatsApp webhooks using HMAC-SHA256 via the `X-Hub-Signature-256` header (Meta platform standard). |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +## Messenger |
| 222 | + |
| 223 | +### 1. Create a Facebook Page |
| 224 | + |
| 225 | +You need a Facebook Page for your bot. Create one at [facebook.com/pages/create](https://www.facebook.com/pages/create). |
| 226 | + |
| 227 | +### 2. Create a Meta app |
| 228 | + |
| 229 | +In [Meta for Developers](https://developers.facebook.com/), create a new app and add the **Messenger** product. |
| 230 | + |
| 231 | +### 3. Generate a Page Access Token |
| 232 | + |
| 233 | +Under **Messenger** → **Access Tokens**, select your Page and generate a token. |
| 234 | + |
| 235 | +### 4. Configure webhook |
| 236 | + |
| 237 | +Under **Messenger** → **Webhooks**: |
| 238 | + |
| 239 | +- Callback URL: `https://<YOUR_TUNNEL>/webhook/messenger` |
| 240 | +- Verify token: any string |
| 241 | +- Subscribe to: `messages` |
| 242 | + |
| 243 | +### 5. Set environment variables |
| 244 | + |
| 245 | +```bash |
| 246 | +export MESSENGER_PAGE_TOKEN=your-page-access-token |
| 247 | +export MESSENGER_APP_SECRET=your-app-secret |
| 248 | +``` |
| 249 | + |
| 250 | +### Verification |
| 251 | + |
| 252 | +Same HMAC-SHA256 scheme as WhatsApp (Meta platform standard). |
| 253 | + |
| 254 | +--- |
| 255 | + |
| 256 | +## application.yaml |
| 257 | + |
| 258 | +All channels are configured via environment variables. The Spring Boot configuration maps them: |
| 259 | + |
| 260 | +```yaml |
| 261 | +atmosphere: |
| 262 | + packages: com.example.myagent |
| 263 | + |
| 264 | +atmosphere.channels: |
| 265 | + telegram: |
| 266 | + bot-token: ${TELEGRAM_BOT_TOKEN:} |
| 267 | + webhook-secret: ${TELEGRAM_WEBHOOK_SECRET:} |
| 268 | + slack: |
| 269 | + bot-token: ${SLACK_BOT_TOKEN:} |
| 270 | + signing-secret: ${SLACK_SIGNING_SECRET:} |
| 271 | + discord: |
| 272 | + bot-token: ${DISCORD_BOT_TOKEN:} |
| 273 | + whatsapp: |
| 274 | + phone-number-id: ${WHATSAPP_PHONE_NUMBER_ID:} |
| 275 | + access-token: ${WHATSAPP_ACCESS_TOKEN:} |
| 276 | + app-secret: ${WHATSAPP_APP_SECRET:} |
| 277 | + messenger: |
| 278 | + page-access-token: ${MESSENGER_PAGE_TOKEN:} |
| 279 | + app-secret: ${MESSENGER_APP_SECRET:} |
| 280 | +``` |
| 281 | +
|
| 282 | +Each channel activates only when its credentials are set. You can enable one, some, or all simultaneously. |
| 283 | +
|
| 284 | +## Message Filtering |
| 285 | +
|
| 286 | +Atmosphere provides a `ChannelFilter` chain for processing messages before and after they reach the agent: |
| 287 | + |
| 288 | +- **MessageSplittingFilter** — automatically truncates messages that exceed the channel's max length (4096 for Telegram, 40000 for Slack, 2000 for Discord/Messenger) |
| 289 | +- **AuditLoggingFilter** — logs all inbound/outbound messages at INFO level |
| 290 | + |
| 291 | +Custom filters implement `ChannelFilter` and are auto-discovered via Spring Boot component scanning. |
| 292 | + |
| 293 | +## Samples |
| 294 | + |
| 295 | +| Sample | Channels | Description | |
| 296 | +|--------|----------|-------------| |
| 297 | +| [spring-boot-dentist-agent](https://github.com/Atmosphere/atmosphere/tree/main/samples/spring-boot-dentist-agent) | Web + Slack + Telegram | Dr. Molar dental emergency agent with commands and AI tools | |
| 298 | +| [spring-boot-channels-chat](https://github.com/Atmosphere/atmosphere/tree/main/samples/spring-boot-channels-chat) | All 5 channels | Omnichannel AI chat with all platforms | |
0 commit comments