feat(sources): accept t.me links and auto-extract chat id #9
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/issue-4-tme-link"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Accepts a
t.melink in the Sources form and auto-extracts the numeric Telegram chat id, so sources can be created from a pasted link without leaving the value in a shape_resolve_chatcannot handle.Closes #4
Problem
The "Telegram chat" field on the Sources form only accepted
@usernameor a numeric chat id. A pastedhttps://t.me/somechannelwas stored verbatim and a pastedhttps://t.me/+invitehashwas stored verbatim. Both shapes later failed in_resolve_chat(app/telegram/indexer.py:47), which only understood@usernameor a digit-only id.Approach
Add a single normaliser —
_normalize_telegram_chat_identifier()inapp/telegram/indexer.py— built on Telethon helpers:@somechannel/somechannel@somechannelhttps://t.me/somechannel/t.me/foo/@somechannelhttps://t.me/+HASH/t.me/+HASHtelethon.utils.resolve_invite_link)https://t.me/joinchat/HASH-100…/123…_resolve_chatraise with original text)create_source(app/main.py) runs the field through the normaliser before storing it, soSource.telegram_chatis always a canonical shape._resolve_chatruns its input through the normaliser too, so sources stored with at.melink in a prior release still resolve on the next indexing run.Tests
Added to
tests/test_telegram_indexer.py:_normalize_telegram_chat_identifiercases for every accepted shape._resolve_chattests proving at.mechannel URL resolves via@usernameand at.me/+HASHresolves via numeric id.Sabotage check: replacing the normaliser with an identity function makes 12 of the new tests fail.
Verification
uv run pytest tests/test_telegram_indexer.py→ 20 passeduv run pytest --ignore=tests/test_job_recovery.py→ 147 passed (3 excluded failures are pre-existing: they need a live Redis container and reproduce on cleanorigin/main)uv run ruff check app/telegram/indexer.py app/main.py tests/test_telegram_indexer.py→ no new issuesRisk / rollout
@somechannel.app/presentation.py:telegram_message_urlalready handles both shapes; existing_resolve_chataccepts both.