Skip to content

Comments

feat: add Telegram message editing support#185

Open
Marenz wants to merge 1 commit intospacedriveapp:mainfrom
Marenz:feat/telegram-edit-message
Open

feat: add Telegram message editing support#185
Marenz wants to merge 1 commit intospacedriveapp:mainfrom
Marenz:feat/telegram-edit-message

Conversation

@Marenz
Copy link
Collaborator

@Marenz Marenz commented Feb 24, 2026

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_message tool that allows agents to specify a message ID and new content, with Telegram-specific handling via the editMessageText API and graceful no-op fallbacks for other messaging platforms.

Key changes:
A new EditMessageTool in src/tools/edit_message.rs that sends OutboundResponse::EditMessage events. A new OutboundResponse::EditMessage variant carrying message_id and text fields. Integration of an edited_flag through the channel event loop to track when a message edit occurs. Platform-specific implementations: Telegram uses editMessageText with automatic HTML fallback to plain text; Discord, Slack, Twitch, and Webhook adapters handle edits gracefully without errors. Updates to src/agent/channel.rs to thread the edited_flag through the agent turn and result handling.

Written by Tembo for commit 436fe39e. This will update automatically on new commits.

- 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,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
/// Other platforms: falls back to sending a new message (no-op).
/// Other platforms: no-op (message unchanged).

Comment on lines +478 to +480
let html = markdown_to_telegram_html(&text);

if let Err(html_error) = self
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: there’s a whitespace-only line after markdown_to_telegram_html(&text); (shows up in the diff).

Suggested change
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,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant