Phase 1 / Ep 06: 你的第一条消息 —— 从 CLI 到 Telegram 的完整对话流
🎯 学习目标:成功发送第一条消息并理解消息的完整流转路径。
1. CLI 直接对话
最简单的方式——直接在终端和 Agent 对话:
# 启动交互式聊天
openclaw chat
# 或者单条消息模式
openclaw chat "今天天气怎么样?"
交互式模式下,你会看到:
🦀 OpenClaw Chat (personal)
Type /help for commands, /quit to exit
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
You: 你好,自我介绍一下
Agent: 你好!我是你的 OpenClaw 个人 Agent。
我运行在你的本地机器上,可以帮你:
- 搜索互联网
- 管理文件
- 执行 Shell 命令
- 设置提醒
有什么我能帮你的吗?
2. 接入 Telegram
Step 1: BotFather 创建 Bot
- 在 Telegram 中搜索
@BotFather - 发送
/newbot - 按提示填写 Bot 名称和用户名
- 获得 Bot Token:
7123456789:AAH...
Step 2: 添加 Telegram 频道
openclaw channels add telegram --token "7123456789:AAH..."
Step 3: 配对(Pairing)
向你的 Bot 发送任意消息,Agent 会返回一个 Pairing Code。在 CLI 中确认:
openclaw channels pair <code>
配对完成!现在你可以直接在 Telegram 中和 Agent 对话了。
3. 消息流转全链路
sequenceDiagram
actor User as 🧑 用户
participant TG as 📱 Telegram Bot
participant GW as 🦀 Gateway
participant Auth as 🔐 认证引擎
participant Perm as 🛡️ 权限检查
participant Agent as 🤖 Agent
participant Boot as 📋 Bootstrap
participant Mem as 🧠 Memory
participant LLM as 🧪 Claude API
User->>TG: "帮我查一下明天北京的天气"
TG->>GW: Webhook 推送
GW->>Auth: 验证用户身份
Auth->>Perm: 检查权限等级
Perm->>Agent: 路由到 personal Agent
Note over Agent: 初始化上下文
Agent->>Boot: 加载 SOUL.md, USER.md...
Agent->>Mem: 检索相关记忆
Agent->>LLM: 组装 Prompt + Tool 定义
LLM->>Agent: 返回 tool_use: web_search
Agent->>Agent: 执行 web_search("北京明天天气")
Agent->>LLM: 提交工具执行结果
LLM->>Agent: 返回最终回复
Agent->>GW: 传递响应
GW->>TG: 推送回复
TG->>User: "明天北京:晴,28°C / 17°C\n空气质量:良"4. CLI vs Telegram 对比
| 操作 | CLI | Telegram |
|---|---|---|
| 发消息 | openclaw chat "xxx" |
直接发消息 |
| 清除会话 | openclaw sessions clear |
/clear |
| 查看帮助 | openclaw --help |
/help |
| 查看状态 | openclaw status |
/status |
| 退出 | /quit 或 Ctrl+C |
N/A(关闭聊天即可) |
5. 恭喜你!
你的 Agent 已经活了。它运行在你的机器上,拥有你给它的身份(SOUL.md),了解你是谁(USER.md),并且正在学习记忆你们的对话。
从下一章开始,我们将深入 CLI 命令体系——掌握 OpenClaw 的每一个命令,成为真正的 Agent 管理员。
下节预告: Ep 07,进入 Phase 2!我们从 Gateway 的生命周期管理开始:start, stop, restart, daemon 模式。每个命令都会同步展示 CLI 和 Telegram 的等效操作。