Skip to main content
Messaging Bots enable your AI agents to interact with users across Telegram, Discord, Slack, and WhatsApp.

Quick Start

Start a bot with a single command - no Python code required:
1

Set Environment Variables

# Telegram
export TELEGRAM_BOT_TOKEN="123456:ABC-DEF..."

# Discord
export DISCORD_BOT_TOKEN="MTIz..."

# Slack (requires both tokens)
export SLACK_BOT_TOKEN="xoxb-..."
export SLACK_APP_TOKEN="xapp-..."

# WhatsApp (Cloud API)
export WHATSAPP_ACCESS_TOKEN="EAAx..."
export WHATSAPP_PHONE_NUMBER_ID="123456789"
export WHATSAPP_VERIFY_TOKEN="my-secret-verify"
2

Start the Bot

# Telegram
praisonai bot telegram --token $TELEGRAM_BOT_TOKEN

# Discord
praisonai bot discord --token $DISCORD_BOT_TOKEN

# Slack
praisonai bot slack --token $SLACK_BOT_TOKEN --app-token $SLACK_APP_TOKEN

# WhatsApp Cloud API (starts a webhook server on port 8080)
praisonai bot whatsapp --token $WHATSAPP_ACCESS_TOKEN --phone-id $WHATSAPP_PHONE_NUMBER_ID

# WhatsApp Web Mode (no tokens needed — scan QR code)
praisonai bot whatsapp --mode web
A default agent is created automatically with basic assistant capabilities.
3

(Optional) Custom Agent

# Use a custom agent configuration
praisonai bot slack --token $SLACK_BOT_TOKEN --app-token $SLACK_APP_TOKEN --agent agents.yaml
agents.yaml:
name: support-bot
instructions: |
  You are a customer support assistant.
  Be helpful and concise.
llm: gpt-4o-mini
tools:
  - search_web

Supported Platforms

Bot Runtimes (Bidirectional — Send + Receive)

Bot ClassPlatformEnv VariableStatus
SlackBotSlackSLACK_BOT_TOKEN, SLACK_APP_TOKEN
DiscordBotDiscordDISCORD_BOT_TOKEN
TelegramBotTelegramTELEGRAM_BOT_TOKEN
WhatsAppBotWhatsApp BusinessWHATSAPP_ACCESS_TOKEN, WHATSAPP_PHONE_NUMBER_ID

Outbound Tools (Send-Only — Bot Runtime Coming Soon)

ToolPlatformEnv VariableBot Runtime
SignalToolSignalRequires signal-cli daemon🔜 Coming Soon
LineToolLINELINE_CHANNEL_ACCESS_TOKEN🔜 Coming Soon
iMessageTooliMessage (macOS only)No token needed🔜 Coming Soon
TwilioToolSMS/VoiceTWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN🔜 Coming Soon
WebexToolWebexWEBEX_ACCESS_TOKEN🔜 Coming Soon
XToolX (Twitter)X_API_KEY, X_API_SECRET🔜 Coming Soon
EmailToolEmail (Gmail/SMTP)EMAIL_USERNAME, EMAIL_PASSWORD🔜 Coming Soon
Outbound tools are from praisonai-tools for sending messages from agents. For receiving messages via bot runtime, use the CLI or Python SDK shown above.Install: pip install praisonai-tools

How It Works

ComponentRole
PlatformTelegram, Discord, Slack, or WhatsApp
BotMessage router and formatter
AgentAI processing and response
UserEnd user on messaging app

Socket Mode vs Webhook

PraisonAI bots support two connection modes:
ModeUse CaseRequirements
Socket ModeLocal development, behind firewallApp Token only
Webhook ModeProduction, high scalePublic URL with HTTPS
Socket Mode works by opening an outbound WebSocket connection to Slack/Discord. No public URL or port forwarding is needed - your bot initiates the connection from behind NAT/firewall.

Configuration Options

from praisonaiagents import BotConfig

config = BotConfig(
    token="bot-token",              # Bot authentication token
    webhook_url=None,               # Webhook URL (optional)
    command_prefix="/",             # Command prefix
    mention_required=True,          # Require @mention in groups
    typing_indicator=True,          # Show typing indicator
    max_message_length=4096,        # Max message length
    allowed_users=[],               # Allowed user IDs (empty = all)
    allowed_channels=[],            # Allowed channel IDs
    reply_in_thread=False,          # Reply in threads (default: inline)
    thread_threshold=500,           # Auto-thread if response > N chars (0 = disabled)
    group_policy="mention_only",    # Group chat policy: respond_all, mention_only, command_only
    auto_approve_tools=False,       # Auto-approve tool executions (skip confirmation)
)
OptionTypeDefaultDescription
tokenstr""Bot authentication token
webhook_urlstrNoneWebhook URL for webhook mode
command_prefixstr"/"Prefix for bot commands
mention_requiredboolTrueRequire @mention in channels (DMs never require mention)
typing_indicatorboolTrueShow typing indicator
max_message_lengthint4096Max message length
allowed_userslist[]Allowed user IDs
allowed_channelslist[]Allowed channel IDs
timeoutint30Request timeout
reply_in_threadboolFalseAlways reply in threads
thread_thresholdint500Auto-thread responses longer than N chars (0 = disabled)
group_policystr"mention_only"Group chat behavior: respond_all, mention_only, or command_only
default_toolslist["execute_command", ...]Default tools enabled for all bots
auto_approve_toolsboolFalseSkip tool execution confirmation (for trusted environments)
retry_attemptsint3Number of retry attempts for failed operations
polling_intervalfloat1.0Interval for polling mode (seconds)
Reply behavior:
  • Default: Inline replies in the channel
  • Auto-thread: Responses > 500 chars are automatically threaded
  • Force thread: Set reply_in_thread=True to always use threads
Group policy:
  • mention_only — Bot only responds when @mentioned (default, safest)
  • respond_all — Bot responds to every message in the group
  • command_only — Bot only responds to /commands

CLI Capabilities

Enable powerful agent features directly from the command line:

Memory

praisonai bot slack --memory
Bot remembers previous conversations

Knowledge/RAG

praisonai bot slack --knowledge \
  --knowledge-sources docs.pdf manual.txt
Answer from your documents

Skills

praisonai bot slack --skills researcher writer
Load named skill modules

Extended Thinking

praisonai bot slack --thinking high
Enable reflection mode (off/minimal/low/medium/high)
FlagDescriptionExample
--memoryEnable conversation memory--memory
--memory-providerMemory backend--memory-provider chroma
--knowledgeEnable RAG/knowledge--knowledge
--knowledge-sourcesSource files--knowledge-sources file.pdf
--skillsSkill modules--skills researcher
--thinkingThinking mode--thinking high
--webEnable web search--web
--web-providerSearch provider--web-provider duckduckgo
--browserEnable browser--browser
--toolsNamed tools--tools WikipediaTool
--sandboxSandbox mode--sandbox
--auto-approveAuto-approve tool executions--auto-approve

Platform Setup

  1. Message @BotFather on Telegram
  2. Send /newbot and follow prompts
  3. Copy the bot token
export TELEGRAM_BOT_TOKEN="123456:ABC-DEF..."
praisonai bot telegram --token $TELEGRAM_BOT_TOKEN

Bot Commands

Built-in commands available on all platforms:
CommandDescription
/helpShow available commands and agent info
/statusShow agent name, model, platform, and uptime
/newReset conversation session — starts a fresh chat
You can register custom commands programmatically:
bot.register_command("ping", my_handler, description="Check latency")
See Bot Chat Commands for full details on custom command registration and platform-specific behavior.

Common Patterns

from praisonaiagents import BotConfig

config = BotConfig(
    token="your-token",
    allowed_users=["user123", "user456"],
    allowed_channels=["channel789"]
)

CLI Commands

# Start Telegram bot
praisonai bot telegram --token $TOKEN

# Start Discord bot
praisonai bot discord --token $TOKEN

# Start Slack bot  
praisonai bot slack --token $TOKEN --app-token $APP_TOKEN

# Start WhatsApp bot (webhook server)
praisonai bot whatsapp --token $TOKEN --phone-id $PHONE_ID --verify-token $VERIFY

# With agent configuration
praisonai bot telegram --token $TOKEN --agent agents.yaml
The Slack bot uses Slack Bolt, Slack’s official Python framework. When running, you’ll see “⚡️ Bolt app is running!” - this confirms the bot is connected and listening.

WhatsApp Message Filtering (Web Mode)

