返回

Hermes Agent 教程 4:消息网关 — 多平台集成

将 Hermes Agent 部署到 Telegram、Discord、Slack、WhatsApp 或 Signal。本文介绍网关架构、平台配置步骤、语音转写、跨平台连续性,以及安全设置。

教程概述

系列索引: Hermes Agent 教程系列

本文介绍 Hermes Agent 的消息网关。这是它非常独特的一项能力,允许你同时把同一个 Agent 部署到多个消息平台。

你将学到什么

  • ✅ 消息网关架构及其工作原理
  • ✅ Telegram、Discord、Slack、WhatsApp、Signal 的配置方式
  • ✅ 语音备忘录转写
  • ✅ 跨平台会话连续性
  • ✅ 安全能力:私聊配对与命令审批

说明:如果你的目标是部署 Discord 或 Telegram 机器人,请先读这一篇。如果你更偏好纯终端工作流,可以转到 教程 5:CLI 与 TUI 指南

为什么多平台能力重要

Hermes 与桌面型 Agent 的差异

Claude Code、Cursor 和大多数 AI 助手都依赖你的桌面环境。Hermes Agent 则不同,它可以运行在 Telegram 群组、Discord 服务器、Slack 工作区或 Signal 中,而不只是你的笔记本电脑里。

flowchart TD
    A[Hermes Gateway] --> B[Telegram]
    A --> C[Discord]
    A --> D[Slack]
    A --> E[WhatsApp]
    A --> F[Signal]
    A --> G[CLI]

    B --> H[统一的 Agent 记忆]
    C --> H
    D --> H
    E --> H
    F --> H
    G --> H

    style A fill:#e1f5ff
    style H fill:#e8f5e9

核心收益

功能 收益
团队可访问 多个用户可与同一个 Agent 交互
持续在线 Agent 运行在服务器上,而非你的笔记本
记忆连续性 所有平台共享同一套记忆
语音支持 可自动转写语音消息

网关架构

它如何工作

flowchart LR
    A[平台 API] --> B[网关进程]
    B --> C[Hermes Agent]
    C --> D[记忆 / 技能]
    D --> C
    C --> B
    B --> A

    style B fill:#fff3e0

组件包括:

  1. 网关进程 — 以守护进程方式运行,监听所有平台
  2. 平台适配器 — 把各平台消息转换为 Hermes 可处理的格式
  3. Agent 核心 — 为所有平台共享一套记忆与技能

启动网关

# 初始化网关配置
hermes gateway setup

# 启动网关守护进程
hermes gateway start

# 查看状态
hermes gateway status

平台配置

平台对比

平台 配置复杂度 语音支持 群组支持
Telegram ✅ 完整 ✅ 支持
Discord ✅ 完整 ✅ 支持
Slack ✅ 有限 ✅ 支持
WhatsApp ✅ 完整 ❌ 仅私聊
Signal ✅ 完整 ❌ 仅私聊

Telegram 配置

步骤 1:创建机器人

  1. 打开 Telegram,搜索 @BotFather
  2. 发送 /newbot
  3. 为机器人命名,例如 My Hermes
  4. 获取 bot token

步骤 2:配置 Hermes

hermes gateway add telegram --token "YOUR_BOT_TOKEN"

步骤 3:启动并测试

hermes gateway start telegram

在 Telegram 中给你的 bot 发一条消息,Hermes 应该会返回响应。

Discord 配置

步骤 1:创建 Discord 应用

  1. 打开 Discord Developer Portal
  2. 点击 New Application
  3. 输入名称,例如 Hermes Agent
  4. 进入 Bot 页面,点击 Add Bot
  5. 复制 bot token

步骤 2:配置 Hermes

hermes gateway add discord --token "YOUR_DISCORD_TOKEN"

步骤 3:邀请机器人进服务器

创建邀请链接并授予以下权限:

  • Read Messages
  • Send Messages
  • Read Message History

步骤 4:启动网关

hermes gateway start discord

Slack 配置

步骤 1:创建 Slack App

  1. 打开 Slack API
  2. 创建新应用
  3. 添加 Bot Token Scopes:chat:writechannels:historygroups:history
  4. 安装到工作区
  5. 复制 Bot User OAuth Token

步骤 2:配置 Hermes

hermes gateway add slack --token "xoxb-YOUR-TOKEN"

步骤 3:启动网关

hermes gateway start slack

WhatsApp 配置

WhatsApp 需要接入 Meta Cloud API 或 Twilio。基础配置如下:

hermes gateway add whatsapp --provider twilio --account_sid "YOUR_SID" --auth_token "YOUR_TOKEN"

