docs
Channels
Connect messaging platforms like Telegram, WhatsApp, and Discord to your Ninetrix agents. Users message your bot, and your agent responds — no custom webhook code needed.
What are channels?
Channels connect messaging platforms to your Ninetrix agents. Users message your bot on Telegram, WhatsApp, or Discord, and your agent processes and responds to those messages automatically. No custom webhook code, no polling logic — just connect a bot and add a trigger to your agentfile.yaml.
Supported platforms
| Platform | Transport | Notes |
|---|---|---|
| Telegram | Long-polling (local), Webhook (cloud) | Most stable, recommended for getting started |
| Discord | Persistent WebSocket via discord.py | Requires bot from Discord Developer Portal |
| Baileys Node.js bridge via Unix Domain Socket | Requires Node.js, QR code scan, use a dedicated number |
Quick start
Connect a channel
ninetrix channel connect telegram
Follow the interactive prompts to enter your bot token and verify the connection.
Add a channel trigger to agentfile.yaml
triggers:
- type: channel
channels: ["telegram"]
Run your agent
ninetrix run
Your agent is now live. Send a message to your bot on Telegram and it will respond.
Setting up Telegram
- Open Telegram and message @BotFather
- Send
/newbotand follow the prompts to create a bot and get your token - Run
ninetrix channel connect telegram - Enter the bot token when prompted
- Send
/startto your bot in Telegram to verify the connection - The bot is verified and ready to use
Setting up Discord
- Go to discord.com/developers/applications and create a new application
- Navigate to Bot in the sidebar and click Add Bot
- Copy the bot token
- Run
ninetrix channel connect discord - Enter the token when prompted
- Open the OAuth2 URL provided by the CLI to add the bot to your server
Setting up WhatsApp
- Ensure Node.js is installed (
node --version) - Run
ninetrix channel connect whatsapp - Scan the QR code displayed in your terminal with WhatsApp > Linked Devices > Link a Device
- Wait for verification to complete
agentfile.yaml configuration
The channel trigger supports several options for controlling behavior:
triggers:
- type: channel
channels: ["telegram", "discord"]
bot: "support_bot" # optional: specific bot name
session_mode: per_chat # per_chat (default) | per_message
verbose: true # print channel I/O to console
allowed_ids: ["123456789"] # optional: allowlist user/chat IDs
reject_message: "Not authorized" # message for blocked users
Session modes
| Mode | Behavior |
|---|---|
per_chat (default) | Same chat = same conversation thread. The agent remembers context from previous messages in the chat. |
per_message | Every message starts a fresh conversation. No history is carried over between messages. |
Named bots
You can connect multiple bots of the same platform type. Use the --bot flag to name them:
ninetrix channel connect telegram --bot support_bot
ninetrix channel connect telegram --bot sales_bot
Then reference a specific bot in your trigger:
triggers:
- type: channel
channels: ["telegram"]
bot: "support_bot"
Access control
Restrict who can interact with your bot using allowed_ids. Messages from other users receive the reject_message:
triggers:
- type: channel
channels: ["telegram"]
allowed_ids: ["123456789", "987654321"]
reject_message: "Sorry, this bot is private."
ninetrix run console output with verbose: true — it prints the chat ID for every incoming message.How it works
Local mode
ninetrix runinjects bot configs into the container as environment variables- ChannelManager starts adapters inside the container (Telegram long-polling, Discord WebSocket, WhatsApp Baileys bridge)
- Inbound messages are received by the adapter and forwarded via HTTP POST to the container's
/chatendpoint - The agent processes the message and returns a response
- The response is sent back to the user through the adapter
Cloud mode
In Ninetrix Cloud, Telegram uses webhooks instead of long-polling. The webhook URL points to the saas-api, which routes messages to the correct Fly machine running your agent.
Channel config storage
Channel configurations (bot tokens, chat IDs) are stored in ~/.agentfile/channels.yaml with chmod 600 permissions. This file is never committed to git.
The CLI and dashboard perform bidirectional sync — changes in either place are synced when you run ninetrix run or ninetrix channel status.
Environment variables
These environment variables are auto-injected into the container when a channel trigger is configured. You do not need to set them manually:
| Variable | Purpose |
|---|---|
AGENTFILE_CHANNEL_BOTS | JSON array of bot configs (auto-injected by ninetrix run) |
AGENTFILE_CHANNEL_SESSION_MODE | per_chat or per_message |
AGENTFILE_CHANNEL_VERBOSE | Print channel I/O to console |
AGENTFILE_CHANNEL_ALLOWED_IDS | Comma-separated allowlist of user/chat IDs |
AGENTFILE_CHANNEL_REJECT_MESSAGE | Message sent to blocked users |
ninetrix dev too. All conversations from channel messages appear in your dashboard alongside interactive runs.