@easbot/gateway
v0.3.23
Published
EASBot Gateway - AI Agent Server and Multi-channel Integration Platform - 支持 WebSocket、HTTP、Discord、Telegram、Slack 等多渠道集成
Maintainers
Readme
English | 中文
@easbot/gateway
EASBot Gateway - AI Agent 服务器与多渠道集成平台
特性
- 多渠道集成:支持 WebSocket、HTTP、Discord、Telegram、Slack、飞书、公众号 / 企业微信、iLink 个人微信等
- Agent 核心:基于 AI SDK 的 Agent 运行时
- 会话管理:支持多会话、多 Agent 并发
- 消息路由:智能消息路由和格式转换
- 事件系统:完善的事件驱动架构
- 插件系统:可扩展的插件机制
安装
pnpm add @easbot/gateway快速开始
启动服务器
import { createGateway } from '@easbot/gateway';
const gateway = createGateway({
server: {
port: 4096,
websocket: true,
},
agents: [
{
id: 'main',
model: 'anthropic/claude-3-5-sonnet',
},
],
});
await gateway.start();WebSocket 客户端
import { GatewayClient } from '@easbot/gateway';
const client = new GatewayClient('ws://localhost:4096');
await client.connect();
await client.sendMessage({
agent: 'main',
message: '你好!',
});
client.on('message', (msg) => {
console.log('收到:', msg.content);
});Telegram Bot
const gateway = createGateway({
telegram: {
botToken: process.env.TELEGRAM_BOT_TOKEN,
},
agents: [{ id: 'main' }],
});
await gateway.start();渠道配置
WebSocket
{
server: {
port: 4096,
path: '/ws',
}
}HTTP
{
server: {
http: {
port: 4097,
path: '/api',
}
}
}Discord
{
discord: {
botToken: 'YOUR_BOT_TOKEN',
guildId: 'YOUR_GUILD_ID',
}
}Telegram
{
telegram: {
botToken: 'YOUR_BOT_TOKEN',
}
}Slack
{
slack: {
botToken: 'xoxb-...',
signingSecret: 'YOUR_SIGNING_SECRET',
}
}Weixin (iLink 个人微信)
⚠️ 与 wechat(公众号 / 企业微信)不同 —— Weixin 走 iLink 个人号协议,一次只能托管一个微信用户。详见 docs/channel/weixin.md。
{
weixin: {
enabled: true,
// token / userId 不在配置里,通过 `easbot weixin login` 扫码写入 account.json
}
}# 1. 扫码绑定个人微信
easbot weixin login
# 2. 启动 Gateway(自动接管 weixin channel)
easbot gateway start
# 3. 陌生用户给 bot 发消息后,管理员授权配对码
easbot weixin access pair 123456login / access pair 都是独立 CLI 进程;Gateway 通过 fs.watch 自动 reload,无需重启。
API 文档
Gateway
主网关类,管理所有渠道和 Agent。
const gateway = createGateway(config);
await gateway.start();
await gateway.stop();GatewayClient
WebSocket 客户端,用于连接 Gateway。
const client = new GatewayClient(url);
await client.connect();
await client.sendMessage(message);
client.disconnect();Agent
Agent 实例配置。
interface AgentConfig {
id: string;
model: string;
systemPrompt?: string;
tools?: Tool[];
}开发
# 安装依赖
pnpm install
# 构建
pnpm build
# 测试
pnpm test
# 类型检查
pnpm type-check许可证
MIT
