mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-11 18:46:07 +00:00
* fix(telegram): bypass sequentializer for approval callback_queries Approval callback_queries from clicking inline buttons get the same sequential key as the blocked agent turn (telegram:<chatId>), causing a deadlock: the callback can't run because the lane is held, and the lane can't release because it's waiting for the callback. Give approval callbacks a separate lane (telegram:<chatId>:approval), same pattern as abort requests (telegram:<chatId>:control) and btw requests (telegram:<chatId>:btw). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * style(telegram): trim approval lane comments * fix: unblock Telegram approval callback deadlock (#64979) (thanks @nk3750) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Ayaan Zaidi <hi@obviy.us>
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
import { type Message, type UserFromGetMe } from "@grammyjs/types";
|
|
import { parseExecApprovalCommandText } from "openclaw/plugin-sdk/infra-runtime";
|
|
import { isAbortRequestText } from "openclaw/plugin-sdk/reply-runtime";
|
|
import { isBtwRequestText } from "openclaw/plugin-sdk/reply-runtime";
|
|
import { resolveTelegramForumThreadId } from "./bot/helpers.js";
|
|
|
|
export type TelegramSequentialKeyContext = {
|
|
chat?: { id?: number };
|
|
me?: UserFromGetMe;
|
|
message?: Message;
|
|
channelPost?: Message;
|
|
editedChannelPost?: Message;
|
|
update?: {
|
|
message?: Message;
|
|
edited_message?: Message;
|
|
channel_post?: Message;
|
|
edited_channel_post?: Message;
|
|
callback_query?: { message?: Message; data?: string };
|
|
message_reaction?: { chat?: { id?: number } };
|
|
};
|
|
};
|
|
|
|
export function getTelegramSequentialKey(ctx: TelegramSequentialKeyContext): string {
|
|
const reaction = ctx.update?.message_reaction;
|
|
if (reaction?.chat?.id) {
|
|
return `telegram:${reaction.chat.id}`;
|
|
}
|
|
const msg =
|
|
ctx.message ??
|
|
ctx.channelPost ??
|
|
ctx.editedChannelPost ??
|
|
ctx.update?.message ??
|
|
ctx.update?.edited_message ??
|
|
ctx.update?.channel_post ??
|
|
ctx.update?.edited_channel_post ??
|
|
ctx.update?.callback_query?.message;
|
|
const chatId = msg?.chat?.id ?? ctx.chat?.id;
|
|
const rawText = msg?.text ?? msg?.caption;
|
|
const botUsername = ctx.me?.username;
|
|
if (isAbortRequestText(rawText, botUsername ? { botUsername } : undefined)) {
|
|
if (typeof chatId === "number") {
|
|
return `telegram:${chatId}:control`;
|
|
}
|
|
return "telegram:control";
|
|
}
|
|
if (isBtwRequestText(rawText, botUsername ? { botUsername } : undefined)) {
|
|
const messageId = msg?.message_id;
|
|
if (typeof chatId === "number" && typeof messageId === "number") {
|
|
return `telegram:${chatId}:btw:${messageId}`;
|
|
}
|
|
if (typeof chatId === "number") {
|
|
return `telegram:${chatId}:btw`;
|
|
}
|
|
return "telegram:btw";
|
|
}
|
|
const callbackData = ctx.update?.callback_query?.data;
|
|
if (callbackData && parseExecApprovalCommandText(callbackData) !== null) {
|
|
if (typeof chatId === "number") {
|
|
return `telegram:${chatId}:approval`;
|
|
}
|
|
return "telegram:approval";
|
|
}
|
|
const isGroup = msg?.chat?.type === "group" || msg?.chat?.type === "supergroup";
|
|
const messageThreadId = msg?.message_thread_id;
|
|
const isForum = msg?.chat?.is_forum;
|
|
const threadId = isGroup
|
|
? resolveTelegramForumThreadId({ isForum, messageThreadId })
|
|
: messageThreadId;
|
|
if (typeof chatId === "number") {
|
|
return threadId != null ? `telegram:${chatId}:topic:${threadId}` : `telegram:${chatId}`;
|
|
}
|
|
return "telegram:unknown";
|
|
}
|