feat: add Telegram message editing support#185
feat: add Telegram message editing support#185Marenz wants to merge 1 commit intospacedriveapp:mainfrom
Conversation
- Add OutboundResponse::EditMessage variant for editing previously sent messages - Implement editMessageText API in Telegram adapter - Add edit_message tool for agents to edit messages by ID - Add fallback handlers in other messaging adapters (Discord, Slack, Twitch, webchat, webhook) The edit_message tool allows the agent to edit a Telegram message by providing the message_id and new content. On other platforms, calls are logged but have no effect.
| result: std::result::Result<String, rig::completion::PromptError>, | ||
| skip_flag: &crate::tools::SkipFlag, | ||
| replied_flag: &crate::tools::RepliedFlag, | ||
| edited_flag: &crate::tools::EditedFlag, |
There was a problem hiding this comment.
edited_flag gets threaded through here, but handle_agent_result still only checks skip_flag/replied_flag. If the model calls edit_message without reply, you'll likely still hit the fallback text send and double-post. Consider loading edited_flag and treating it like replied_flag for fallback suppression.
| StreamEnd, | ||
| /// Edit a previously sent message by ID. | ||
| /// Telegram: edits the text of a message using editMessageText. | ||
| /// Other platforms: falls back to sending a new message (no-op). |
There was a problem hiding this comment.
The comment says other platforms "falls back to sending a new message", but adapters currently treat EditMessage as a no-op. Suggest tightening this doc to match behavior.
| /// Other platforms: falls back to sending a new message (no-op). | |
| /// Other platforms: no-op (message unchanged). |
| let html = markdown_to_telegram_html(&text); | ||
|
|
||
| if let Err(html_error) = self |
There was a problem hiding this comment.
Minor: there’s a whitespace-only line after markdown_to_telegram_html(&text); (shows up in the diff).
| let html = markdown_to_telegram_html(&text); | |
| if let Err(html_error) = self | |
| let html = markdown_to_telegram_html(&text); | |
| if let Err(html_error) = self |
Also, this branch duplicates the StreamChunk edit logic above (markdown->HTML->plain fallback). Might be worth extracting a small helper to keep behavior consistent.
| pub struct EditMessageTool { | ||
| response_tx: mpsc::Sender<OutboundResponse>, | ||
| conversation_id: String, | ||
| conversation_logger: ConversationLogger, |
There was a problem hiding this comment.
EditMessageTool stores conversation_logger/channel_id, but call() doesn’t use them yet. If they’re intended for future (logging edits / mention conversion), maybe add a quick note or wire it up; otherwise consider dropping them from the struct/ctor to keep the tool minimal.
This PR adds Telegram message editing support via editMessageText API. See: https://github.com/Marenz/spacebot/pull/new/feat/telegram-edit-message
Note
Summary
This PR introduces message editing capability to Spacebot, enabling agents to modify previously sent Telegram messages. The implementation adds a new
edit_messagetool that allows agents to specify a message ID and new content, with Telegram-specific handling via theeditMessageTextAPI and graceful no-op fallbacks for other messaging platforms.Key changes:
A new
EditMessageToolinsrc/tools/edit_message.rsthat sendsOutboundResponse::EditMessageevents. A newOutboundResponse::EditMessagevariant carryingmessage_idandtextfields. Integration of anedited_flagthrough the channel event loop to track when a message edit occurs. Platform-specific implementations: Telegram useseditMessageTextwith automatic HTML fallback to plain text; Discord, Slack, Twitch, and Webhook adapters handle edits gracefully without errors. Updates tosrc/agent/channel.rsto thread theedited_flagthrough the agent turn and result handling.Written by Tembo for commit 436fe39e. This will update automatically on new commits.