名称: telegram-pairing-customization
描述: 修改 OpenClaw 的 Telegram 配对逻辑,使未获批准的用户在通过审批前,每次发送 /start 消息时都能收到配对码。适用于用户需要在初次请求后重复获取配对码的场景,确保即使首次配对码丢失或错过,用户仍能持续获得配对指引。
本技能介绍如何修改 OpenClaw 的 Telegram 配对逻辑,使得未获批准的用户在每次发送 /start 消息时(而非仅首次)都能收到包含配对码的回复。
/start 都能收到配对消息在运行代码中搜索以下代码段:
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"))
});
}
将条件判断从 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"))
});
}
修改完成后,重启 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),确保用户每次请求都能收到有效的配对码/start 命令/start 命令,确认用户再次收到相同的配对码sudo)