By default, WhatsApp Web mode responds only to self-chat messages — when you message your own number. This prevents the bot from replying to every conversation on your account, including messages you send in other people’s chats.
Self-chat means messaging your own phone number — not just any message you send. Messages you send in other people’s chats or groups are filtered out by default.

CLI Flags

# Only responds when YOU message yourself
praisonai bot whatsapp --mode web

Python SDK

from praisonaiagents import Agent
from praisonai.bots import WhatsAppBot

agent = Agent(name="assistant", instructions="You are a helpful bot")

bot = WhatsAppBot(
    mode="web",
    agent=agent,
    allowed_numbers=["1234567890", "9876543210"],
    allowed_groups=["120363123456@g.us"],
    respond_to_all=False,  # default
)

import asyncio
asyncio.run(bot.start())

YAML Config

platform: whatsapp
mode: web

respond_to:
  - "1234567890"
  - "9876543210"
respond_to_groups:
  - "120363123456@g.us"
respond_to_all: false

agent:
  name: "My Assistant"
  instructions: "You are a helpful AI assistant."
  llm: "gpt-4o-mini"
praisonai bot start --config bot.yaml

Filtering Behavior Matrix

ScenarioDefault--respond-to 123--respond-to-groups g@g.us--respond-to-all
Self-chat (message your own number)
Your message in someone else’s chat
DM from 123
DM from 999
Group g@g.us
Other group
Old/offline messages
Phone numbers are normalized automatically — +1-234-567-890, 1234567890, and (123) 456-7890 all match the same number. Group IDs use WhatsApp’s JID format (e.g., 120363123456@g.us).Stale message guard: Messages older than when the bot connected are always dropped, even with --respond-to-all. This prevents replaying old conversations on reconnect.

Docker Deployment

Deploy bots using Docker for production environments:
# Create .env file
cat > .env << EOF
OPENAI_API_KEY=your-openai-key
SLACK_BOT_TOKEN=xoxb-your-slack-bot-token
SLACK_APP_TOKEN=xapp-your-slack-app-token
EOF

# Run with docker compose
docker compose up slack-bot -d

# View logs
docker compose logs -f slack-bot
docker-compose.yml:
version: '3.8'
services:
  slack-bot:
    image: python:3.11-slim
    environment:
      OPENAI_API_KEY: ${OPENAI_API_KEY}
      SLACK_BOT_TOKEN: ${SLACK_BOT_TOKEN}
      SLACK_APP_TOKEN: ${SLACK_APP_TOKEN}
    command: >
      bash -c "pip install praisonai slack-bolt slack-sdk &&
               praisonai bot slack"
    restart: unless-stopped
For production, build a dedicated Docker image instead of installing dependencies at runtime. See the docker/bots folder for ready-to-use Dockerfiles.

Production (Webhook Mode)

For production deployments with a public URL, use webhook mode instead of Socket Mode:
from praisonaiagents import BotConfig
from praisonai.bots import SlackBot

config = BotConfig(
    token="xoxb-your-slack-bot-token",
    webhook_url="https://your-domain.com",
    webhook_path="/slack/events"
)

bot = SlackBot(config=config)
bot.start()  # Listens on /slack/events
Configure in Slack API Console:
  1. Event Subscriptions → Enable Events
  2. Set Request URL: https://your-domain.com/slack/events
  3. Subscribe to bot events: app_mention, message.im
Webhook mode requires:
  • Public HTTPS URL with valid SSL certificate
  • Port 443 (or 80/88/8443 for Telegram)
  • Firewall rules allowing inbound connections

Multi-Channel Gateway

Run all bots simultaneously with a single gateway config: gateway.yaml:
agents:
  personal:
    name: "Personal Assistant"
    instructions: "You are a helpful personal assistant."
    llm: "gpt-4o-mini"
  support:
    name: "Support Agent"
    instructions: "You are a customer support agent."
    llm: "gpt-4o-mini"

