feat: forward unknown /commands to Claude as natural language#120
feat: forward unknown /commands to Claude as natural language#120inhyoe wants to merge 1 commit intoRichardAtCT:mainfrom
Conversation
Adds a catch-all handler for unrecognized slash commands (e.g. /commit, /review, /tofu_at) that converts them to natural language prompts and forwards them to Claude via the existing agentic_text handler. This enables project-specific Claude Code slash commands defined in .claude/commands/ to work seamlessly through the Telegram bot without requiring explicit handler registration for each one. Implementation notes: - Registers a COMMAND filter handler at group=10 (after built-in commands) - Converts underscores to hyphens (/tofu_at → /tofu-at) since Telegram bot commands don't support hyphens - Uses an override_text parameter on agentic_text() instead of mutating update.message.text, which is frozen in python-telegram-bot v20+ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
PR #120 — feat: forward unknown /commands to Claude as natural language Clean, well-reasoned feature. The One issue to consider: The parts = message_text.split(maxsplit=1)
cmd = parts[0].replace("_", "-") # /tofu_at → /tofu-at
args = parts[1] if len(parts) > 1 else ""
prompt = f"Run {cmd} {args}".strip()Minor:
Overall: ship-ready once the argument mangling is addressed. — Friday, AI assistant to @RichardAtCT |
RichardAtCT
left a comment
There was a problem hiding this comment.
Thanks for this! There's a bug in the command-to-natural-language forwarding:
The replace("_", "-") transformation is applied to the entire message including arguments, not just the command name. For example, /my_command some_argument would become my-command some-argument, mangling the user's input.
Please fix so the replacement only applies to the command portion (before the first space). Happy to re-review once fixed!
Summary
/commit,/review,/tofu_at) that forwards them to Claude viaagentic_text/tofu_at→Run /tofu-at) since Telegram bot commands don't support hyphensoverride_textparameter onagentic_text()instead of mutatingupdate.message.text, which is frozen (immutable) inpython-telegram-botv20+Problem
Claude Code supports project-specific slash commands via
.claude/commands/*.md. When users send these commands through the Telegram bot (e.g./tofu_at,/commit), they hit the "unknown command" path and are silently dropped.A naive fix of setting
update.message.text = promptcausesAttributeError: Attribute 'text' of class 'Message' can't be set!becauseMessageobjects are frozen dataclasses inpython-telegram-botv22.x.Solution
filters.COMMANDhandler at group 10 (after built-in command handlers) to catch unrecognized commands_agentic_unknown_command()transforms the command text and passes it viaoverride_textparameteragentic_text()accepts optionaloverride_text: str | None = None, using it overupdate.message.textwhen providedTest plan
/tofu_atvia Telegram → bot forwardsRun /tofu-atto Claude (noAttributeError)agentic_textworks as before (override_text=None)/start,/new,/status) still handled by their dedicated handlerspython-telegram-botv22.6🤖 Generated with Claude Code