fix(telegram): surface fallback on dispatch failures (#39209, thanks @riftzen-bit)

Co-authored-by: riftzen-bit <binb53339@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-07 22:40:53 +00:00
parent f53e10e3fd
commit 99de6515a0
6 changed files with 88 additions and 20 deletions

View File

@@ -72,4 +72,29 @@ describe("telegram bot message processor", () => {
await processSampleMessage(processMessage);
expect(dispatchTelegramMessage).not.toHaveBeenCalled();
});
it("sends user-visible fallback when dispatch throws", async () => {
const sendMessage = vi.fn().mockResolvedValue(undefined);
const runtimeError = vi.fn();
buildTelegramMessageContext.mockResolvedValue({
chatId: 123,
threadSpec: { id: 456 },
route: { sessionKey: "agent:main:main" },
});
dispatchTelegramMessage.mockRejectedValue(new Error("dispatch exploded"));
const processMessage = createTelegramMessageProcessor({
...baseDeps,
bot: { api: { sendMessage } },
runtime: { error: runtimeError },
} as unknown as Parameters<typeof createTelegramMessageProcessor>[0]);
await expect(processSampleMessage(processMessage)).resolves.toBeUndefined();
expect(sendMessage).toHaveBeenCalledWith(
123,
"Something went wrong while processing your request. Please try again.",
{ message_thread_id: 456 },
);
expect(runtimeError).toHaveBeenCalledWith(expect.stringContaining("dispatch exploded"));
});
});