fix(tg): route /compact and /evaluator-prompt to the command router

The Telegram channel forwards slash commands through an allowlist regex
that must mirror the builtin command router. /compact and
/evaluator-prompt were missing from it, and messages starting with '/'
never reach the generic text handler, so both commands were silently
dropped: pressing /compact did nothing at all.

Add both commands to the allowlist, register /compact in the Telegram
command menu, and pin the router/regex pairing in the existing regex
test.
This commit is contained in:
Naster17 authored and chengyongru committed 2026-09-10 11:44:17 +08:00
1 parent dfed706bc0
commit 6a8647cfb6
2 files changed
+9 -1

No files matched your search

+4 -1
View File
@@ -477,6 +477,7 @@ class TelegramChannel(BaseChannel):
BOT_COMMANDS: list[BotCommand] = [ BOT_COMMANDS: list[BotCommand] = [
BotCommand("start", "Start the bot"), BotCommand("start", "Start the bot"),
BotCommand("new", "Start a new conversation"), BotCommand("new", "Start a new conversation"),
BotCommand("compact", "Compact this chat's context"),
BotCommand("stop", "Stop the current task"), BotCommand("stop", "Stop the current task"),
BotCommand("restart", "Restart the bot"), BotCommand("restart", "Restart the bot"),
BotCommand("status", "Show bot status"), BotCommand("status", "Show bot status"),
@@ -495,8 +496,10 @@ class TelegramChannel(BaseChannel):
# Regex for slash commands routed to AgentLoop via ``_forward_command``. # Regex for slash commands routed to AgentLoop via ``_forward_command``.
# Hyphenated ``dream-*`` commands stay on a separate handler (below). # Hyphenated ``dream-*`` commands stay on a separate handler (below).
# Must cover every builtin router command; ``test_telegram_bus_slash_command_regex_matches_agent_loop_commands``
# pins the pairing.
TELEGRAM_BUS_SLASH_COMMAND_RE = re.compile( TELEGRAM_BUS_SLASH_COMMAND_RE = re.compile(
r"^/(?:new|stop|restart|status|dream|history|goal|trigger|pairing|model|skill)(?:@\w+)?(?:\s+.*)?$" r"^/(?:new|compact|stop|restart|status|dream|history|goal|trigger|pairing|model|skill|evaluator-prompt)(?:@\w+)?(?:\s+.*)?$"
) )
@classmethod @classmethod
@@ -2491,6 +2491,11 @@ def test_telegram_bus_slash_command_regex_matches_agent_loop_commands() -> None:
assert pat.fullmatch("/new@nanobot_bot") assert pat.fullmatch("/new@nanobot_bot")
assert pat.fullmatch("/goal@nanobot_bot refine objective") assert pat.fullmatch("/goal@nanobot_bot refine objective")
assert pat.fullmatch("/trigger@nanobot_bot CI summary") assert pat.fullmatch("/trigger@nanobot_bot CI summary")
assert pat.fullmatch("/compact")
assert pat.fullmatch("/compact@nanobot_bot")
assert pat.fullmatch("/evaluator-prompt")
assert pat.fullmatch("/evaluator-prompt init")
assert not pat.fullmatch("/unknown-command")
assert pat.fullmatch("/dream-log deadbeef") is None assert pat.fullmatch("/dream-log deadbeef") is None
assert pat.fullmatch("/dream-restore deadbeef") is None assert pat.fullmatch("/dream-restore deadbeef") is None
assert pat.fullmatch("/dream-prompt init") is None assert pat.fullmatch("/dream-prompt init") is None