brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
telegram-pairing-customizationModify OpenClaw's Telegram pairing logic so unapproved users receive pairing codes on every /start message before approval. Use when users need to repeatedly access pairing codes after the initial request, ensuring consistent access to pairing instructions even if the initial code was missed or lost.
Independent GitHub snapshot · Automated classification · Original documentation governs
此技能描述如何修改 OpenClaw 的 Telegram 配对逻辑,使未批准的用户在配对被批准前,每次发送 /start 消息时都能收到配对码回复。
/start 都收到配对消息(而非仅首次)运行提供的脚本来自动执行修改:
bash /root/.openclaw/workspace/skills/telegram-pairing-customization/scripts/apply-pairing-fix.sh
脚本将自动完成以下操作:
if (created) 为 if (code)如果需要手动修改,请按以下步骤操作:
在进行任何修改之前,备份原始文件:
cp /usr/lib/node_modules/openclaw/dist/telegram/bot-message-context.js /usr/lib/node_modules/openclaw/dist/telegram/bot-message-context.js.backup
文件路径:/usr/lib/node_modules/openclaw/dist/telegram/bot-message-context.js
找到以下原始代码段:
if (dmPolicy === "pairing") {
try {
const from = msg.from;
const telegramUserId = from?.id ? String(from.id) : candidate;
const { code, created } = await upsertTelegramPairingRequest({
chatId: candidate,
username: from?.username,
firstName: from?.first_name,
lastName: from?.last_name,
});
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")),
});
}
}
catch (err) {
logVerbose(`telegram pairing reply failed for chat ${chatId}: ${String(err)}`);
}
}
将条件判断从 if (created) 修改为 if (code):
if (dmPolicy === "pairing") {
try {
const from = msg.from;
const telegramUserId = from?.id ? String(from.id) : candidate;
const { code, created } = await upsertTelegramPairingRequest({
chatId: candidate,
username: from?.username,
firstName: from?.first_name,
lastName: from?.last_name,
});
if (code) { // Send pairing message if we have a valid code (either newly created or previously 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")),
});
}
}
catch (err) {
logVerbose(`telegram pairing reply failed for chat ${chatId}: ${String(err)}`);
}
}
修改完成后需要重启 OpenClaw 服务以使更改生效:
openclaw gateway restart
upsertTelegramPairingRequest 函数返回 {code, created} 对象created: true,有配对码created: false,但仍有相同的配对码(只要配对请求未过期或未被批准)if (code) 而不是 if (created),确保用户每次请求都能收到有效的配对码/start 命令/start 命令,确认用户再次收到相同的配对码