Skip to content

fix(telegram): keep typing indicator alive while Claude is processing#979

Open
snemesh wants to merge 1 commit intoanthropics:mainfrom
snemesh:feat/telegram-continuous-typing-indicator
Open

fix(telegram): keep typing indicator alive while Claude is processing#979
snemesh wants to merge 1 commit intoanthropics:mainfrom
snemesh:feat/telegram-continuous-typing-indicator

Conversation

@snemesh
Copy link
Copy Markdown

@snemesh snemesh commented Mar 25, 2026

Problem

Telegram's typing indicator expires after ~5 seconds. For queries that take 30s–2min (tool use, file reads, complex reasoning), the indicator disappears and the user can't tell if the bot is still working or has silently failed. This is especially problematic because --channels is experimental and sessions can genuinely stop responding (#777, #963).

Fix

Added startTyping(chat_id) / stopTyping(chat_id) helpers:

  • startTyping sends sendChatAction("typing") immediately, then repeats every 4 seconds via setInterval
  • stopTyping clears the interval — called when reply or edit_message sends a response
  • Multiple chats tracked independently via Map<string, interval>
  • startTyping on the same chat replaces the previous interval (no leak)
  • stopTyping on unknown chat is a safe no-op

Changes

  • external_plugins/telegram/server.ts — 27 insertions, 2 deletions

Test plan

  • bun build passes
  • 12/12 unit tests pass
Test output (12/12 passed)
── Test 1: immediate typing on startTyping ──
  ✅ Typing sent immediately
  ✅ Correct chat_id
  ✅ Interval registered

── Test 2: typing repeats every interval ──
  ✅ Typing sent multiple times (got 3, expect 3-4)

── Test 3: stopTyping stops the indicator ──
  ✅ No more typing after stop (before=2, after=2)
  ✅ Interval removed from map

── Test 4: multiple chats are independent ──
  ✅ Two intervals active
  ✅ Only chat_B remains
  ✅ All cleared

── Test 5: startTyping on same chat replaces interval ──
  ✅ Interval replaced (not duplicated)
  ✅ Different interval object

── Test 6: stopTyping on unknown chat is no-op ──
  ✅ No error thrown

═══ Result: 12/12 passed ✅ ═══

Fixes #932

Telegram's typing indicator expires after ~5 seconds. For queries
that take 30s-2min (tool use, file reads, complex reasoning), the
indicator disappears and the user can't tell if the bot is still
working or silently failed.

Added startTyping/stopTyping helpers that re-send sendChatAction
every 4 seconds. startTyping is called when an inbound message is
received; stopTyping is called when reply or edit_message sends a
response. Multiple chats are tracked independently via a Map.

Fixes anthropics#932
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.

Telegram channel: keep sending typing indicator while processing

1 participant