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.

Start with Telegram
Telegram is the easiest channel to set up. Create a bot with @BotFather, connect it with one CLI command, and you are running in under 2 minutes.

Supported platforms

PlatformTransportNotes
TelegramLong-polling (local), Webhook (cloud)Most stable, recommended for getting started
DiscordPersistent WebSocket via discord.pyRequires bot from Discord Developer Portal
WhatsAppBaileys Node.js bridge via Unix Domain SocketRequires Node.js, QR code scan, use a dedicated number

Quick start

1

Connect a channel

Bash
ninetrix channel connect telegram

Follow the interactive prompts to enter your bot token and verify the connection.

2

Add a channel trigger to agentfile.yaml

agentfile.yaml
triggers:
  - type: channel
    channels: ["telegram"]
3

Run your agent

Bash
ninetrix run

Your agent is now live. Send a message to your bot on Telegram and it will respond.

Setting up Telegram

  1. Open Telegram and message @BotFather
  2. Send /newbot and follow the prompts to create a bot and get your token
  3. Run ninetrix channel connect telegram
  4. Enter the bot token when prompted
  5. Send /start to your bot in Telegram to verify the connection
  6. The bot is verified and ready to use

Setting up Discord

  1. Go to discord.com/developers/applications and create a new application
  2. Navigate to Bot in the sidebar and click Add Bot
  3. Copy the bot token
  4. Run ninetrix channel connect discord
  5. Enter the token when prompted
  6. Open the OAuth2 URL provided by the CLI to add the bot to your server

Setting up WhatsApp

Requirements
WhatsApp requires Node.js installed on your machine. Use a dedicated phone number — not your personal one — to avoid disruption to your main WhatsApp account.
  1. Ensure Node.js is installed (node --version)
  2. Run ninetrix channel connect whatsapp
  3. Scan the QR code displayed in your terminal with WhatsApp > Linked Devices > Link a Device
  4. Wait for verification to complete

agentfile.yaml configuration

The channel trigger supports several options for controlling behavior:

agentfile.yaml
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

ModeBehavior
per_chat (default)Same chat = same conversation thread. The agent remembers context from previous messages in the chat.
per_messageEvery 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:

Bash
ninetrix channel connect telegram --bot support_bot
ninetrix channel connect telegram --bot sales_bot

Then reference a specific bot in your trigger:

agentfile.yaml
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:

agentfile.yaml
triggers:
  - type: channel
    channels: ["telegram"]
    allowed_ids: ["123456789", "987654321"]
    reject_message: "Sorry, this bot is private."
Finding your chat ID
For Telegram, send a message to your bot and check the ninetrix run console output with verbose: true — it prints the chat ID for every incoming message.

How it works

Local mode

  1. ninetrix run injects bot configs into the container as environment variables
  2. ChannelManager starts adapters inside the container (Telegram long-polling, Discord WebSocket, WhatsApp Baileys bridge)
  3. Inbound messages are received by the adapter and forwarded via HTTP POST to the container's /chat endpoint
  4. The agent processes the message and returns a response
  5. 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:

VariablePurpose
AGENTFILE_CHANNEL_BOTSJSON array of bot configs (auto-injected by ninetrix run)
AGENTFILE_CHANNEL_SESSION_MODEper_chat or per_message
AGENTFILE_CHANNEL_VERBOSEPrint channel I/O to console
AGENTFILE_CHANNEL_ALLOWED_IDSComma-separated allowlist of user/chat IDs
AGENTFILE_CHANNEL_REJECT_MESSAGEMessage sent to blocked users
Dashboard integration
Channels work with ninetrix dev too. All conversations from channel messages appear in your dashboard alongside interactive runs.
On this page