fix: unblock control commands during active runs

This commit is contained in:
Peter Steinberger
2026-01-15 07:07:37 +00:00
parent 5a58feefdc
commit 0a1eeedc10
10 changed files with 66 additions and 14 deletions

View File

@@ -251,6 +251,21 @@ describe("createTelegramBot", () => {
update: { message: { chat: { id: 555 } } },
}),
).toBe("telegram:555");
expect(
getTelegramSequentialKey({
message: { chat: { id: 123 }, text: "/stop" },
}),
).toBe("telegram:123:control");
expect(
getTelegramSequentialKey({
message: { chat: { id: 123 }, text: "/status" },
}),
).toBe("telegram:123:control");
expect(
getTelegramSequentialKey({
message: { chat: { id: 123 }, text: "stop" },
}),
).toBe("telegram:123:control");
});
it("routes callback_query payloads as messages and answers callbacks", async () => {
onSpy.mockReset();

View File

@@ -4,6 +4,7 @@ import { apiThrottler } from "@grammyjs/transformer-throttler";
import type { ApiClientOptions } from "grammy";
import { Bot, webhookCallback } from "grammy";
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
import { isControlCommandMessage } from "../auto-reply/command-detection.js";
import { resolveTextChunkLimit } from "../auto-reply/chunk.js";
import { DEFAULT_GROUP_HISTORY_LIMIT, type HistoryEntry } from "../auto-reply/reply/history.js";
import {
@@ -66,6 +67,12 @@ export function getTelegramSequentialKey(ctx: {
ctx.update?.edited_message ??
ctx.update?.callback_query?.message;
const chatId = msg?.chat?.id ?? ctx.chat?.id;
const rawText = msg?.text ?? msg?.caption;
const botUsername = (ctx as { me?: { username?: string } }).me?.username;
if (rawText && isControlCommandMessage(rawText, undefined, botUsername ? { botUsername } : undefined)) {
if (typeof chatId === "number") return `telegram:${chatId}:control`;
return "telegram:control";
}
const isForum = (msg?.chat as { is_forum?: boolean } | undefined)?.is_forum;
const threadId = resolveTelegramForumThreadId({
isForum,