Register bot commands (setMyCommands) + /help handler #3

Closed
opened 2026-07-04 21:45:15 +08:00 by weiwen · 2 comments
Owner

Make commands discoverable in Telegram's menu and add a /help handler. Highest-value interaction affordance; no new update type.

Current state

  • /clear is the only command, handled by a raw text == "/clear" string match in handle_message (src/telegram/mod.rs:54).
  • No command registration; no /help; /start and any other slash-command fall through and are sent to pi as a literal prompt.

Scope

  1. Call setMyCommands once at startup in run() (global scope — single-user + allowlist, so scope is irrelevant). Register /help and /clear only.
  2. Add a /help handler: static reply describing what evie is + the command list.
  3. Handle /start by aliasing to /help, but do not register it in the command menu (avoids Telegram's auto Start button being forwarded to pi as a literal prompt).
  4. Refactor the inline /clear check into a small command dispatch so adding handlers isn't ad-hoc string comparisons.
  5. Swallow unknown commands. Any message starting with / that isn't a known command gets a one-line "unknown command — try /help" reply and is not forwarded to pi (stops pi receiving noise like /claer). Non-slash text is unaffected.

Acceptance

  • The menu shows /help and /clear (not /start).
  • /help and /start both return the help text; neither reaches pi.
  • /clear still resets the session.
  • An unknown command (e.g. /foo) gets the hint reply and never reaches pi.
  • Ordinary (non-slash) messages still go to pi.
Make commands discoverable in Telegram's menu and add a `/help` handler. Highest-value interaction affordance; no new update type. ## Current state - `/clear` is the only command, handled by a raw `text == "/clear"` string match in `handle_message` (`src/telegram/mod.rs:54`). - No command registration; no `/help`; `/start` and any other slash-command fall through and are sent to pi as a literal prompt. ## Scope 1. Call `setMyCommands` **once at startup** in `run()` (global scope — single-user + allowlist, so scope is irrelevant). Register **`/help`** and **`/clear`** only. 2. Add a **`/help`** handler: static reply describing what evie is + the command list. 3. Handle **`/start`** by aliasing to `/help`, but do **not** register it in the command menu (avoids Telegram's auto Start button being forwarded to pi as a literal prompt). 4. Refactor the inline `/clear` check into a small command dispatch so adding handlers isn't ad-hoc string comparisons. 5. **Swallow unknown commands.** Any message starting with `/` that isn't a known command gets a one-line "unknown command — try /help" reply and is **not** forwarded to pi (stops pi receiving noise like `/claer`). Non-slash text is unaffected. ## Acceptance - The menu shows `/help` and `/clear` (not `/start`). - `/help` and `/start` both return the help text; neither reaches pi. - `/clear` still resets the session. - An unknown command (e.g. `/foo`) gets the hint reply and never reaches pi. - Ordinary (non-slash) messages still go to pi.
Author
Owner

Implemented bot command registration and /help handler:

  1. setMyCommands — and registered at startup (global scope)
  2. Command dispatch — refactored inline check into a -based dispatch
  3. /help — static reply with bot description + command list
  4. /start — aliased to (not registered in command menu, so Telegram's auto-start button shows help instead of hitting pi)
  5. Unknown commands — swallowed with a hint reply, never reach pi
  6. Non-slash messages — unaffected, still forwarded to pi as normal

All 24 tests pass (). File changed:

Implemented bot command registration and /help handler: 1. **setMyCommands** — and registered at startup (global scope) 2. **Command dispatch** — refactored inline check into a -based dispatch 3. **/help** — static reply with bot description + command list 4. **/start** — aliased to (not registered in command menu, so Telegram's auto-start button shows help instead of hitting pi) 5. **Unknown commands** — swallowed with a hint reply, never reach pi 6. **Non-slash messages** — unaffected, still forwarded to pi as normal All 24 tests pass (). File changed:
Author
Owner

Implemented bot command registration and /help handler:

  1. setMyCommands - /help and /clear registered at startup (global scope)
  2. Command dispatch - refactored inline /clear check into a match-based dispatch
  3. /help - static reply with bot description + command list
  4. /start - aliased to /help (not registered in command menu, so Telegram auto-start shows help instead of hitting pi)
  5. Unknown commands - swallowed with hint reply, never reach pi
  6. Non-slash messages - unaffected, still forwarded to pi as normal

All 24 tests pass (cargo test). File changed: src/telegram/mod.rs

Implemented bot command registration and /help handler: 1. **setMyCommands** - /help and /clear registered at startup (global scope) 2. **Command dispatch** - refactored inline /clear check into a match-based dispatch 3. **/help** - static reply with bot description + command list 4. **/start** - aliased to /help (not registered in command menu, so Telegram auto-start shows help instead of hitting pi) 5. **Unknown commands** - swallowed with hint reply, never reach pi 6. **Non-slash messages** - unaffected, still forwarded to pi as normal All 24 tests pass (cargo test). File changed: src/telegram/mod.rs
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
weiwen/evie#3
No description provided.