Skip to content

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_idStringOptional
Unique identifier of the business connection on behalf of which the message will be sent
chat_idIntegerStringRequired
Unique identifier for the target chat or username of the target channel (in the format @channelusername)
message_thread_idIntegerOptional
Unique 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_idIntegerOptional
Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
voiceInputFileStringRequired📎 Files
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 »
captionStringOptional✏️ FormattableminLen 0maxLen 1024
Voice message caption, 0-1024 characters after entities parsing
parse_modeStringOptional
Mode for parsing entities in the voice message caption. See formatting options for more details.
caption_entitiesMessageEntity[]Optional
A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse\_mode
durationIntegerOptional
Duration of the voice message in seconds
disable_notificationBooleanOptional
Sends the message silently. Users will receive a notification with no sound.
protect_contentBooleanOptional
Protects the contents of the sent message from forwarding and saving
allow_paid_broadcastBooleanOptional
Pass 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_idStringOptional
Unique identifier of the message effect to be added to the message; for private chats only
suggested_post_parametersSuggestedPostParametersOptional
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.
reply_parametersReplyParametersOptional
Description of the message to reply to
Additional 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

CodeErrorCause
400Bad Request: chat not foundInvalid or inaccessible chat_id — verify the chat exists and the bot is a member
400Bad Request: VOICE_MESSAGES_FORBIDDENThe target user has disabled receiving voice messages from non-contacts
400Bad Request: failed to get HTTP URL contentTelegram could not fetch the audio from the provided HTTP URL
400Bad Request: wrong file typeThe file is not OGG/OPUS, MP3, or M4A — it will fall back to Audio or Document
400Bad Request: caption is too longCaption exceeds 1024 characters after entity parsing
413Request Entity Too LargeUploaded file exceeds the 50 MB limit
403Forbidden: bot was blocked by the userThe target user has blocked the bot
403Forbidden: not enough rightsBot lacks can_send_voice_notes permission in the group/channel
429Too Many Requests: retry after NFlood 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_FORBIDDEN error. 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.
  • sendVoice vs sendAudio. Use sendVoice when you want the audio to appear in the voice-message player (waveform UI). Use sendAudio when you want a music player card showing performer and title metadata.
  • Cache file_id after the first upload. Capture message.voice.file_id from the returned MessageContext and persist it to avoid re-uploading on repeat sends.
  • Captions support formatting entities. Use the format tagged template from "gramio" to embed bold, italic, links, and other entities — never add parse_mode alongside format.

See Also