Use this method to send a voice note. If you want nandbox clients to display the file as a playable voice message, your voice audio must be in an .ogg file encoded with OPUS (other formats may be sent as audio or document). On success, the sent message is returned.
📘 Bots can currently send voice note files of up to 50 MB in size, this limit may be changed in the future.
Field
Type
Required
Description
method
String
Yes
"sendVoice"
chat_id
String
Yes
Unique identifier for the target Chat or User_id
size
String
Optional
Size of document
voice
String
Yes
Voice note: Pass a media_id as a string to send a voice note that exists on the nandbox servers.
caption
String
Optional
Voice note caption: 0-256 characters
disable_web_page_preview
Boolean
Optional
Disables link previews for links in this message
disable_notification
Boolean
Optional
Sends the message silently: users will receive a notification with no sound.
reply_to_message_id
String
Optional
Unique identification for the original parent message if the message is a reply.
reference
Long
Yes
Unique local identifier for the target Chat or User.
to_user_id
String
Optional
Unique identifier of the target user if a user replies or sends a message to the target user within a Group or Channel.
echo
Integer
Optional
1= repeat message 0= no echo
menu_ref
String
Optional
Menu reference for an existing predefined menu: the menu will be displayed as an inline menu associated with the message.
inline_menu
Array of Menu
Optional
Inline menu object to hold menus: if both inline_menu and menu_ref are defined, the priority goes to inline_menu.
chat_settings
Integer
Optional
1: if you want to send to bot chat settings

Requests

json
{ "method": "sendVoice", "chat_id": "44125896441110235", "reference": 95959775121117, "voice": "8a94888c62b2f3b632c4bc00da4387b8a465e5ee8d521bf428b49625c0dee3b9.m4a", "size": 650, "caption": "Beautiful Days" }
java
String uploadedVoiceId = MediaTransfer.uploadFile(TOKEN, "< .ogg File Path >"); if (uploadedVoiceId != null) { // VoiceOutMessage voiceMsg = new VoiceOutMessage(); voiceMsg.setChatId(incomingMsg.getChat().getId()); voiceMsg.setReference(getUniqueId()); voiceMsg.setVoice(uploadedVoiceId); voiceMsg.setEcho(0); api.send(voiceMsg); // }
javascript
if (incomingMsg.isVoiceMsg()) { let voiceOutMsg = new VoiceOutMessage(); voiceOutMsg.chat_id = incomingMsg.chat.id; voiceOutMsg.reference = Id(); voiceOutMsg.voice = incomingMsg.voice.id; voiceOutMsg.size = 700; voiceOutMsg.caption = "Vocie From Bot"; api.send(JSON.stringify(voiceOutMsg)); }

Response

json
{ "method": "message", "message": { "date": 1600168078602, "reference": 2097, "chat": { "name": "Alice Park", "id": "90089668723575679", "terminal": "Mobile", "type": "Contact", "version": "('0HNt','1QBk','2c2H','31RN')" }, "sent_to": { "id": "90091903321704167" }, "message_id": "i1_CD11KwDr126551", "style": 6, "from": { "name": "Alice Park", "id": "90089668723575679", "terminal": "Mobile", "type": "Contact", "version": "('0HNt','1QBk','2c2H','31RN')" }, "text": "Hello", "type": "text" } }

Powered by Notaku