Skip to content

gateway: handle /start as welcome + command list + home-channel status#11640

Open
sosasays wants to merge 1 commit into
NousResearch:mainfrom
sosasays:start-handler
Open

gateway: handle /start as welcome + command list + home-channel status#11640
sosasays wants to merge 1 commit into
NousResearch:mainfrom
sosasays:start-handler

Conversation

@sosasays

Copy link
Copy Markdown

What

Register /start as a slash command and add a handler. Without this, /start falls through to the generic "unknown command" notice, which breaks standard Telegram bot first-contact UX (every bot must respond to /start).

Why

Every Telegram bot receives /start as the mandatory first message from a new user. hermes-agent already recognizes /sethome, /status, /help, etc. but not /start — so first-contact responses feel broken and users are unclear whether the bot is alive. Discovered during a production Hermes-Quant deploy.

Changes

  • hermes_cli/commands.py: add one CommandDef("start", …, "Session", gateway_only=True) entry to COMMAND_REGISTRY so /start is recognized everywhere the registry feeds (GATEWAY_KNOWN_COMMANDS, help text, Telegram BotCommands menu, Slack subcommand mapping, etc.).
  • gateway/run.py:
    • Dispatch: if canonical == "start": return await self._handle_start_command(event) next to the /sethome dispatch.
    • New async method _handle_start_command(self, event: MessageEvent) -> str that:
      1. Returns a markdown welcome listing /sethome, /status, /help.
      2. Reads the current home channel from ~/.hermes/config.yaml (same key /sethome writes to: {PLATFORM}_HOME_CHANNEL); falls back to the process environment.
      3. If no home is set → prompts the user to run /sethome.
      4. If a home is set but the user is in a different chat → acknowledges the bot is active and points to the existing home.
      5. If the user is in the home channel → confirms that.

Idempotent; safe to invoke any time.

Tests

Direct-call smoke covered all three code paths of the handler.

Live Telegram round-trip on a production gateway verified all five scenarios:

  • /start from the home channel → correct "this chat is home" response.
  • /start from a different chat → correct "home is already set elsewhere" response.
  • /start with no home set → correct "run /sethome to receive digests" prompt.
  • /help still works (unchanged upstream handler).
  • /status still works (unchanged upstream handler).
  • /sethome in a different chat correctly reassigns + reverts cleanly.

Import smoke:

  • from hermes_cli.commands import COMMAND_REGISTRY, GATEWAY_KNOWN_COMMANDS; 'start' in GATEWAY_KNOWN_COMMANDSTrue
  • import gateway.run compiles clean (Python 3.11)

Downstream status

Our production deploy will run on canonical upstream and accept the "unknown command" reply for /start until this merges. Documented as a known issue pointing at this PR.

Made with Cursor

Every Telegram bot must respond to /start as the mandatory first-
contact message. Previously hermes-agent returned the generic
"unknown command" notice because /start was absent from
COMMAND_REGISTRY and the gateway dispatch table.

Changes:
- hermes_cli/commands.py: register start as a gateway-only slash
  command.
- gateway/run.py: dispatch /start to a new _handle_start_command
  handler.

Handler behavior:
1. Returns a structured markdown welcome listing /sethome, /status,
   /help with short descriptions.
2. Reads the current home channel from ~/.hermes/config.yaml (same
   file /sethome writes to); falls back to environment.
3. If no home channel is set: appends a prompt to run /sethome.
4. If a home channel IS set and the user is in a different chat:
   acknowledges the bot is active and reports the existing home.
5. If the user is in the home channel: confirms that.

Idempotent and safe to invoke any time.

Bug discovered during a production Hermes-Quant deploy. The handler
was verified in staging (direct-call smoke test covered all three
code paths; live Telegram round-trip confirmed correct responses in
all five scenarios).
@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery labels Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants