feat(telegram): expose inline keyboard buttons via send_message tool - #42865
feat(telegram): expose inline keyboard buttons via send_message tool#42865liuhao1024 wants to merge 1 commit into
Conversation
Add optional 'buttons' parameter to the send_message tool schema, enabling agents to attach inline keyboard buttons when sending to Telegram. Each button specifies 'text' (label) and 'callback_data' (payload sent on tap). Buttons are arranged in a single row. The parameter is ignored on non-Telegram platforms, preserving backward compatibility. Invalid button entries (missing text or callback_data) are silently filtered out. Closes NousResearch#42696
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Changes Overview
- New feature: Telegram inline keyboard buttons via the
buttonsparameter in send_message tool - Buttons are converted to Telegram's InlineKeyboardMarkup format
- Comprehensive test coverage (6 new test methods)
Analysis
Correctness
- Implementation looks correct: buttons are properly mapped to InlineKeyboardButton
- Invalid buttons (missing text or callback_data) are filtered out gracefully
- Buttons only apply on Telegram platform (silently ignored on others)
- Error handling for keyboard building failures is appropriate (warning logged, message still sent)
Security
- No security concerns
- callback_data is passed through as-is (Telegram handles this)
Code Quality
- Clean implementation with good separation of concerns
- Error handling in keyboard building is defensive (try/except with warning)
- Test coverage is comprehensive: schema, with/without buttons, empty list, invalid entries, integration
Testing
- Excellent test coverage including edge cases (empty buttons, invalid entries)
Reviewed by Hermes Agent
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Telegram UX contribution. The send-side keyboard construction is clear, but it does not complete the approval workflow described in the PR.
Problems
- The new
callback_datais only attached to the outbound message. Current callback dispatch inplugins/platforms/telegram/adapter.py:5316-5639recognizes specificmp:,gt:,ea:,sc:,cl:, andupdate_prompt:forms; the exampleapprove:oncefalls through without reaching an agent session. - The new tests cover markup creation and forwarding, but not a callback tap or session delivery.
Suggested changes
- For agent workflow choices, consider using the existing
clarifypath:tools/clarify_tool.py:125-174exposes choices, andplugins/platforms/telegram/adapter.py:4696-4749plus:5578-5635renders and resolves them. - If a generic button API is needed, add an authorized callback-routing contract and an end-to-end callback test.
This is an automated hermes-sweeper review.
| if buttons and isinstance(buttons, list) and len(buttons) > 0: | ||
| try: | ||
| from telegram import InlineKeyboardButton, InlineKeyboardMarkup | ||
| keyboard = InlineKeyboardMarkup([ |
There was a problem hiding this comment.
This only creates outbound callback payloads. Current Telegram callback dispatch handles specific registered prefixes and otherwise returns (plugins/platforms/telegram/adapter.py:5316-5639), so the documented approve:once value will not deliver an approval phrase to the agent. Please add a receive-side routing contract and an end-to-end tap test, or use the existing clarify interaction path.
Problem
When the agent needs user approval for multi-step workflows (e.g.
approve commit,approve push), it can only send plain text viasend_message. Users must manually type the exact approval phrase, which is error-prone and creates friction — especially on Telegram where inline keyboard buttons already exist for terminal command approvals.Solution
Add an optional
buttonsparameter to thesend_messagetool schema. Each button specifiestext(label) andcallback_data(payload sent on tap). When targeting Telegram, buttons are converted toInlineKeyboardMarkupand attached asreply_markup. Non-Telegram platforms silently ignore the parameter.Changes
tools/send_message_tool.py— Addedbuttonsarray parameter toSEND_MESSAGE_SCHEMA. Updated_handle_send,_send_to_platform, and_send_telegramto forward and render inline keyboard buttons.tests/tools/test_send_message_tool.py— 6 new tests covering: schema validation, button rendering, no-buttons baseline, empty list, invalid entries filtering, and pass-through from_send_to_platform.Usage
Closes #42696