Skip to content

feat(bot): Telegram bot over the Basira API - #2

Merged
MoTechSys merged 2 commits into
mainfrom
feat/telegram-bot
Oct 6, 2026
Merged

MoTechSys merged 2 commits into
mainfrom
feat/telegram-bot

Conversation

@MoTechSys

@MoTechSys MoTechSys commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

What

integrations/telegram/: Telegram bot @BasiraCheckBot, a thin client over POST /v1/check and POST /v1/check/image. No model, no storage (ADR-004). Every sentence comes from messages/ar.json; source_text and ref_label_ar are inserted verbatim; bold ranges come from the API diff, widened to whole letter clusters so harakat are never split.

Also: make bot-install / make bot-test, CI job bot, optional compose service telegram-bot (profiles: [bot]), docs (INTEGRATIONS §4, README, CHANGELOG Unreleased, DECISIONS E-059, one line in AI_USAGE §1). backend/ and frontend/ untouched.

Measured

  • ruff check . && ruff format --check . && mypy --strict . && pytest -q → 73 passed, 0 errors. Handlers run through the real PTB Application, with Telegram faked at the HTTP layer. Fixtures are real API responses from basirapp.site.
  • make lint in the root: green.
  • Live run, real user account → @BasiraCheckBot → https://basirapp.site (scripts/live_e2e.py): 11/11 — start, found, needs_review (bold «علي» / «عَلَىٰ»), not_found + Dorar/Shamela links, partial_match, refusal (refusal notice only), no quotes, /sources, /limits, unsupported file, image → OCR text + needs_review/image_unconfirmed.
  • Live in a channel/group: forward from a channel ✅ (2 × found), plain text in a group ignored ✅, /check as a reply ✅, /check with nothing → usage ✅.
  • git grep -nE "[0-9]{8,}:[A-Za-z0-9_-]{30,}" → empty.

Known limit

  • Privacy mode: Telegram does not deliver plain @mention messages to the bot (measured: 0 updates), so groups use /check.

Suggestions for the frontend

  • Read ?text= on /check to enable an "Open this text in Basira" button. The bot currently links to /check without the text.

Update — Rich Messages layout (E-060)

Each reply is now one RTL Telegram Rich Message (Bot API 10.3): a heading with a status strip, your text as a cited blockquote, the source verbatim as a pull-quote with its reference as the credit (one per ayah), the differences marked with <mark> taken from the API diff, a compact metadata table, collapsible notes / other positions / full record, and buttons for the source, search and copy. If the rich call is rejected, the bot falls back to classic HTML automatically.

Thin client (python-telegram-bot 22) over POST /v1/check and /v1/check/image:
status, verbatim source_text + reference, bold differences from the API diff,
links, transparency line. No model, no storage (ADR-004), all prose from
messages/*.json. Groups: /check (reply or argument). Polling default (E-059).

Measured: ruff + mypy --strict clean, 73 tests; live 11/11 private scenarios,
channel forward and group /check against https://basirapp.site.
Each result is one RTL rich message: heading + status strip, the user's quote
as a cited blockquote, source_text as a verbatim pull-quote credited with
ref_label_ar (one per ayah), <mark> from the API diff, a compact metadata
table, collapsible notices / other positions / full record, url and copy
buttons. Classic HTML stays as the automatic fallback (BOT_RICH=0 forces it).

Measured: 105 tests (Rich-HTML validation, lexicon, limits, fallback);
live 16/16 scenarios on the rich path, 0 rich calls rejected (E-060).
Evidence rendered from the blocks Telegram stored: docs/design/evidence/telegram/.
@MoTechSys
MoTechSys merged commit ca8401a into main Oct 6, 2026
5 checks passed
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.

2 participants