Signal 配置

Signal 集成依赖 Signal CLI:

# 先把 Signal CLI 与你的手机号绑定
signal-cli link -n "Hermes"

# 然后配置 Hermes
hermes gateway add signal --phone "+1234567890"

语音备忘录转写

它如何工作

Hermes 可以使用 ElevenLabs 或 Whisper 自动转写语音消息:

sequenceDiagram
    participant U as 用户
    participant P as 平台
    participant G as 网关
    participant T as 转写服务
    participant H as Hermes

    U->>P: 发送语音消息
    P->>G: 接收语音文件
    G->>T: 转写音频
    T->>G: 返回文本结果
    G->>H: 按文本处理
    H->>G: 返回响应
    G->>P: 发送响应
    P->>U: 文本回复

    style T fill:#fff3e0

启用语音转写

# 配置转写服务商
hermes config set transcription.provider elevenlabs

# 或改用 OpenAI Whisper
hermes config set transcription.provider whisper

支持格式

  • MP3、WAV、M4A(Telegram、Discord)
  • OGG(WhatsApp、Signal)
  • 单条最长 5 分钟

跨平台连续性

会话连续性

你可以在 Telegram 开始一个话题,再在 Discord 中继续,Hermes 仍然记得上下文:

flowchart TD
    A[Telegram: 调试认证 bug] --> B[写入记忆]
    B --> C[Discord: 那个 bug 怎么样了?]
    C --> D[从记忆中取回]
    D --> E[完整上下文恢复]
    E --> F[继续对话]

    style B fill:#e8f5e9
    style D fill:#e8f5e9

跨平台命令

所有平台都可用:

命令 用途
/new 开始新对话
/status 查看网关状态
/platforms 查看已连接平台
/sethome 设置首选主平台

主平台概念

你可以指定一个优先使用的平台:

/sethome telegram

Hermes 会:

  • 默认把定时报告发送到 Telegram
  • 把关键通知发往 Telegram
  • 将所有平台的记忆同步回 Telegram 上下文

安全

私聊配对

限制 Hermes 只响应已授权用户:

# 启用私聊配对模式
hermes config set security.dm_pairing true

# 绑定用户(用户需向 Hermes 发送 /pair code)
hermes gateway pair telegram --user "@username"

命令审批

为敏感命令启用审批机制:

# 配置需要审批的命令
hermes config set security.approval_commands "file:write,bash:execute"

触发后流程如下:

  1. Hermes 发起审批请求
  2. 你可在任意平台上批准或拒绝
  3. 只有批准后命令才会执行

速率限制

# 配置单用户限制
hermes config set security.rate_limit 10  # 每分钟消息数
hermes config set security.daily_limit 1000  # 每日 token 上限

管理网关

查看已连接平台

hermes gateway status

输出示例:

Platform     Status    Messages    Users
─────────────────────────────────────────
Telegram     Active    156         5
Discord      Active    89          3
Slack        Active    23          1
WhatsApp     Inactive  -           -
Signal       Inactive  -           -

重启指定平台

hermes gateway restart telegram

停止网关

hermes gateway stop

常见问题排查

平台没有响应

原因:网关进程停止,或 token 无效。

解决方案

hermes gateway status
hermes gateway restart PLATFORM

消息没有在不同平台之间同步

原因:跨平台记忆同步被禁用。

解决方案

hermes config set memory.cross_platform true

语音转写失败

原因:缺少 API key,或额度已超限。

解决方案

hermes config set transcription.api_key "YOUR_KEY"
hermes config set transcription.provider whisper

总结

消息网关是 Hermes 的部署优势

  1. 多平台支持 — Telegram、Discord、Slack、WhatsApp、Signal
  2. 网关架构 — 单一 Agent,可接入多个平台
  3. 语音支持 — 自动转写语音消息
  4. 连续性 — 所有平台共享同一套记忆
  5. 安全能力 — 私聊配对、审批、速率限制

关键要点

  • ✅ 网关以守护进程形式运行,并监听多个平台
  • ✅ 配置时需要各平台对应的 bot token
  • ✅ 语音备忘录可以自动转写
  • ✅ 记忆会在不同平台之间保持连续
  • ✅ 安全控制可以限制访问范围

系列导航:


决策说明:你现在已经掌握了两条部署路线中的一条。如果你从消息网关起步,那么 Hermes 已经能运行在 Telegram 或 Discord 上。若想补齐终端使用基础,请继续阅读 教程 5:CLI 与 TUI 指南。而教程 6 的多模型配置,对这两条路线都适用。