The Universal Multi-Channel Messaging SDK for AI Agents, Autonomous Systems & Microservices
- Overview & Architecture
- How It Works Deep Dive
- Key Features
- Installation
- Quick Start
- Channel Adapters
- Rich Media, Stickers & GIFs
- SmartStreamer for LLMs
- Automated Personal Login
- Model Context Protocol (MCP) Server
- Security Hardening
- License
ChannelHub is an ultra-lightweight, zero-heavy-dependency messaging abstraction library designed for developers and AI systems. Instead of juggling distinct libraries (grammy, discord.js, zca-js, facebook-chat-api), ChannelHub bridges them all behind a single, ergonomic contract.
ββββββββββββββββββββββββββββββββββββββββββββ
β Your Application / β
β AI Agent Framework β
ββββββββββββββββββββββ¬ββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β ChannelHub β
β (Core Event Engine) β
βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ
β β β
ββββββββββββββββββββ΄βββ β ββββ΄βββββββββββββββββββ
βΌ βΌ βΌ βΌ βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Messenger β β Zalo β β Telegram β β Discord/Slack β
β Adapter β β Adapter β β Adapter β β Adapters β
βββββββββ¬ββββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ
β β β β
βΌ βΌ βΌ βΌ
Meta Graph API / zca-js Web API Telegram Bot Discord/Slack
Resumable Upload & Anti-Ban Q HTTP API Gateways
| Channel | Outbound Send | Inbound Ingestion | Rich Media & Attachments | Native Reactions | Streaming & Typing | Current Status |
|---|---|---|---|---|---|---|
| Zalo | β Full API (Personal/OA) | β Native Listener / Polling | β Image, Video, File, Sticker, GIF | β Full Native | β Typing & Sentence Stream | Stable Inbound/Outbound |
| Telegram | β Full Bot API | β Polling & Webhook Handler | β Photo, Video, File, Sticker, GIF | β Native Reactions | β Realtime In-place Edit Stream | Stable Inbound/Outbound |
| Messenger | β Graph API v19.0 (100MB) | β‘ Webhook Normalizer (normalizeEvent) |
β Image, Video, File, Sticker, GIF | β³ Planned v2.1 | β‘ Typing Indicator | Stable Outbound + Normalizer |
| Discord | β Bot REST API | β‘ Webhook Normalizer (normalizeEvent) |
β Embeds & Attachments | β Native Reactions | β‘ Realtime In-place Edit Stream | Stable Outbound + Normalizer |
| Slack | β Web API / Chat | β‘ Events Normalizer (normalizeEvent) |
β File & Media | β³ Planned v2.1 | β‘ Typing Indicator | Stable Outbound + Normalizer |
Every incoming payloadβregardless of whether it arrived from a Telegram Webhook, Discord WebSocket, or Meta Graph API payloadβis normalized into an immutable, cross-platform standard representation:
export interface UnifiedMessage {
id: string; // Normalized message identifier
channel: ChannelType; // "messenger" | "zalo" | "telegram" | "discord" | "slack"
sender: {
id: string;
name?: string;
username?: string;
avatarUrl?: string;
isBot?: boolean;
};
chat: {
id: string;
type: "dm" | "group" | "channel";
title?: string;
};
content: {
text: string;
attachments?: MediaAttachment[];
replyToId?: string;
};
raw: unknown; // Original vendor payload preserved for platform-specific access
timestamp: number;
}When an event occurs, ChannelHub constructs a MessageContext wrapper around the event. This decouples message reply logic from the underlying protocol:
- Calling
await ctx.reply("Hello")resolves the originating channel, routes through the target adapter, manages rate-limiting queues, and emits typing indicators automatically. - Calling
await ctx.sendMedia({ type: "image", source: "./image.png" })validates local paths against directory traversal, detects MIME headers, and handles chunked file uploading seamlessly.
- Unified Multi-Platform API: Write business logic once; execute identically on Messenger, Zalo, Telegram, Discord, and Slack.
- AI-Native MCP Daemon: Built-in stdio Model Context Protocol (MCP) server exposing 10 high-level tools for Claude Desktop, Hermes Agent, and Codex.
- SmartStreamer Token Batcher: Seamlessly converts LLM token streams into real-time in-place message edits or sentence-boundary chunks with typing indicators.
- Large Video Resumable Upload: Native support for video assets up to 100MB on Meta Messenger using the Graph API Attachment Upload protocol.
- Native Sticker & Animated GIF Engine: Send stickers and GIFs natively across all supported platforms.
- Zero Heavy Core: Core engine depends exclusively on Node.js / Bun standard library (
node:events, nativefetch).
# Recommended (Bun)
bun add @theowlops/channelhub
# NPM
npm install @theowlops/channelhub
# PNPM
pnpm add @theowlops/channelhubimport { ChannelHub } from "@theowlops/channelhub/core";
import { MessengerChannelAdapter } from "@theowlops/channelhub/channels/messenger";
import { TelegramChannelAdapter } from "@theowlops/channelhub/channels/telegram";
const hub = new ChannelHub();
// 1. Register Telegram
hub.register(new TelegramChannelAdapter({
botToken: process.env.TELEGRAM_BOT_TOKEN!
}));
// 2. Register Facebook Messenger
hub.register(new MessengerChannelAdapter({
pageId: process.env.MESSENGER_PAGE_ID!,
pageAccessToken: process.env.MESSENGER_PAGE_TOKEN!,
verifyToken: "my_webhook_secret"
}));
// 3. Central message dispatcher
hub.on("message", async (ctx) => {
console.log(`[${ctx.channel}] ${ctx.message.sender.name}: ${ctx.message.content.text}`);
if (ctx.message.content.text.startsWith("/echo ")) {
const replyText = ctx.message.content.text.replace("/echo ", "");
await ctx.reply(replyText);
}
});
await hub.startAll();Supports Meta Graph API v19.0 with webhook challenge verification, personal Playwright session recovery, and large file support.
import { MessengerChannelAdapter } from "@theowlops/channelhub/channels/messenger";
const messenger = new MessengerChannelAdapter({
pageAccessToken: "EAA...",
verifyToken: "custom_token",
pageId: "10029384912"
});Supports reverse-engineered Web API (zca-js) personal sessions and Official Account (OA) v3 OpenAPI. Includes anti-ban jitter algorithms and automatic quote object generation.
import { ZaloChannelAdapter } from "@theowlops/channelhub/channels/zalo";
const zalo = new ZaloChannelAdapter({
credentialsPath: "./credentials.json", // Auto-captured session
minDelayMs: 300,
maxDelayMs: 800
});Lightweight bot integration via Telegram Bot API with native webhook and polling dispatchers.
import { TelegramChannelAdapter } from "@theowlops/channelhub/channels/telegram";
const telegram = new TelegramChannelAdapter({
botToken: "123456:ABC-DEF..."
});ChannelHub normalizes rich media transmission across all platforms:
// 1. Send Images / Files via URL or Local Path
await ctx.sendMedia({
type: "image",
source: "https://example.com/art.png",
caption: "Concept Art"
});
// 2. Send Large Videos (Meta Resumable Upload up to 100MB)
await ctx.sendMedia({
type: "video",
source: "/var/media/demo_video.mp4"
});
// 3. Send Native Stickers
// Supports Telegram file_id, Zalo sticker ID, or Messenger sticker ID
await ctx.sendSticker("369239263222822");
// 4. Send Animated GIFs
await ctx.sendGif("https://media.giphy.com/media/cat.gif", "Cat Dancing");LLMs generate responses token by token. Direct API calls per token will hit rate-limits and get your bots banned. SmartStreamer solves this:
- Editable Channels (Discord, Telegram): Streams first chunk, then edits message at throttled intervals (
updateIntervalMs: 800). - Non-Editable Channels (Zalo, Messenger): Accumulates tokens and flushes them chunk by chunk on sentence boundaries (
.,!,?,\n) while emitting typing signals.
import { SmartStreamer } from "@theowlops/channelhub/core";
const streamer = new SmartStreamer(ctx, {
chunkSentences: true,
updateIntervalMs: 800
});
// Pipe tokens directly from OpenAI / Anthropic / Local LLM
for await (const chunk of llmTokenStream) {
await streamer.write(chunk);
}
await streamer.end();ChannelHub provides built-in browser automation via Playwright Chromium to extract sessions for personal accounts without requiring developer app verification.
bun run login:messengerLaunches an automated Chromium browser. Once you log into Facebook, it securely intercepts your c_user session cookies and writes messenger.credentials.json.
bun run zalohub --loginRenders a terminal QR code for instant scan-and-connect authentication.
ChannelHub ships with a standalone stdio JSON-RPC MCP server. Connect your AI agent directly to all your chat channels with zero boilerplate.
channelhub-mcpAdd to claude_desktop_config.json:
{
"mcpServers": {
"channelhub": {
"command": "bun",
"args": ["run", "channelhub-mcp"]
}
}
}channelhub_list_channels: List active registered channels.channelhub_get_status: Health-check channel connectivity.channelhub_send_message: Send or reply to messages with text.channelhub_send_media: Send photos, audio, documents, and videos.channelhub_send_sticker: Send native stickers to any channel.channelhub_send_gif: Send animated GIFs.channelhub_send_typing: Simulate human-like typing status.channelhub_edit_message: Edit previously dispatched messages.channelhub_add_reaction: React to messages with emojis.channelhub_broadcast: Broadcast a message across multiple channels in a single call.
- Localhost Loopback Default: Webhook bridge defaults to
127.0.0.1rather than0.0.0.0. - DoS Payload Limits: Enforces a strict 1MB JSON body size ceiling before socket termination.
- Path Traversal Guard: All file uploads run through
path.resolveand verifyfs.statSync().isFile(), preventing arbitrary file disclosure. - Credential Hygiene: Auto-masks sensitive tokens in logs (
[REDACTED]) and enforces.gitignorerules against credential files.
ChannelHub is licensed under the MIT License. Maintained by TheOwlOps Team.