Skip to content

Commit 4795404

Browse files
committed
fix(telegram): retry forum replies without invalid thread id
1 parent bf0cbfe commit 4795404

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

extensions/telegram/src/bot/delivery.send.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export async function sendTelegramWithThreadFallback<T>(params: {
6868
send: (effectiveParams: Record<string, unknown>) => Promise<T>;
6969
shouldLog?: (err: unknown) => boolean;
7070
}): Promise<T> {
71-
const allowThreadlessRetry = params.thread?.scope === "dm";
71+
const allowThreadlessRetry =
72+
params.thread?.scope === "dm" || params.thread?.scope === "forum";
7273
const hasThreadId = hasMessageThreadIdParam(params.requestParams);
7374
const hasNativeQuote = getTelegramNativeQuoteReplyMessageId(params.requestParams) != null;
7475
const shouldSuppressFirstErrorLog = (err: unknown) =>

extensions/telegram/src/bot/delivery.test.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -758,22 +758,32 @@ describe("deliverReplies", () => {
758758
expect(runtime.error).not.toHaveBeenCalled();
759759
});
760760

761-
it("does not retry forum sends without message_thread_id", async () => {
761+
it("retries forum sends without message_thread_id when thread is missing", async () => {
762762
const runtime = createRuntime();
763-
const sendMessage = vi.fn().mockRejectedValue(createThreadNotFoundError("sendMessage"));
763+
const sendMessage = vi
764+
.fn()
765+
.mockRejectedValueOnce(createThreadNotFoundError("sendMessage"))
766+
.mockResolvedValueOnce({
767+
message_id: 7,
768+
chat: { id: "123" },
769+
});
764770
const bot = createBot({ sendMessage });
765771

766-
await expect(
767-
deliverWith({
768-
replies: [{ text: "hello" }],
769-
runtime,
770-
bot,
771-
thread: { id: 42, scope: "forum" },
772-
}),
773-
).rejects.toThrow("message thread not found");
772+
await deliverWith({
773+
replies: [{ text: "hello" }],
774+
runtime,
775+
bot,
776+
thread: { id: 42, scope: "forum" },
777+
});
774778

775-
expect(sendMessage).toHaveBeenCalledTimes(1);
776-
expect(runtime.error).toHaveBeenCalledTimes(1);
779+
expect(sendMessage).toHaveBeenCalledTimes(2);
780+
expect(sendMessage.mock.calls[0]?.[2]).toEqual(
781+
expect.objectContaining({
782+
message_thread_id: 42,
783+
}),
784+
);
785+
expect(sendMessage.mock.calls[1]?.[2]).not.toHaveProperty("message_thread_id");
786+
expect(runtime.error).not.toHaveBeenCalled();
777787
});
778788

779789
it("retries final text sends for wrapped pre-connect grammY HttpError envelopes", async () => {

0 commit comments

Comments
 (0)