OpenClaw 企业定制 私人订制工作流 优化运维 openclaw记忆优化 问题咨询解决 请加微信交流
微信: aixbwz
Messaging Gateway是Hermes的”连接中心”,通过一个统一接口让你的AI同时接入Telegram、Discord、Slack、WhatsApp等15+个消息平台。无论用户在哪个平台,AI都能响应,真正做到一处管理。这篇讲清楚Gateway是什么、支持哪些平台、怎么配置、以及高级用法。
Gateway是什么
Gateway是Hermes的消息汇聚层:
- 一个进程服务所有消息平台
- 统一的消息处理接口
- 多平台并发支持
- 独立会话管理
- 统一的认证和授权
你只需要运行一个Gateway,就能同时服务Telegram用户、Discord用户、Slack团队等。
支持的消息平台
| 平台 | 私聊 | 群聊 | 语音 | 文件 |
|---|---|---|---|---|
| Telegram | ✅ | ✅ | ✅ | ✅ |
| Discord | ✅ | ✅ | ✅ | ✅ |
| Slack | ✅ | ✅ | ❌ | ✅ |
| ✅ | ✅ | ❌ | ✅ | |
| Signal | ✅ | ✅ | ❌ | ❌ |
| Matrix | ✅ | ✅ | ❌ | ✅ |
| Mattermost | ✅ | ✅ | ❌ | ✅ |
| ✅ | ❌ | ❌ | ✅ | |
| SMS | ✅ | ❌ | ❌ | ❌ |
| DingTalk | ✅ | ✅ | ❌ | ✅ |
| Feishu | ✅ | ✅ | ❌ | ✅ |
| WeCom | ✅ | ✅ | ❌ | ✅ |
启动Gateway
命令行启动
hermes gateway
配置文件
# config.yaml
gateway:
port: 3000
host: "0.0.0.0"
debug: false
后台运行
# 用nohup后台运行
nohup hermes gateway > gateway.log 2>&1 &
# 或用systemd管理
sudo systemctl enable hermes-gateway
Telegram配置
telegram:
bot_token: "${TELEGRAM_BOT_TOKEN}"
allowed_users:
- 123456789
stream: true
voice_reply: true
获取Bot Token
- 搜索@BotFather
- 发送/newbot
- 按提示创建Bot
- 复制Token
获取用户ID
- 搜索@userinfobot
- 给它发消息
- 获取你的数字ID
Discord配置
discord:
bot_token: "${DISCORD_BOT_TOKEN}"
allowed_users:
- 123456789012345678
guild_id: 987654321098765432
stream: true
voice:
enabled: true
创建Discord Bot
- 访问Discord Developer Portal
- 创建Application
- 创建Bot
- 获取Token
- 开启Message Content Intent
- 用OAuth2 URL邀请Bot到服务器
开启必要权限
在Bot设置里开启Privileged Gateway Intents:
- PRESENCE INTENT
- SERVER MEMBERS INTENT
- MESSAGE CONTENT INTENT(最重要)
Slack配置
slack:
bot_token: "${SLACK_BOT_TOKEN}"
signing_secret: "${SLACK_SIGNING_SECRET}"
allowed_users:
- U12345678
app_level_token: "${SLACK_APP_LEVEL_TOKEN}"
创建Slack App
- 访问api.slack.com/apps
- 创建新App
- 选择”Bots”功能
- 配置OAuth Scopes
- 安装到工作区
- 获取Bot Token
配置Event Subscriptions
- 开启Event Subscriptions
- 添加Request URL
- 订阅事件:message.channels, message.im
WhatsApp配置
whatsapp: phone_number_id: "${WHATSAPP_PHONE_ID}" access_token: "${WHATSAPP_ACCESS_TOKEN}" webhook_verify_token: "${WHATSAPP_VERIFY_TOKEN}"WhatsApp需要通过Meta Business平台配置。
多平台同时配置
# config.yaml - 完整配置示例 gateway: port: 3000 host: "0.0.0.0" telegram: bot_token: "${TELEGRAM_BOT_TOKEN}" allowed_users: - 123456789 discord: bot_token: "${DISCORD_BOT_TOKEN}" allowed_users: - 987654321012345678 slack: bot_token: "${SLACK_BOT_TOKEN}" signing_secret: "${SLACK_SIGNING_SECRET}" allowed_users: - U12345678 whatsapp: phone_number_id: "${WHATSAPP_PHONE_ID}" access_token: "${WHATSAPP_ACCESS_TOKEN}"会话管理
平台隔离
每个平台的用户有独立会话:
Telegram用户A ←→ 会话A(独立上下文) Discord用户B ←→ 会话B(独立上下文) Slack用户C ←→ 会话C(独立上下文)跨平台识别
可以配置跨平台用户识别:
gateway: cross_platform: enabled: true users: - telegram: 123456789 discord: 987654321012345678 name: "张三"会话配置
gateway: session: max_history: 100 compress_threshold: 50 idle_timeout: 3600安全配置
全局白名单
gateway: security: allow_all: false allowed_platforms: - telegram - discord平台级白名单
telegram: allowed_users: - 123456789 discord: allowed_users: - 987654321012345678DM配对系统
如果没配置白名单,新用户DM Bot会收到配对码:
配对码: XKGH5N7P管理员审批后才能使用:
hermes pairing approve telegram XKGH5N7P hermes pairing listGateway命令
/new # 开始新对话 /reset # 重置当前对话 /model claude # 切换模型 /stop # 停止生成 /compress # 压缩上下文 /usage # 查看使用量 /status # 查看状态 /help # 帮助流式消息
gateway: stream: true开启后AI回复像ChatGPT一样逐字显示。
消息格式化
gateway: formatting: code_theme: "monokai" code_languages: - python - javascript - bash markdown: trueWebhook配置
对于需要Webhook的平台(如Telegram、Slack):
gateway: webhook: enabled: true host: "your-domain.com" port: 3000 path: "/webhook" tls: enabled: true cert: "/path/to/cert.pem" key: "/path/to/key.pem"Nginx反代配置
server { listen 443 ssl; server_name your-domain.com; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; location /telegram { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }监控和日志
查看连接状态
hermes gateway status查看日志
hermes logs --platform telegram hermes logs --platform discord设置日志级别
gateway: log_level: "info" # debug, info, warn, error常见问题
某个平台不响应?
检查:1)平台配置是否正确;2)Bot Token是否有效;3)白名单是否包含你的ID;4)Webhook是否正常。
多平台消息混乱?
每个平台会话独立,不应该混乱。如果混乱,检查是否有跨平台识别配置问题。
Webhook收不到消息?
检查:1)外网能否访问你的服务器;2)TLS证书是否有效;3)Nginx配置是否正确。
如何限制Bot只能在私聊响应?
群聊模式下需要@提及才响应,私聊直接响应。
总结
Gateway让Hermes成为真正的多平台AI助手:
- 15+平台同时接入
- 一个进程管理所有
- 独立会话,互不干扰
- 配置简单,扩展方便
- 支持Webhook和长连接
建议先接Telegram和Discord两个最常用的平台。
相关文章
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END








暂无评论内容