Skip to content

fix(telegram): preserve this on adapter.telegramFetch (v0.5.35 regression)#139

Merged
royosherove merged 1 commit into
mainfrom
fix/postRich-this-binding
May 16, 2026
Merged

fix(telegram): preserve this on adapter.telegramFetch (v0.5.35 regression)#139
royosherove merged 1 commit into
mainfrom
fix/postRich-this-binding

Conversation

@royosherove
Copy link
Copy Markdown
Member

🐛 Hotfix for v0.5.35. Inline keyboards for /model and /topic regressed to text fallback after the Rich UI Surface migration.

Root cause:

// PR #137 introduced this:
const telegramFetch = telegramThread.adapter?.telegramFetch;
await telegramFetch('sendMessage', {...});  // `this` is undefined!

The real @chat-adapter/telegram telegramFetch is a class method that uses this.apiBaseUrl and this.botToken. Detached calls throw Cannot read properties of undefined (reading apiBaseUrl) — but postRich's catch swallows it and falls back to text. Live verified on prod:

BOUND ok: pi5_faststart_loki_bot
DETACHED threw: Cannot read properties of undefined (reading 'apiBaseUrl')

Fix: Invoke as tgAdapter.telegramFetch(...) so this is preserved.

Why tests didn't catch it: Existing tests mock telegramFetch as vi.fn() which has no this-dependence. Added a regression test using FakeTelegramAdapter that touches this.apiBaseUrl and throws when detached. Mutation-tested: revert fix → test fails exactly on the 'menu was sent' assertion.

Test: 562 green (+1).

Will tag v0.5.36 + publish on merge.

v0.5.35 regression: postRich extracted telegramFetch as a plain reference
(`const fn = adapter.telegramFetch; fn(...)`) which loses `this`. The real
@chat-adapter/telegram telegramFetch is a class method that depends on
`this.apiBaseUrl` and `this.botToken` — detached calls throw 'Cannot read
properties of undefined (reading apiBaseUrl)'. The catch swallowed the
error and silently fell back to plain text, breaking inline keyboards
for /model and /topic.

Fix: invoke as `tgAdapter.telegramFetch(...)` so `this` is preserved.

Live verified on prod: bound call works, detached throws.

Mutation-tested regression in test/telegram-postrich.test.ts using a
FakeTelegramAdapter that touches `this.apiBaseUrl` (vi.fn() can't catch
this — no this-dependence). Reverting the fix → test fails exactly on
the 'menu was sent' assertion.
@royosherove royosherove merged commit 6a4f0b8 into main May 16, 2026
1 check passed
@royosherove royosherove deleted the fix/postRich-this-binding branch May 16, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant