Architecture Overview
The channel system consists of three main components:1. Chat Channels
Each chat platform (Telegram, Discord, Slack) implements theBaseChannel interface defined in channels/base.py. Channels:
- Receive messages from their platform
- Wrap them as
InboundMessageobjects - Push them onto the
MessageBus - Subscribe to
OutboundMessageto deliver agent replies back to users
2. Message Bus
TheMessageBus (defined in bus/queue.py) provides async message passing between components:
Inbound Queue: Channels push incoming user messages here. The gateway pops messages, processes them through the agent, and generates responses.
Outbound Pub/Sub: The gateway publishes agent responses, and all subscribed channels receive them. Each channel filters for messages targeting their platform.
3. Channel Manager
TheChannelManager (in channels/manager.py) handles the lifecycle of all enabled channels:
- Loads channel configurations on startup
- Instantiates and starts enabled channels
- Gracefully stops all channels on shutdown
- Provides lookup for active channels
Message Flow
channel: Platform identifier (“telegram”, “discord”, “slack”)chat_id: Unique chat/channel identifieruser_id: User identifier for allowlist checkstext: Message contentmetadata: Platform-specific data (message IDs, timestamps, etc.)channel: Target platformchat_id: Destination chattext: Response text (supports Markdown)file_path: Optional file attachmentMessage Types
InboundMessage
OutboundMessage
file_path is set, channels send the file as an attachment (photo for images, document for other files) with text as the caption.
User Allowlists
All channels support optional user allowlists for access control:allow_from is empty or omitted, all users are allowed. Otherwise, only listed user IDs can send messages.
Message Splitting
Channels automatically split long responses to fit platform limits:- Telegram: 4,096 characters
- Discord: 2,000 characters
- Slack: 40,000 characters
BaseChannel.split_message() method intelligently splits on newline boundaries when possible, falling back to hard splits only when necessary.
File Attachments
All channels support sending files via thesend_file() method:
Telegram: Automatically detects image extensions (.png, .jpg, .jpeg, .gif, .webp) and sends as photos. Other files sent as documents.
Discord: Uses discord.File attachments with optional caption.
Slack: Uses files_upload_v2 API (fallback to files_upload for older SDK versions).
Available Channels
Telegram
Full bot with rich commands and media support
Discord
Discord bot with command prefix support
Slack
Socket Mode bot (no public URL required)
Next Steps
Set up Telegram
Create a Telegram bot and configure it with Grip AI
Set up Discord
Configure a Discord bot for your server