@coopah/bentley-gateway
v0.3.0
Published
Multi-channel message router (WhatsApp, Slack, Telegram, Discord, Email, WebChat)
Readme
@coopah/bentley-gateway
Multi-channel message router for Bentley agents. Routes incoming messages from WhatsApp, Telegram, Slack, Discord, Email, and WebChat to the appropriate shell.
Install
pnpm add @coopah/bentley-gatewayThen install the adapter(s) you need:
pnpm add @whiskeysockets/baileys # WhatsApp
pnpm add telegraf # Telegram
pnpm add @slack/bolt # Slack
pnpm add discord.js # Discord
pnpm add imapflow nodemailer # Email (IMAP + SMTP)
pnpm add ws # WebChat (WebSocket)Dependencies
@coopah/bentley-core(required)
Peer Dependencies (all optional — install only what you use)
| Peer | Version | Channel |
|------|---------|---------|
| @whiskeysockets/baileys | >=6.0.0 | WhatsApp |
| telegraf | >=4.0.0 | Telegram |
| @slack/bolt | >=3.0.0 | Slack |
| discord.js | >=14.0.0 | Discord |
| imapflow | >=1.0.0 | Email (receive) |
| nodemailer | >=6.0.0 | Email (send) |
| ws | >=8.0.0 | WebChat |
Usage
import { createBentley } from "@coopah/bentley-core";
import { BentleyGateway, WhatsAppAdapter, TelegramAdapter } from "@coopah/bentley-gateway";
const bentley = createBentley({ plugins: [/* ... */] });
const gateway = new BentleyGateway();
// Add channels
gateway.addAdapter(new WhatsAppAdapter({ /* WhatsAppAdapterConfig */ }));
gateway.addAdapter(new TelegramAdapter({ botToken: process.env.TELEGRAM_BOT_TOKEN! }));
// Route messages to shells
const router = gateway.getRouter();
router.addRoute({ channelPattern: "whatsapp:*", shellId: "support-agent" });
router.addRoute({ channelPattern: "telegram:*", shellId: "telegram-bot" });
// Set the message handler (connects gateway → bentley)
gateway.setMessageHandler(async (channelId, senderId, text, shellId) => {
const result = await bentley.invoke(shellId, { input: text, threadId: senderId });
return result;
});
await gateway.start();API
BentleyGateway
addAdapter(adapter)— Register a channel adaptergetRouter()— Access theShellRouterfor message routing rulessetMessageHandler(handler)— Connect incoming messages to your Bentley instancestart()— Connect all adapters and begin listeningstop()— Disconnect all adapters
Adapters
Each adapter implements the channel-specific connection logic:
WhatsAppAdapter(config: WhatsAppAdapterConfig)TelegramAdapter(config: TelegramAdapterConfig)SlackAdapter(config: SlackAdapterConfig)DiscordAdapter(config: DiscordAdapterConfig)EmailAdapter(config: EmailAdapterConfig)WebChatAdapter(config: WebChatAdapterConfig)
Routing
ShellRouter— Maps channel patterns to shell IDsShellRoute—{ channelPattern: string, shellId: string }
Related Packages
| Package | Role |
|---------|------|
| @coopah/bentley-core | Core runtime (required) |
| @coopah/bentley-server | HTTP/SSE server |
License
MIT
