Skip to main content

Chat Providers

OpenPact supports multiple chat platforms simultaneously through a unified provider interface. Each provider connects your AI assistant to a different platform while sharing the same engine, MCP tools, and context files.

Supported Providers

ProviderLibraryConnectionCommands
DiscorddiscordgoWebSocketSlash commands (/new, /sessions, /switch, /context, /mode-*)
Telegramgo-telegram-bot-apiLong pollingBot commands (/new, /sessions, /switch, /context)
Slackslack-goSocket ModeSlash commands (/openpact-new, /openpact-context, etc.)

Architecture

All providers implement the same chat.Provider interface, which the orchestrator uses to manage message routing and session tracking.

┌─────────────┐   ┌─────────────┐   ┌─────────────┐
│ Discord │ │ Telegram │ │ Slack │
│ Client │ │ Client │ │ Client │
└──────┬───────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────────────┐
│ Chat Provider Interface │
│ SetMessageHandler() / SetCommandHandler() │
│ Start() / Stop() / SendMessage() │
└──────────────────────┬───────────────────────────┘


┌──────────────────────────────────────────────────┐
│ Orchestrator │
│ Per-channel session management │
│ Source context injection │
│ Unified command handling │
└──────────────────────┬───────────────────────────┘


┌──────────────────────────────────────────────────┐
│ AI Engine (OpenCode) │
└──────────────────────────────────────────────────┘

Per-Channel Sessions

Each (provider, channelID) pair gets its own independent session. This means:

  • A Discord channel #general has a separate conversation from Telegram group MyChat
  • Two Discord channels each maintain their own session and history
  • The /switch command only affects the channel where it was issued

Session mappings are persisted to <DataDir>/channel_sessions.json, and detail mode settings to <DataDir>/channel_modes.json:

{
"sessions": {
"discord:123456789": "ses_abc123",
"telegram:98765432": "ses_def456",
"slack:C12345678": "ses_ghi789"
}
}

Automatic Session Creation

If a channel has no active session when a message arrives, one is created automatically. You don't need to run /new before chatting.

Session Commands

All providers support the same commands:

CommandDiscordTelegramSlackDescription
New session/new/new/openpact-newStart a fresh conversation
List sessions/sessions/sessions/openpact-sessionsShow all sessions
Switch session/switch <id>/switch <id>/openpact-switch <id>Switch to existing session
Context usage/context/context/openpact-contextShow context window usage
Detail mode/mode-simple, /mode-thinking, /mode-tools, /mode-full/mode-simple, etc.Control response detail level (Discord docs)

Source Context

When a message arrives from any provider, the orchestrator prepends source information before sending it to the AI engine:

[via telegram, channel:98765432, user:12345]
What's the weather like today?

This lets the AI know which platform and channel a message came from, enabling provider-aware responses.

Unified chat_send MCP Tool

The AI can proactively send messages to any connected provider using the chat_send MCP tool:

{
"name": "chat_send",
"arguments": {
"provider": "telegram",
"target": "98765432",
"message": "Reminder: Your meeting starts in 15 minutes!"
}
}

The provider parameter determines which platform to send through. The target format depends on the provider:

ProviderTarget FormatExamples
DiscordChannel ID or user:<id> for DMs123456789, user:987654321
TelegramChat ID (numeric)98765432, -100123456789
SlackChannel ID or user IDC12345678, U12345678

Enabling Multiple Providers

Configure each provider in openpact.yaml:

discord:
enabled: true
allowed_users:
- "123456789012345678"

telegram:
enabled: true
allowed_users:
- "987654321"

slack:
enabled: true
allowed_users:
- "U12345678"
allowed_chans:
- "C12345678"

Set the corresponding environment variables:

DISCORD_TOKEN=your_discord_bot_token
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
SLACK_BOT_TOKEN=xoxb-your-slack-bot-token
SLACK_APP_TOKEN=xapp-your-slack-app-token

If a provider is enabled but its token is missing, OpenPact logs a warning and skips that provider. The remaining providers still start normally.

Admin UI Sessions

The Admin UI can create, view, and chat with any session — including those created by chat providers. Each chat provider channel tracks its own session independently, so actions in the Admin UI have no effect on which session a Discord channel or Telegram group is using, and vice versa.