qm icon indicating copy to clipboard operation
qm copied to clipboard

Triage: Telegram surface: DM turns, delivery polling, and a generalized core client

Open time-attack opened this issue 3 months ago • 2 comments

Tracking the change proposed in #196 (by @BeAChanger).

We're moving this from a code PR to a tracked issue under CONTRIBUTING.md: feature ideas belong in adrs/ as a short human-written note and bugs as an issue, and we implement the underlying code from our side. Capturing the original proposal here so it isn't lost.

Original PR: #196 Reported by: @BeAChanger


Summary

Adds Telegram as a first-class surface alongside Slack and the web:

  • src/telegram/ — a new in-process plugin mirroring the Slack one. Long-polls getUpdates (no public URL or TLS needed), bridges each DM message to a turn with surface: "telegram", posts the reply back to the same chat (threaded when replying to the bot), splits replies > 4096 chars, and claims type: "telegram" deliveries for cron / monitor / agent-initiated posts (including file documents). Group chats are refused out loud rather than mis-scoped; DM-only for now.
  • Core generalization — src/api/slack-core-client.ts → src/api/core-client.ts: createCoreClient(deps, surface) parameterizes the surface name (default "slack"), and the turn bridge moved to src/api/core-bridge.ts so both surfaces share one implementation. wiring.ts now exposes telegramCore alongside slackCore; src/index.ts boots the plugin when TELEGRAM_BOT_TOKEN is set.

Why

QM's core speaks surfaces generically — TurnRequest.surface flows into session scoping, delivery destination.type, and the surface tool name (the pi-tools test already asserts a telegram surface produces a telegram tool). Only the Slack plugin's client was hard-coded to "slack", which blocked a second surface. This change removes that coupling and demonstrates the pattern with a working Telegram surface.

Setup

BotFather → /newbot → put the token in TELEGRAM_BOT_TOKEN. Optional TELEGRAM_ALLOWED_CHAT_IDS to restrict which chats the bot answers. See src/telegram/README.md.

Test plan

  • test/telegram-plugin.test.ts (new): mocks the Bot API via an injected fetchImpl and covers message→turn→reply, long-reply splitting, reply-thread continuation, chat allowlisting, delivery claim/ack, and the surface parameterization.
  • test/slack-index.integration.test.ts and the other slack/delivery suites: all still green (216 + 116 tests run locally).
  • tsc --noEmit, eslint, prettier --check, and the root-test-shard plan check all pass.

Screenshot: no UI surface — this is a headless plugin; behavior is covered by the tests above.


View with [code]smith Autofix with [code]smith Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


If we ship a fix or feature from this, credit @BeAChanger as co-author.

time-attack avatar Aug 28 '26 21:08 time-attack

@time-attack is this feature being prioritised?

BhargavSatya avatar Sep 12 '26 12:09 BhargavSatya

Same. For small teams, Slack is overkill.

Telegram has groups and topics now, and OpenClaw is great at this:

Screenshot_20261128-231551

gianpaj avatar Nov 28 '26 22:11 gianpaj