OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  telegram-pairing:对 OpenClaw 的 Telegram 实例配对流程进行深度定制

telegram-pairing:对 OpenClaw 的 Telegram 实例配对流程进行深度定制

 
  automation ·  2026-02-27 23:54:38 · 2 次点击  · 0 条评论  

名称: telegram-pairing-customization
描述: 修改 OpenClaw 的 Telegram 配对逻辑,使未获批准的用户在通过审批前,每次发送 /start 消息时都能收到配对码。适用于用户需要在初次请求后重复获取配对码的场景,确保即使首次配对码丢失或错过,用户仍能持续获得配对指引。


Telegram 配对消息持续响应技能

概述

本技能介绍如何修改 OpenClaw 的 Telegram 配对逻辑,使得未获批准的用户在每次发送 /start 消息时(而非仅首次)都能收到包含配对码的回复。

何时使用此技能

  • 需要让未批准用户每次发送 /start 都能收到配对消息
  • 用户可能错过首次配对消息,需要重新获取配对码
  • 希望提升用户体验,确保用户始终能获得清晰的配对指引

执行步骤

1. 定位需修改的文件

在运行代码中搜索以下代码段:

if (created) {
  logger.info({
    chatId: candidate,
    username: from?.username,
    firstName: from?.first_name,
    lastName: from?.last_name,
    matchKey: allowMatch.matchKey ?? "none",
    matchSource: allowMatch.matchSource ?? "none"
  }, "telegram pairing request");
  await withTelegramApiErrorLogging({
    operation: "sendMessage",
    fn: () => bot.api.sendMessage(chatId, [
      "OpenClaw: access not configured.",
      "",
      `Your Telegram user id: ${telegramUserId}`,
      "",
      `Pairing code: ${code}`,
      "",
      "Ask the bot owner to approve with:",
      formatCliCommand("openclaw pairing approve telegram <code>")
    ].join("\n"))
  });
}

2. 实施修改

将条件判断从 if (created) 改为 if (code)

if (code) { // <-- 关键修改点
  logger.info({
    chatId: candidate,
    username: from?.username,
    firstName: from?.first_name,
    lastName: from?.last_name,
    matchKey: allowMatch.matchKey ?? "none",
    matchSource: allowMatch.matchSource ?? "none"
  }, "telegram pairing request");
  await withTelegramApiErrorLogging({
    operation: "sendMessage",
    fn: () => bot.api.sendMessage(chatId, [
      "OpenClaw: access not configured.",
      "",
      `Your Telegram user id: ${telegramUserId}`,
      "",
      `Pairing code: ${code}`,
      "",
      "Ask the bot owner to approve with:",
      formatCliCommand("openclaw pairing approve telegram <code>")
    ].join("\n"))
  });
}

3. 重启服务

修改完成后,重启 OpenClaw 服务以使更改生效:

openclaw gateway restart

实用建议

  • 搜索 Ask the bot owner to approve with: 可快速缩小文件范围
  • 建议从 /usr/lib/node_modules/openclaw/ 目录开始查找

工作原理

  • upsertTelegramPairingRequest 函数返回 {code, created} 对象
  • 首次请求配对时:created: true,生成配对码
  • 再次请求配对时:created: false,但配对码仍有效(只要请求未过期或未批准)
  • 通过检查 if (code) 而非 if (created),确保用户每次请求都能收到有效的配对码

验证修改

  1. 让未配对的用户发送 /start 命令
  2. 确认用户收到配对码消息
  3. 再次发送 /start 命令,确认用户再次收到相同的配对码

注意事项

  • 修改系统文件前务必备份原始文件
  • OpenClaw 更新时可能覆盖修改,需重新应用
  • 需要足够的文件系统权限来修改安装文件
  • 修改后应进行功能测试

故障排除

  • 修改不生效:确认已正确重启 OpenClaw 服务
  • 找不到文件:确认 OpenClaw 的实际安装路径
  • 权限不足:使用适当权限提升方法(如 sudo
  • 回滚修改:使用备份文件替换修改后的文件
2 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor