Bridge channel bot conversations (Slack, Discord, Telegram) into the Chat UI in real-time.
_attach_chat_bridge(channel_id, bot, platform) is called in _start_channel_bot() right before the bot task is launched:
_attach_chat_bridge(channel_id, bot, platform)
_start_channel_bot()
1. on_message hook — Captures incoming platform messages and broadcasts channel_message events with sender name, platform, and icon
on_message
channel_message
2. _session.chat() wrapper — Wraps the agent's chat method so responses are also broadcast as channel_response events
_session.chat()
channel_response
3. Persistence — All messages saved to the datastore under session channel-{channel_id} for history on reload
channel-{channel_id}
| Function | Purpose |
|---|---|
| _handleChannelMessage(data) | Renders incoming platform user messages; auto-switches to channel session if on fresh chat |
_handleChannelMessage(data)
| _handleChannelResponse(data) | Renders agent responses from channel bots |
_handleChannelResponse(data)
| _appendChannelMsg(role, data) | Creates message DOM with platform badge, icon, sender name |
_appendChannelMsg(role, data)
| _markSessionUnread(sessionId) | Adds unread dot to sidebar for inactive channel sessions |
_markSessionUnread(sessionId)
Every broadcast is dispatched via asyncio.create_task() — the original bot message handling is never blocked. Errors in broadcasting are logged at debug level and swallowed — the bot continues normally even with zero Chat UI clients connected.
asyncio.create_task()
debug
Each channel gets a dedicated session: channel-{channel_id}. Platform icons:
| Platform | Icon |
| Slack | 💬 |
| Discord | 🎮 |
| Telegram | ✈️ |
| WhatsApp | 📱 |