mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:51:23 +00:00
fix(telegram): prevent non-abort slash commands from racing chat replies (#17899)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 5c2f6f2c96
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -139,12 +139,27 @@ describe("createTelegramBot", () => {
|
||||
getTelegramSequentialKey({
|
||||
message: { chat: { id: 123 }, text: "/status" },
|
||||
}),
|
||||
).toBe("telegram:123:control");
|
||||
).toBe("telegram:123");
|
||||
expect(
|
||||
getTelegramSequentialKey({
|
||||
message: { chat: { id: 123 }, text: "stop" },
|
||||
}),
|
||||
).toBe("telegram:123:control");
|
||||
expect(
|
||||
getTelegramSequentialKey({
|
||||
message: { chat: { id: 123 }, text: "stop please" },
|
||||
}),
|
||||
).toBe("telegram:123");
|
||||
expect(
|
||||
getTelegramSequentialKey({
|
||||
message: { chat: { id: 123 }, text: "/abort" },
|
||||
}),
|
||||
).toBe("telegram:123");
|
||||
expect(
|
||||
getTelegramSequentialKey({
|
||||
message: { chat: { id: 123 }, text: "/abort now" },
|
||||
}),
|
||||
).toBe("telegram:123");
|
||||
});
|
||||
it("routes callback_query payloads as messages and answers callbacks", async () => {
|
||||
onSpy.mockReset();
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { OpenClawConfig, ReplyToMode } from "../config/config.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import { resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
||||
import { isControlCommandMessage } from "../auto-reply/command-detection.js";
|
||||
import { isAbortRequestText } from "../auto-reply/reply/abort.js";
|
||||
import { DEFAULT_GROUP_HISTORY_LIMIT, type HistoryEntry } from "../auto-reply/reply/history.js";
|
||||
import {
|
||||
isNativeCommandsExplicitlyDisabled,
|
||||
@@ -90,10 +90,7 @@ export function getTelegramSequentialKey(ctx: {
|
||||
const chatId = msg?.chat?.id ?? ctx.chat?.id;
|
||||
const rawText = msg?.text ?? msg?.caption;
|
||||
const botUsername = ctx.me?.username;
|
||||
if (
|
||||
rawText &&
|
||||
isControlCommandMessage(rawText, undefined, botUsername ? { botUsername } : undefined)
|
||||
) {
|
||||
if (isAbortRequestText(rawText, botUsername ? { botUsername } : undefined)) {
|
||||
if (typeof chatId === "number") {
|
||||
return `telegram:${chatId}:control`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user