OpenFang Multi-Channel Adapter Configuration Guide

18 min read

OpenFang supports over 40 channel adapters. This guide provides a detailed walkthrough for configuring six common adapters: CLI, WhatsApp Business API, Telegram Bot, Discord, Slack Socket Mode, and Web Chat widgets. Includes comprehensive solutions for multi-channel operation, context sharing, security hardening, and status monitoring.

OpenFang Multi-Channel Adapter Configuration Guide: Make Your Agent Ubiquitous

Slug: openfang-channel-setup-guide Category: usage-guides Target Keywords: OpenFang channel configuration, OpenFang adapters, OpenFang WhatsApp Telegram Search Intent: Informational (Users want to connect their Agent to different platforms) Target Word Count: ~1800 words Language: en


What is a Channel Adapter?

A Channel Adapter is the bridge between OpenFang and external platforms. Each adapter is responsible for converting messages from external platforms into a unified format that OpenFang understands, and translating the Agent's responses back into the platform's native format.

OpenFang's design philosophy is "Write your Agent logic once, run it on 40+ platforms." You don't need to rewrite your Agent for every platform—simply configure the corresponding channel adapter.

Currently, OpenFang supports over 40 channel adapters, covering instant messaging, social media, collaboration tools, email, and custom APIs.

Core Concepts of Channel Adapters

All channel adapters share the following design principles:

  • Unified Message Format: Regardless of the source channel, all messages are converted into the standard OpenFang Message format.
  • Isolated Sandboxes: Each channel adapter runs in an isolated sandbox; a failure in one channel does not affect others.
  • Hot Reloading: No need to restart the Agent after adding or modifying channel configurations.
  • Rate Limiting: Built-in rate limiting to prevent triggering platform API restrictions.

Common Channel Adapter Configurations

CLI Adapter

The CLI is the most basic adapter, suitable for development, debugging, and local use:

toml
[channels.cli]enabled = truehistory_size = 1000              # Number of session history entries to keepprompt_style = "rich"            # plain / rich / minimal

The CLI adapter works out of the box with no extra configuration required. It supports multi-line input, command completion, and syntax highlighting.

WhatsApp Adapter

WhatsApp is one of the most widely used instant messaging tools globally. Through the WhatsApp Business API, your Agent can interact directly with users on WhatsApp:

toml
[channels.whatsapp]enabled = trueapi_version = "v18.0"phone_number_id = "${WA_PHONE_NUMBER_ID}"access_token = "${WA_ACCESS_TOKEN}"verify_token = "${WA_VERIFY_TOKEN}"[channels.whatsapp.features]media_support = true             # Support for sending images/filesreply_buttons = true             # Support for interactive buttonsmax_message_length = 4096typing_indicator = true          # Show "typing..." status

Configuration steps:

  1. Create a WhatsApp app at Meta for Developers.
  2. Obtain your Phone Number ID and Access Token.
  3. Configure the Webhook URL (your OpenFang server address + /webhook/whatsapp).
  4. Enter the information into your OpenFang configuration.

Telegram Adapter

Telegram is one of the most popular communication platforms in the tech community, featuring simple configuration and a developer-friendly API:

toml
[channels.telegram]enabled = truebot_token = "${TELEGRAM_BOT_TOKEN}"allowed_users = []               # Leave empty for all usersadmin_users = ["@your_username"][channels.telegram.features]inline_queries = true            # Support for inline queriesmarkdown_support = truefile_upload = truemax_file_size_mb = 50

Configuration steps:

  1. Chat with @BotFather in Telegram to create a Bot.
  2. Obtain your Bot Token.
  3. Enter the token into your configuration file.

Discord Adapter

The Discord adapter supports both Server (Guild) and Direct Message modes:

toml
[channels.discord]enabled = truebot_token = "${DISCORD_BOT_TOKEN}"application_id = "${DISCORD_APP_ID}"[channels.discord.guilds]server_ids = ["1234567890"]      # Allowed server IDs[channels.discord.features]slash_commands = true            # Support for slash commandsthread_support = true            # Support for threadsembed_messages = true            # Rich text embed messages

