From 9284eca810ed3d308360c5761479b61dd69edd66 Mon Sep 17 00:00:00 2001 From: c0mrade Date: Wed, 4 Feb 2026 09:56:46 +0300 Subject: [PATCH] debug: add console logging to Telegram popup flow Trace showPopup lifecycle (open, callback, popupClosed event, timeout) to diagnose why popup action doesn't execute and subsequent calls fail. Reduce safety timeout to 5s for faster debugging. --- src/platform/adapters/TelegramAdapter.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/platform/adapters/TelegramAdapter.ts b/src/platform/adapters/TelegramAdapter.ts index 2a901f7..f4f29dc 100644 --- a/src/platform/adapters/TelegramAdapter.ts +++ b/src/platform/adapters/TelegramAdapter.ts @@ -203,6 +203,8 @@ function createDialogController(): DialogController { popupOpen = true; let settled = false; + console.log('[popup] opening', JSON.stringify(params)); + const cleanup = () => { if (settled) return; settled = true; @@ -211,10 +213,8 @@ function createDialogController(): DialogController { tg.offEvent?.('popupClosed', onPopupClosed); }; - // Fallback: listen for popupClosed event in case the callback doesn't fire - // (known Telegram Desktop bug: popup_closed payload can be undefined, - // crashing the internal handler before it invokes the callback) const onPopupClosed = ((...args: unknown[]) => { + console.log('[popup] popupClosed event', JSON.stringify(args)); if (settled) return; const event = args[0] as { button_id?: string } | undefined; const buttonId = event?.button_id ?? ''; @@ -222,22 +222,25 @@ function createDialogController(): DialogController { resolve(mapResult(buttonId)); }) as (...args: unknown[]) => void; - // Safety timeout: reset state if neither callback nor event arrives const timer = setTimeout(() => { + console.log('[popup] timeout — force reset'); if (settled) return; cleanup(); resolve(mapResult('')); - }, 30_000); + }, 5_000); tg.onEvent?.('popupClosed', onPopupClosed); try { tg.showPopup(params, (buttonId) => { + console.log('[popup] callback fired, buttonId=', buttonId); if (settled) return; cleanup(); resolve(mapResult(buttonId)); }); - } catch { + console.log('[popup] showPopup called OK'); + } catch (e) { + console.error('[popup] showPopup threw', e); cleanup(); resolve(fallback()); }