fix(telegram): answer callback queries immediately to prevent retries
Telegram retries callback queries if they aren't acknowledged quickly. Previously, answerCallbackQuery was called in a finally block AFTER processing, which could take several seconds for agent responses. This change moves answerCallbackQuery to immediately after basic validation, before any processing begins. This prevents Telegram from sending duplicate callbacks while the agent is thinking. Fixes duplicate callback handling when agent processing is slow.
This commit is contained in:
@@ -179,6 +179,8 @@ export const registerTelegramHandlers = ({
|
||||
const callback = ctx.callbackQuery;
|
||||
if (!callback) return;
|
||||
if (shouldSkipUpdate(ctx)) return;
|
||||
// Answer immediately to prevent Telegram from retrying while we process
|
||||
await bot.api.answerCallbackQuery(callback.id).catch(() => {});
|
||||
try {
|
||||
const data = (callback.data ?? "").trim();
|
||||
const callbackMessage = callback.message;
|
||||
@@ -323,8 +325,6 @@ export const registerTelegramHandlers = ({
|
||||
});
|
||||
} catch (err) {
|
||||
runtime.error?.(danger(`callback handler failed: ${String(err)}`));
|
||||
} finally {
|
||||
await bot.api.answerCallbackQuery(callback.id).catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user