Add voice note cancellation feature during transcription

- Implemented functionality to cancel pending voice transcriptions when a user replies with the /clear command.
- Updated the Telegram and Discord platform classes to manage pending voice messages, including registration and cancellation logic.
- Enhanced the message handler to delete associated messages and notify users when a voice note is cancelled.
- Added tests to ensure the cancellation feature works as expected during transcription.
This commit is contained in:
Alishahryar1 2026-02-18 06:36:42 -08:00
parent f66834e402
commit 2220880671
4 changed files with 135 additions and 0 deletions

View file

@ -923,6 +923,26 @@ class ClaudeMessageHandler:
self.tree_queue.resolve_parent_node_id(reply_id) if tree else None
)
if not branch_root_id:
cancel_fn = getattr(self.platform, "cancel_pending_voice", None)
if cancel_fn is not None:
cancelled = await cancel_fn(incoming.chat_id, reply_id)
if cancelled is not None:
voice_msg_id, status_msg_id = cancelled
msg_ids_to_del: set[str] = {voice_msg_id, status_msg_id}
if incoming.message_id is not None:
msg_ids_to_del.add(str(incoming.message_id))
await self._delete_message_ids(incoming.chat_id, msg_ids_to_del)
msg_id = await self.platform.queue_send_message(
incoming.chat_id,
self._format_status(
"🗑", "Cleared.", "Voice note cancelled."
),
fire_and_forget=False,
)
self._record_outgoing_message(
incoming.platform, incoming.chat_id, msg_id, "command"
)
return
msg_id = await self.platform.queue_send_message(
incoming.chat_id,
self._format_status(