fix: honor telegram default debounce account

This commit is contained in:
Tak Hoffman 2026-04-03 14:30:17 -05:00
parent a715b83e67
commit f7f467b042
No known key found for this signature in database
3 changed files with 42 additions and 1 deletions

View File

@ -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}`;
}

View File

@ -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");
});
});

View File

@ -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,