From f7f467b04205744b04d97ebb089be20138ec5431 Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Fri, 3 Apr 2026 14:30:17 -0500 Subject: [PATCH] fix: honor telegram default debounce account --- .../telegram/src/bot-handlers.debounce-key.ts | 9 +++++++ .../telegram/src/bot-handlers.runtime.test.ts | 26 +++++++++++++++++++ .../telegram/src/bot-handlers.runtime.ts | 8 +++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 extensions/telegram/src/bot-handlers.debounce-key.ts create mode 100644 extensions/telegram/src/bot-handlers.runtime.test.ts diff --git a/extensions/telegram/src/bot-handlers.debounce-key.ts b/extensions/telegram/src/bot-handlers.debounce-key.ts new file mode 100644 index 00000000000..530230cc1f8 --- /dev/null +++ b/extensions/telegram/src/bot-handlers.debounce-key.ts @@ -0,0 +1,9 @@ +export function buildTelegramInboundDebounceKey(params: { + accountId?: string | null; + conversationKey: string; + senderId: string; + debounceLane: "default" | "forward"; +}): string { + const resolvedAccountId = params.accountId?.trim() || "default"; + return `telegram:${resolvedAccountId}:${params.conversationKey}:${params.senderId}:${params.debounceLane}`; +} diff --git a/extensions/telegram/src/bot-handlers.runtime.test.ts b/extensions/telegram/src/bot-handlers.runtime.test.ts new file mode 100644 index 00000000000..08d2c6ef6c8 --- /dev/null +++ b/extensions/telegram/src/bot-handlers.runtime.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from "vitest"; +import { buildTelegramInboundDebounceKey } from "./bot-handlers.debounce-key.js"; + +describe("buildTelegramInboundDebounceKey", () => { + it("uses the resolved account id instead of literal default when provided", () => { + expect( + buildTelegramInboundDebounceKey({ + accountId: "work", + conversationKey: "12345", + senderId: "67890", + debounceLane: "default", + }), + ).toBe("telegram:work:12345:67890:default"); + }); + + it("falls back to literal default only when account id is actually absent", () => { + expect( + buildTelegramInboundDebounceKey({ + accountId: undefined, + conversationKey: "12345", + senderId: "67890", + debounceLane: "forward", + }), + ).toBe("telegram:default:12345:67890:forward"); + }); +}); diff --git a/extensions/telegram/src/bot-handlers.runtime.ts b/extensions/telegram/src/bot-handlers.runtime.ts index 17bdc5390ca..b3344714a31 100644 --- a/extensions/telegram/src/bot-handlers.runtime.ts +++ b/extensions/telegram/src/bot-handlers.runtime.ts @@ -101,6 +101,7 @@ import { resolveModelSelection, type ProviderInfo, } from "./model-buttons.js"; +import { buildTelegramInboundDebounceKey } from "./bot-handlers.debounce-key.js"; import { buildInlineKeyboard } from "./send.js"; export const registerTelegramHandlers = ({ @@ -1085,7 +1086,12 @@ export const registerTelegramHandlers = ({ conversationThreadId != null ? `${chatId}:topic:${conversationThreadId}` : String(chatId); const debounceLane = resolveTelegramDebounceLane(msg); const debounceKey = senderId - ? `telegram:${accountId ?? "default"}:${conversationKey}:${senderId}:${debounceLane}` + ? buildTelegramInboundDebounceKey({ + accountId, + conversationKey, + senderId, + debounceLane, + }) : null; await inboundDebouncer.enqueue({ ctx,