A voice message is an audio recording of a person's speech that is sent to a recipient over a communication chat room.
Use this method to send a voice note file to a chat (user, group, or channel). The voice note file must be uploaded first to obtain a
media_id
before sending the message. The voice note must be in an .ogg file encoded with OPUS (other formats may be sent as audio or document). Field | Type | Required | Description |
method | String | Yes | "sendTextFile" |
app_id | String | Yes | App Id to which the message belongs. |
app_id | String | Yes | App Id to which the message belongs. |
chat_id | String | Yes | Unique identifier for the target Chat or User_id. |
to_user_id | String | Optional | Unique identifier of the target user. If the user replies or sends a message to the target user, it will be displayed within a Group or Channel. |
voice | String | Yes | Voice File: First, upload the media to the nandbox media server and obtain a media_id . Pass the media_id as a string to send the voice note. |
caption | String | Optional | Voice note caption: 0-256 characters. |
reference | Long | Yes | Unique local identifier for the message. |
reply_to_message_id | String | Optional | Unique identifier for the original parent message. Use it when the message is a reply. |
echo | Integer | Optional | If set to 1 , returns a copy of the message to the sender. Default is 0 . |
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. |
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 | Administrators can chat with the bot privately, unlike normal users. In settings, the Bot Manager section allows admins to send commands. Setting chat_settings=1 reroutes messages to the Bot Manager for administrative communication. |
Preconditions for API Functionality
The following tables outline the preconditions that must be met for the API to function correctly. Failure to meet these conditions may result in errors or unexpected behavior.
- Preconditions for API permissions
Before sending or replying to a message, ensure the following conditions are met:
Action | Required Permission | Description |
Sending a message | "Send Message" | The API must have the "Send Message" permission to send messages in a chat (user, group, or channel). |
Replying to a specific message | "Reply to Message" | The user must have the "Reply to Message" permission to respond to a specific message within a chat. |
- Preconditions for API Role in the Chat
Before sending messages, the API must meet the following status requirements based on the type of chat:
Chat Type | Required API Role | Description |
User Chat | User Pre-Joined | The user must have pre-joined (started) the API (bot) before receiving messages. |
Group Chat | Member | The API must be a member of the group to send messages. |
Channel | Admin | The API must be an admin in the channel to send messages. |
Response
â
The
messageAck
method is always returned on success.- If
echo = 1
, â An additional response is returned with themessage
method, containing a copy of the sent message object.
- If the chat type is a user chat, â Two additional responses are included:
messageDelivered
âConfirms that the message was received by the user's device.messageSeen
âConfirms that the user has read the message.
This process ensures proper acknowledgment and tracking of message status.
Example:
Requests
json{ "method": "sendVoice", "chat_id": "90089584764538542", "reference": 111111136, "app_id": "90090684293000559", "voice": "null4b21560c7f28d665876f5a04c7723406d74ba5f3b3c866f9b902fa38bcd5d19f.ogg", "echo": 1 }
javaString 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); // }
javascriptif (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)); }
pythonnapi.send_voice("chatId","voiceId",Utils.get_unique_id())
Responses
json{ "method": "messageAck", "ack": { "reference": 111111136, "date": 1741967628203, "gmid": null, "message_id": "d1_Obnka5Is126223" } }
json{ "method": "message", "message": { "date": 1741967628203, "reference": 111111136, "voice": { "duration": 75037, "size": 1032948, "id": "null4b21560c7f28d665876f5a04c7723406d74ba5f3b3c866f9b902fa38bcd5d19f.ogg" }, "chat": { "name": "My First API", "id": "90091783822039252", "terminal": "API", "type": "Bot", "version": "('0twD')" }, "sent_to": { "id": "90089584764538542" }, "message_id": "d1_Obnka5Is126223", "style": 0, "from": { "name": "My First API", "id": "90091783822039252", "terminal": "API", "type": "Bot", "version": "('0twD')" }, "type": "voice" }, "app_id": 90090684293000559 }
json{ "reference": 111111136, "method": "messageDelivered", "message_id": "d1_Obnka5Is126223" }
json{ "method": "messageSeen", "message_ids": [ "d1_Obnka5Is126223" ] }