Skip to content

feat(notify): answer permission prompts from Telegram - #525

Merged
mrnasil merged 5 commits into
mainfrom
feat/telegram-approvals
Dec 2, 2026
Merged

mrnasil merged 5 commits into
mainfrom
feat/telegram-approvals

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 30, 2026

Copy link
Copy Markdown
Member

What

Notifications were one way: a ping said the agent was blocked on a permission prompt, and the answer still had to be typed at the terminal.

With notify.telegram_control = true, a permission prompt in the TUI is also sent to the Telegram chat with Allow / Deny buttons. The first answer wins (terminal or Telegram), and the message is rewritten with the outcome.

[notify]
telegram_bot_token = "${TELEGRAM_BOT_TOKEN}"
telegram_chat_id = "${TELEGRAM_CHAT_ID}"
telegram_control = true        # or WHYCODES_NOTIFY_TELEGRAM_CONTROL=1

Safety

  • Off by default.
  • Only a button pressed in the configured chat counts, and only for the nonce of the prompt it was sent with. The nonce is checked for shape before it is used as a file name.
  • The key is read from the global config and the environment. A project config cannot set it (dropped at load with the existing warning), and a project config that changes the bot token or chat id turns control off, so a cloned repository cannot route approvals to its own bot.
  • The buttons answer the prompt the y / n keys answer. deny rules, catastrophic commands and the sandbox are unchanged.

How

  • crates/plugin/src/remote.rs: send the prompt, short-poll getUpdates (every 2 s, only while a prompt waits), record each answer in <data dir>/telegram-control/<nonce>. Sessions and processes sharing one bot read their answer from that file, whoever polled it.
  • ChannelPermissionPrompter::with_remote: races the UI's answer against a RemoteApprover.
  • TUI: a request whose waiter is gone was answered remotely; it leaves the queue and its dialog closes.

Not covered: question prompts, --plain, headless runs, sessions attached to a daemon.

Verification

  • New tests run the whole flow against a loopback Bot API mock: allow, deny, a foreign chat, a failed poll, a failed acknowledgement, the terminal answering first, a prompt that cannot be sent.
  • cargo test for config, plugin, agent (--lib) and the TUI run loop: green on Windows and on Linux (WSL).
  • Linux line coverage: 0 missed lines in every file this PR touches.
  • clippy, fmt and the budget scripts: clean.

Not verified yet

No run against the real Telegram Bot API. Before merging, with a real bot: turn the key on, trigger a permission prompt, press Allow on the phone, and check the tool runs and the dialog closes; then answer one at the terminal and check the message says so.

🤖 Generated with Claude Code

mrnasil and others added 4 commits November 30, 2026 16:49
Notifications were one way: a ping said the agent was blocked on a
permission prompt, and the answer still had to be typed at the terminal.

With `notify.telegram_control = true` the TUI's permission prompt is also
sent to the Telegram chat with Allow / Deny buttons. The first answer
wins; the message is then rewritten with the outcome.

- Only a button pressed in the configured chat counts, and only for the
  nonce of the prompt it was sent with.
- The key is read from the global config and the environment. A project
  config cannot set it, and one that changes the bot token or chat id
  turns control off, so a cloned repository cannot route approvals to its
  own bot.
- Answers go through `<data dir>/telegram-control/<nonce>`, so sessions
  and processes sharing one bot do not lose each other's button presses.
  Polling is a short `getUpdates` every 2 s, only while a prompt waits.
- The TUI drops a request that was answered remotely and closes its
  dialog.

Deny rules, catastrophic commands and the sandbox are unchanged: the
buttons answer the prompt the y/n keys answer.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ble block

The tool name in the title is inline code and the detail (the command) is a
pre block, which the chat copies with one tap. Entities, not a parse mode, so
nothing in a command needs escaping.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A failed send put the full URL in the error, and the error in the logs. The
URL carries the Telegram bot token or the Discord webhook secret.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@mrnasil
mrnasil marked this pull request as ready for review December 2, 2026 14:28
@mrnasil
mrnasil enabled auto-merge (squash) December 2, 2026 14:28
@mrnasil
mrnasil merged commit a91e698 into main Dec 2, 2026
7 checks passed
@mrnasil
mrnasil deleted the feat/telegram-approvals branch December 2, 2026 14:36
@mrnasil mrnasil mentioned this pull request Dec 3, 2026
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