sendVoice
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
Parameters
business_connection_idStringOptionalUnique identifier of the business connection on behalf of which the message will be sent
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target channel (in the format
@channelusername)message_thread_idIntegerOptionalUnique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only
direct_messages_topic_idIntegerOptionalIdentifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
Audio file to send. Pass a file\_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files »
Voice message caption, 0-1024 characters after entities parsing
parse_modeStringOptionalMode for parsing entities in the voice message caption. See formatting options for more details.
A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse\_mode
durationIntegerOptionalDuration of the voice message in seconds
disable_notificationBooleanOptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanOptionalProtects the contents of the sent message from forwarding and saving
allow_paid_broadcastBooleanOptionalPass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
message_effect_idStringOptionalUnique identifier of the message effect to be added to the message; for private chats only
A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
Description of the message to reply to
reply_markupInlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReplyOptional⌨️ KeyboardsAdditional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
Returns
On success, the Message object is returned.
GramIO Usage
ts
// Send a voice message by file_id (fastest — no re-upload)
bot.command("voice", (ctx) =>
ctx.sendVoice(
"AwACAgIAAxkBAAIBjmXzPexample_voice_file_id_hereAAp4B"
)
);ts
// Upload a local OGG/OPUS file and send as a voice message
bot.command("greet", async (ctx) => {
const voice = await MediaUpload.path("./assets/greeting.ogg");
return ctx.sendVoice(voice, { duration: 5 });
});ts
// Fetch an OGG voice file from a URL and send it
bot.command("remote", (ctx) =>
ctx.sendVoice("https://example.com/message.ogg", {
duration: 8,
caption: "Listen to this announcement",
})
);ts
// Voice message with a formatted caption using the format helper
bot.command("announce", async (ctx) => {
const voice = await MediaUpload.path("./assets/notice.ogg");
return ctx.sendVoice(voice, {
caption: format`${bold("New announcement")} — ${italic("please listen carefully")}`,
duration: 12,
});
});ts
// Reply to a user's message with a voice note
bot.command("respond", async (ctx) => {
const voice = await MediaUpload.path("./assets/reply.ogg");
return ctx.replyWithVoice(voice, { duration: 3 });
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | Invalid or inaccessible chat_id — verify the chat exists and the bot is a member |
| 400 | Bad Request: VOICE_MESSAGES_FORBIDDEN | The target user has disabled receiving voice messages from non-contacts |
| 400 | Bad Request: failed to get HTTP URL content | Telegram could not fetch the audio from the provided HTTP URL |
| 400 | Bad Request: wrong file type | The file is not OGG/OPUS, MP3, or M4A — it will fall back to Audio or Document |
| 400 | Bad Request: caption is too long | Caption exceeds 1024 characters after entity parsing |
| 413 | Request Entity Too Large | Uploaded file exceeds the 50 MB limit |
| 403 | Forbidden: bot was blocked by the user | The target user has blocked the bot |
| 403 | Forbidden: not enough rights | Bot lacks can_send_voice_notes permission in the group/channel |
| 429 | Too Many Requests: retry after N | Flood control triggered — use the auto-retry plugin to handle this automatically |
Auto-retry for 429 errors
Install the @gramio/auto-retry plugin to transparently handle flood-wait errors without manual retry logic.
Tips & Gotchas
- OGG/OPUS is the preferred format. While MP3 and M4A are also accepted, OGG encoded with the OPUS codec produces the smallest file sizes at good quality and is natively supported as a voice message. Other formats (WAV, AAC, FLAC) are sent as Audio or Document instead.
- Voice messages can be disabled by users. Privacy-conscious users can block voice messages from non-contacts, causing a
VOICE_MESSAGES_FORBIDDENerror. Handle this gracefully and fall back to a text response. - 50 MB upload limit. Files larger than 50 MB cannot be sent. Most voice messages are well below this limit; compress long recordings before sending.
sendVoicevssendAudio. UsesendVoicewhen you want the audio to appear in the voice-message player (waveform UI). UsesendAudiowhen you want a music player card showing performer and title metadata.- Cache
file_idafter the first upload. Capturemessage.voice.file_idfrom the returnedMessageContextand persist it to avoid re-uploading on repeat sends. - Captions support formatting entities. Use the
formattagged template from"gramio"to embed bold, italic, links, and other entities — never addparse_modealongsideformat.
See Also
- sendAudio — Send an audio file with music player display (performer/title)
- sendVideoNote — Send a rounded video message
- sendDocument — Send an arbitrary file as a document
- Voice — The Voice type embedded in Message
- Media upload guide — Upload files using
MediaUploadhelpers - Formatting guide — Format captions using GramIO's
formattagged template - sendMessage — Send a plain text message