mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 09:47:40 +00:00
fix(telegram): surface REACTION_INVALID as non-fatal warning (#14340)
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -59,6 +59,37 @@ describe("handleTelegramAction", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("surfaces non-fatal reaction warnings", async () => {
|
||||||
|
reactMessageTelegram.mockResolvedValueOnce({
|
||||||
|
ok: false,
|
||||||
|
warning: "Reaction unavailable: ✅",
|
||||||
|
});
|
||||||
|
const cfg = {
|
||||||
|
channels: { telegram: { botToken: "tok", reactionLevel: "minimal" } },
|
||||||
|
} as OpenClawConfig;
|
||||||
|
const result = await handleTelegramAction(
|
||||||
|
{
|
||||||
|
action: "react",
|
||||||
|
chatId: "123",
|
||||||
|
messageId: "456",
|
||||||
|
emoji: "✅",
|
||||||
|
},
|
||||||
|
cfg,
|
||||||
|
);
|
||||||
|
const textPayload = result.content.find((item) => item.type === "text");
|
||||||
|
expect(textPayload?.type).toBe("text");
|
||||||
|
const parsed = JSON.parse((textPayload as { type: "text"; text: string }).text) as {
|
||||||
|
ok: boolean;
|
||||||
|
warning?: string;
|
||||||
|
added?: string;
|
||||||
|
};
|
||||||
|
expect(parsed).toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
warning: "Reaction unavailable: ✅",
|
||||||
|
added: "✅",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("adds reactions when reactionLevel is extensive", async () => {
|
it("adds reactions when reactionLevel is extensive", async () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
channels: { telegram: { botToken: "tok", reactionLevel: "extensive" } },
|
channels: { telegram: { botToken: "tok", reactionLevel: "extensive" } },
|
||||||
|
|||||||
@@ -109,11 +109,18 @@ export async function handleTelegramAction(
|
|||||||
"Telegram bot token missing. Set TELEGRAM_BOT_TOKEN or channels.telegram.botToken.",
|
"Telegram bot token missing. Set TELEGRAM_BOT_TOKEN or channels.telegram.botToken.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await reactMessageTelegram(chatId ?? "", messageId ?? 0, emoji ?? "", {
|
const reactionResult = await reactMessageTelegram(chatId ?? "", messageId ?? 0, emoji ?? "", {
|
||||||
token,
|
token,
|
||||||
remove,
|
remove,
|
||||||
accountId: accountId ?? undefined,
|
accountId: accountId ?? undefined,
|
||||||
});
|
});
|
||||||
|
if (!reactionResult.ok) {
|
||||||
|
return jsonResult({
|
||||||
|
ok: false,
|
||||||
|
warning: reactionResult.warning,
|
||||||
|
...(remove || isEmpty ? { removed: true } : { added: emoji }),
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!remove && !isEmpty) {
|
if (!remove && !isEmpty) {
|
||||||
return jsonResult({ ok: true, added: emoji });
|
return jsonResult({ ok: true, added: emoji });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -596,7 +596,7 @@ export async function reactMessageTelegram(
|
|||||||
messageIdInput: string | number,
|
messageIdInput: string | number,
|
||||||
emoji: string,
|
emoji: string,
|
||||||
opts: TelegramReactionOpts = {},
|
opts: TelegramReactionOpts = {},
|
||||||
): Promise<{ ok: true }> {
|
): Promise<{ ok: true } | { ok: false; warning: string }> {
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
const account = resolveTelegramAccount({
|
const account = resolveTelegramAccount({
|
||||||
cfg,
|
cfg,
|
||||||
@@ -633,7 +633,15 @@ export async function reactMessageTelegram(
|
|||||||
if (typeof api.setMessageReaction !== "function") {
|
if (typeof api.setMessageReaction !== "function") {
|
||||||
throw new Error("Telegram reactions are unavailable in this bot API.");
|
throw new Error("Telegram reactions are unavailable in this bot API.");
|
||||||
}
|
}
|
||||||
await requestWithDiag(() => api.setMessageReaction(chatId, messageId, reactions), "reaction");
|
try {
|
||||||
|
await requestWithDiag(() => api.setMessageReaction(chatId, messageId, reactions), "reaction");
|
||||||
|
} catch (err: unknown) {
|
||||||
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
|
if (/REACTION_INVALID/i.test(msg)) {
|
||||||
|
return { ok: false as const, warning: `Reaction unavailable: ${trimmedEmoji}` };
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user