Slack Adapter

Ideal for enterprise team collaboration scenarios:

toml
[channels.slack]enabled = truebot_token = "${SLACK_BOT_TOKEN}"signing_secret = "${SLACK_SIGNING_SECRET}"app_token = "${SLACK_APP_TOKEN}"[channels.slack.features]socket_mode = true               # Use Socket Mode (recommended, no public URL needed)thread_replies = truereaction_feedback = true

Slack recommends using Socket Mode, which eliminates the need for a public-facing Webhook URL, making it perfect for internal network deployments.

Web Chat Adapter

Embed an OpenFang chat window directly onto your website:

toml
[channels.webchat]enabled = trueport = 3000cors_origins = ["https://your-site.com"][channels.webchat.ui]theme = "auto"                   # light / dark / autologo_url = "/assets/agent-logo.png"welcome_message = "Hello! I am your OpenFang Agent. How can I help you today?"placeholder = "Type your question..."

After configuration, add this to your webpage:

html
<script src="https://your-server:3000/widget.js"></script><script>OpenFangWidget.init({ position: 'bottom-right' })</script>

Running Multiple Channels Simultaneously

OpenFang's architecture natively supports multi-channel concurrency. The Agent core maintains a unified session state, and all channels share the same context:

toml
# Enable multiple channels at once[channels]cli.enabled = truewhatsapp.enabled = truetelegram.enabled = truediscord.enabled = truewebchat.enabled = true[channels.routing]strategy = "context_aware"       # round_robin / context_aware / prioritypreserve_context = true          # Maintain context across channels for the same user

The context_aware routing strategy means: if a user starts a conversation on WhatsApp and switches to Telegram, the Agent will automatically load the previous context.

Channel Security Configuration

More channels mean a larger attack surface. OpenFang provides granular channel security controls:

toml
[channels.security]per_user_rate_limit = 30         # Max 30 messages per user per minuteper_channel_rate_limit = 100     # Max 100 messages per channel per minuterequire_auth = ["discord", "slack"]public_channels = ["webchat"]authenticated_channels = ["whatsapp", "telegram", "discord", "slack"][channels.security.content_filter]block_urls = falseblock_attachments = falsemax_prompt_length = 4000

Key security recommendations:

  • Enable strict rate limiting for publicly accessible channels (Web Chat).
  • In production, all non-CLI channels should require user authentication.
  • Regularly audit channel access logs.

Channel Status Monitoring

bash
# View status of all channelsopenfang channels list# Output example:# Channel        Status    Messages/24h   Errors   Latency# cli            ✅ active       0           0         -# telegram       ✅ active     156          2       120ms# whatsapp       ✅ active      89          0       250ms# discord        ⚠️ degraded    43          5       500ms# webchat        ✅ active      12          0        45ms# Restart a specific channelopenfang channels restart discord# View detailed channel logsopenfang channels logs telegram --level debug

FAQ

Do I need to restart the Agent to add a new channel?
No. OpenFang supports hot-reloading of channel configurations:

``bash
openfang channels reload
``

Is conversation history shared across different channels?
Yes, by default. Conversation history for the same user is shared across all channels, so you won't lose context when switching. If you require channel isolation, you can set preserve_context = false.
Does the WhatsApp adapter require a WhatsApp Business account?
Yes. The WhatsApp adapter uses the WhatsApp Business Platform API, which requires a verified Business account. Personal WhatsApp accounts do not support API integration.
How do I add a custom channel adapter?
OpenFang provides a Channel SDK. Simply implement the ChannelAdapter trait to create a custom adapter:

``rust
use openfang::channels::{ChannelAdapter, Message};

struct MyCustomChannel;
impl ChannelAdapter for MyCustomChannel {
async fn receive(&self) -> Vec<Message> { /* ... */ }
async fn send(&self, msg: Message) -> Result<()> { /* ... */ }
}
``

Next Steps

  • OpenFang Automated Workflow Guide: Orchestrate multi-channel Agents into automated workflows.
  • OpenFang Security Best Practices: Secure your multi-channel Agent deployments.