channels:
  telegram:
    token: "${TELEGRAM_BOT_TOKEN}"
    routing:
      dm: "personal"
      group: "support"
      default: "personal"
  discord:
    token: "${DISCORD_BOT_TOKEN}"
    routing:
      dm: "personal"
      channel: "support"
      default: "support"
  slack:
    token: "${SLACK_BOT_TOKEN}"
    app_token: "${SLACK_APP_TOKEN}"
    routing:
      dm: "personal"
      channel: "support"
      default: "support"
  whatsapp:
    token: "${WHATSAPP_ACCESS_TOKEN}"
    phone_number_id: "${WHATSAPP_PHONE_NUMBER_ID}"
    verify_token: "${WHATSAPP_VERIFY_TOKEN}"
    webhook_port: 8080
    routing:
      dm: "personal"
      default: "personal"

  # Or use WhatsApp Web mode (no tokens needed):
  # whatsapp:
  #   mode: web
  #   routing:
  #     dm: "personal"
  #     default: "personal"
praisonai gateway --config gateway.yaml
The gateway uses routing rules to send messages to different agents based on context (DM vs group vs channel). Each channel can have its own routing configuration.

Zero-Code Mode (YAML Config)

Run a bot with a single YAML file — no Python code needed: bot.yaml:
platform: telegram
token: "${TELEGRAM_BOT_TOKEN}"

agent:
  name: "My Assistant"
  instructions: "You are a helpful AI assistant."
  llm: "gpt-4o-mini"
  memory: true
  web_search: true
  tools: [search_web]
praisonai bot start --config bot.yaml
The .env file in the current directory is auto-loaded, so you can store tokens there and reference them with ${VAR_NAME} syntax.

Token Types — When to Use What

Different platforms use different types of tokens. Here’s when to use each:

Telegram

TokenFormatWhen to Use
Bot Token123456:ABC-DEF...Always required. Get from @BotFather. Used for all bot operations.

Discord

TokenFormatWhen to Use
Bot TokenMTIz...Always required. Get from Discord Developer Portal → Bot → Reset Token. Used for bot authentication.

Slack

TokenFormatWhen to Use
Bot Tokenxoxb-...Always required. Get from OAuth & Permissions → Install to Workspace. Used for sending messages and API calls.
App Tokenxapp-...Required for Socket Mode (default). Get from Socket Mode settings. Enables WebSocket connection without a public URL.
Client ID12345.67890OAuth flow only. Used when building apps that are installed by multiple workspaces (not needed for single-workspace bots).
Client Secretd119ac...OAuth flow only. Used with Client ID for the OAuth2 authorization flow. Never expose publicly.
Common mistake: Using Client ID/Secret instead of Bot Token + App Token. For most bots, you only need:
  • SLACK_BOT_TOKEN (xoxb-…) — for API operations
  • SLACK_APP_TOKEN (xapp-…) — for Socket Mode connection
Client ID and Client Secret are only needed if you’re distributing your app to multiple Slack workspaces via OAuth.

WhatsApp

TokenFormatWhen to Use
Access TokenEAAx...Required. Get from Meta for Developers → WhatsApp → API Setup. Used for sending messages via Cloud API.
Phone Number ID123456789Required. Found in API Setup page. Identifies which WhatsApp business number to send from.
Verify TokenAny stringRequired for webhooks. A secret string you create. Must match in both Meta console and your environment.
App Secretabc123...Optional. Used to verify webhook signatures for security. Found in App Settings → Basic.

Best Practices

Never commit bot tokens to version control. Use environment variables or secure secret management.
Set allowed_users and allowed_channels to prevent unauthorized access to your bot.
Set mention_required=True to prevent the bot from responding to every message in group chats.
Configure retry_attempts and implement exponential backoff for API rate limits.

Multi-Agent Configuration

You can also define multiple agents in an agents.yaml file for complex workflows: agents.yaml:
agents:
  searcher:
    name: Researcher
    role: Web Researcher
    goal: Search the web for relevant information on the given topic
    instructions: |
      Search the web thoroughly for information on the user's query.
      Return comprehensive, accurate results with sources.
    tools:
      - search_web

  summarizer:
    name: Summarizer
    role: Content Summarizer
    goal: Create clear, concise summaries of information
    instructions: |
      Take the research findings and create a well-structured summary.
      Highlight key points and insights.
      Keep it concise but informative.

Inbound Message Debounce

When users send multiple rapid messages (e.g. “hey” → “can you” → “search for AI news”), debounce coalesces them into a single agent call — saving tokens and preventing duplicate responses.
from praisonaiagents import Agent
from praisonaiagents.bots import BotConfig
from praisonai.bots import Bot

agent = Agent(name="assistant", instructions="Be helpful")
config = BotConfig(debounce_ms=1500)  # 1.5s window

bot = Bot("telegram", agent=agent, config=config)
bot.run()
Set debounce_ms: 0 (default) to disable debouncing for real-time response bots. Recommended: 1000–2000ms for conversational bots.

Smart Message Chunking

Long agent responses are split at paragraph boundaries while preserving code fences — no more broken code blocks mid-message.
1

Paragraph boundaries

Split at blank lines (\n\n) first — keeps ideas together.
2

Sentence boundaries

If a paragraph is still too long, split at sentence endings (. ).
3

Hard split

Last resort: character-level split for very long single lines.
Code blocks wrapped in triple backticks are never split, even if they exceed max_message_length. This ensures your users always see complete, copyable code.
Smart chunking is enabled automatically for all bot adapters. No configuration needed. Override max_message_length in BotConfig to change the split threshold (default: 4096).

Session History

Bot agents automatically remember the last 20 messages per conversation — no extra dependencies required.
from praisonaiagents import Agent
from praisonai.bots import Bot

# History is injected automatically — zero config needed
agent = Agent(name="assistant", instructions="Be helpful")
bot = Bot("telegram", agent=agent)
bot.run()
# Agent now remembers last 20 messages per session
Setting memory=True (full memory with ChromaDB) requires pip install praisonaiagents[memory]. The default history=True injection uses zero extra dependencies.

Ack Reactions

Acknowledge inbound messages with an emoji reaction (e.g. ⏳) so users know the bot is processing, then swap to a done emoji (e.g. ✅) when the response is sent.
from praisonaiagents import Agent
from praisonaiagents.bots import BotConfig
from praisonai.bots import Bot

agent = Agent(name="assistant", instructions="Be helpful")
config = BotConfig(ack_emoji="", done_emoji="")

bot = Bot("telegram", agent=agent, config=config)
bot.run()
Set ack_emoji: "" (default) to disable ack reactions. Currently wired for Telegram (which supports native message reactions).

Session Reaper

Automatically prune stale sessions to free memory on long-running bots. Sessions idle longer than session_ttl seconds are reaped.
from praisonaiagents import Agent
from praisonaiagents.bots import BotConfig
from praisonai.bots import Bot

agent = Agent(name="assistant", instructions="Be helpful")
config = BotConfig(session_ttl=86400)  # Reap sessions older than 24h

bot = Bot("telegram", agent=agent, config=config)
bot.run()
Set session_ttl: 0 (default) to disable automatic reaping. You can also call bot._session.reap_stale(max_age_seconds) manually.

YAML Configuration

Deploy bots entirely from YAML — including agent memory, tools, roles, and multi-platform config.
agent:
  name: Research Bot
  role: AI Research Assistant
  goal: Help users find and understand AI research
  instructions: |
    You are a research assistant that helps users
    find and understand the latest AI research papers.
  llm: gpt-4o-mini
  memory:
    history: true
    history_limit: 30
  tools:
    - search_web

platforms:
  telegram:
    token: ${TELEGRAM_BOT_TOKEN}
    debounce_ms: 1500
  discord:
    token: ${DISCORD_BOT_TOKEN}
  slack:
    token: ${SLACK_BOT_TOKEN}
FieldTypeDescription
namestringAgent display name
rolestringRole/job title
goalstringPrimary objective
backstorystringBackground context
instructionsstringDirect instructions
llmstringModel name (gpt-4o-mini, claude-3-sonnet)
memorybool/dictMemory config (true or {history: true})
toolslistTool names from praisonaiagents.tools
knowledgelistKnowledge sources
guardrailstringOutput validation
Use ${ENV_VAR} in YAML values — resolved at load time.
platforms:
  telegram:
    token: ${TELEGRAM_BOT_TOKEN}

Tool Approval via Messaging

When your bot agent uses dangerous tools (e.g. execute_command), you can route approval requests to Slack:
from praisonaiagents import Agent
from praisonai.bots import Bot, SlackApproval

agent = Agent(
    name="assistant",
    instructions="You are a helpful assistant.",
    approval=SlackApproval(channel="#approvals")  # Approvals go to Slack
)

bot = Bot("telegram", agent=agent)  # Users talk via Telegram
bot.run()
See Approval Protocol for full configuration options.