Skip to main content

Universal multi-platform bot framework

Project description

pig-messenger

Universal Multi-Platform Bot Framework

One agent, multiple messaging platforms. Write once, deploy everywhere.

Features

  • Multi-Platform: Slack, Discord, Telegram, WhatsApp, Feishu
  • Plug-in Architecture: Easy to add new platforms
  • Powered by pig-agent-core: Full agent capabilities
  • Session Management: Per-channel conversation history
  • File Handling: Upload/download across platforms
  • Lazy Imports: Only install deps for the platforms you use

Supported Platforms

Platform Status Use Case
Slack ✅ Tested Enterprise (Global)
Discord ✅ Ready Developer Communities
Telegram ✅ Ready Personal & Groups
WhatsApp ✅ Ready Personal Communication
Feishu (飞书) ✅ Ready Enterprise (China)

Installation

# Base
pip install pig-messenger

# With Slack support
pip install pig-messenger[slack]

# With all platforms
pip install pig-messenger[all]

Quick Start

Slack Bot

import os
from pig_messenger import MessengerBot
from pig_messenger.adapters import SlackAdapter
from pig_agent_core import Agent
from pig_llm import LLM

agent = Agent(
    llm=LLM(provider="openrouter", model="moonshotai/kimi-k2.5",
            api_key=os.environ["OPENROUTER_API_KEY"]),
)

bot = MessengerBot(agent)
bot.add_platform(SlackAdapter(
    app_token=os.environ["SLACK_APP_TOKEN"],  # xapp-...
    bot_token=os.environ["SLACK_BOT_TOKEN"],  # xoxb-...
))
bot.start()

Multi-Platform Bot

from pig_messenger.adapters import SlackAdapter, DiscordAdapter, TelegramAdapter

bot = MessengerBot(agent)
bot.add_platform(SlackAdapter(
    app_token=os.environ["SLACK_APP_TOKEN"],
    bot_token=os.environ["SLACK_BOT_TOKEN"],
))
bot.add_platform(DiscordAdapter(bot_token=os.environ["DISCORD_BOT_TOKEN"]))
bot.add_platform(TelegramAdapter(bot_token=os.environ["TELEGRAM_BOT_TOKEN"]))
bot.start()  # All platforms run in parallel

Slack App Setup

  1. Create app at https://api.slack.com/apps → Create New App → From scratch
  2. Socket Mode: Settings → Socket Mode → Enable, generate App Token (xapp-..., scope: connections:write)
  3. Bot Permissions: Features → OAuth & Permissions → Bot Token Scopes:
    • app_mentions:read
    • chat:write
    • channels:history
    • files:read
    • files:write
    • users:read
  4. Event Subscriptions: Features → Event Subscriptions → Enable, subscribe to bot events:
    • app_mention
    • message.im
  5. Install: Settings → Install App → Install to Workspace, get Bot Token (xoxb-...)
  6. Invite bot to a channel: /invite @your-bot-name

Discord

  1. Create app at https://discord.com/developers
  2. Add bot with permissions: Read Messages, Send Messages, Attach Files
  3. Get bot token

Telegram

  1. Talk to @BotFather, create new bot
  2. Get token

Advanced Usage

Custom Tools for Bot

@tool(description="Search company knowledge base")
def search_kb(query: str) -> str:
    # Your implementation
    return f"Results for: {query}"

agent = Agent(
    llm=LLM(),
    tools=[search_kb, ...],
)

bot = MessengerBot(agent)

Per-Platform Configuration

# Different settings per platform
slack = SlackAdapter(...)
discord = DiscordAdapter(...)

bot.add_platform(slack)
bot.add_platform(discord)

# Each platform maintains separate sessions
# slack:C123 → session 1
# discord:987654 → session 2

Session Access

# Access sessions programmatically
sessions = bot.session_manager.list_sessions()

for key, session in sessions.items():
    print(f"{key}: {len(session.tree.entries)} messages")

Architecture

User Message (any platform)
    ↓
Platform Adapter (Slack/Discord/Telegram)
    ↓
UniversalMessage (standardized format)
    ↓
MessengerBot (routing)
    ↓
Agent (pig-agent-core)
    ↓
Response
    ↓
Platform Adapter (send back)
    ↓
User sees response

Custom Adapter

Create your own platform adapter:

from pig_messenger import MessagePlatform, UniversalMessage

class MyPlatformAdapter(MessagePlatform):
    def __init__(self, api_key):
        super().__init__("myplatform")
        self.api_key = api_key
    
    async def send_message(self, channel_id, text, **kwargs):
        # Your implementation
        pass
    
    async def get_history(self, channel_id, limit):
        # Your implementation
        return []
    
    def start(self):
        # Start listening
        pass
    
    def stop(self):
        # Cleanup
        pass

# Use it
bot.add_platform(MyPlatformAdapter(api_key="..."))

Testing

# Unit tests (no Slack credentials needed)
pytest packages/pig-messenger/tests/test_slack_adapter.py -v

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pig_messenger-0.0.2.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pig_messenger-0.0.2-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file pig_messenger-0.0.2.tar.gz.

File metadata

  • Download URL: pig_messenger-0.0.2.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pig_messenger-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7840453fb158c362ea4f8b1ae8d7976d9688f9e3f7511e0ca32029f10e88af71
MD5 24008b061156c8e884bf3b049c894644
BLAKE2b-256 d0950f8c9ee5893a79f2199441d7ea8278d0431ca64a411ddad18484de283004

See more details on using hashes here.

File details

Details for the file pig_messenger-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pig_messenger-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pig_messenger-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 935fe217cb8ee08d2e61a18b612d4f7ac8a391b48f54cb79e1cef22a9ff7b162
MD5 3fe0b6f6c8d2f1b42ac3c475fb034a60
BLAKE2b-256 b70d496a67012249709a760ff3d39776d2e9ae526bc9b4c9128a3801c4a4d1dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page