send_voice
Send voice messages to Telegram chats using OGG/OPUS audio files from URLs or file IDs, with optional captions, formatting, and silent delivery options.
Instructions
Send a voice message to a Telegram chat.
Args: chat_id: Target chat ID. voice_url: URL or file_id of the voice message (OGG with OPUS). caption: Optional caption. parse_mode: HTML, Markdown, MarkdownV2, or None. duration: Duration in seconds. disable_notification: Send silently.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chat_id | Yes | ||
| voice_url | Yes | ||
| caption | No | ||
| parse_mode | No | HTML | |
| duration | No | ||
| disable_notification | No |
Implementation Reference
- aiogram_mcp/tools/media.py:86-131 (handler)The send_voice function handles sending a voice message to a Telegram chat, including rate limiting and permission checks.
async def send_voice( chat_id: int, voice_url: str, caption: str | None = None, parse_mode: str | None = "HTML", duration: int | None = None, disable_notification: bool = False, ) -> SendMediaResult: """Send a voice message to a Telegram chat. Args: chat_id: Target chat ID. voice_url: URL or file_id of the voice message (OGG with OPUS). caption: Optional caption. parse_mode: HTML, Markdown, MarkdownV2, or None. duration: Duration in seconds. disable_notification: Send silently. """ if not ctx.is_chat_allowed(chat_id): result = SendMediaResult(ok=False, error=f"Chat {chat_id} is not allowed.") if ctx.audit_logger: ctx.audit_logger.log( "send_voice", {"chat_id": chat_id, "voice_url": voice_url}, result.ok, result.error, ) return result try: if ctx.rate_limiter: await ctx.rate_limiter.acquire() msg = await ctx.bot.send_voice( chat_id=chat_id, voice=voice_url, caption=caption, parse_mode=normalize_parse_mode(parse_mode), duration=duration, disable_notification=disable_notification, ) result = SendMediaResult(ok=True, message_id=msg.message_id, chat_id=msg.chat.id) except ValueError as exc: result = SendMediaResult(ok=False, error=str(exc)) except (TelegramBadRequest, TelegramForbiddenError) as exc: result = SendMediaResult(ok=False, error=str(exc))