Skip to content

fix(telegram): avoid KeyError on stop while typing and decode UTF-16 entity offsets - #408

Open
KuljeetSinghXDA wants to merge 1 commit into
bubbuild:mainfrom
KuljeetSinghXDA:fix/telegram-typing-and-utf16-mentions
Open

KuljeetSinghXDA wants to merge 1 commit into
bubbuild:mainfrom
KuljeetSinghXDA:fix/telegram-typing-and-utf16-mentions

Conversation

@KuljeetSinghXDA

Copy link
Copy Markdown

Summary

  • Fix KeyError when stopping Telegram channel during an active typing indicator (src/bub/channels/telegram.py):
    • TelegramChannel.stop() clears self._typing_tasks, so an active start_typing(chat_id) context exiting afterward via del self._typing_tasks[chat_id] raised KeyError. Switched to self._typing_tasks.pop(chat_id, None).
  • Decode Telegram entity offsets as UTF-16 code units (src/bub/channels/telegram.py):
    • Telegram Bot API entity.offset and entity.length are UTF-16 code-unit offsets. Added _slice_utf16 and used it in TelegramMessageParser._extract_links and BubMessageFilter._mentions_bot so URLs and mentions following emoji or other non-BMP characters are sliced accurately instead of shifted/truncated.

Verification

  • uv run ruff check src/bub/channels/telegram.py tests/test_channels.py: passed
  • uv run mypy src: Success: no issues found in 77 source files
  • uv run pytest tests/test_channels.py -q: 90 passed

This branch has not been deployed

No deployments
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