Use this method to send audio files, if you want nandbox clients to display them in the music player. Your audio must be in the .mp3 format. On success, the sent message is returned.
πBots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
Field | Type | Required | Description |
method | String | Yes | "sendAudio" |
chat_id | String | Yes | Unique identifier for the target Chat or User_id. |
audio | String | Yes | |
performer | String | Optional | Audio fileβs performer. |
title | String | Optional | Audio fileβs title. |
caption | String | Optional | Audio 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 this message as set forth by the bot. |
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 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": "sendAudio", "chat_id": "14774569822200013", "reference": 64818504566661, "audio": "a2517a187f5c78f3b3b5b6e535e7ab6be54e524e7f94b718b079b82a9c008ee6.mp3", "performer": "Ed Clark", "title": " Song", "caption": "Far away from here" }
java// SEND AUDIO else if (incomingMsg.getText().toLowerCase().equals("audio")) { String uploadedAudioId = MediaTransfer.uploadFile(TOKEN, System.getProperty("user.dir") + "/src/main/resources/upload/hello.mp3"); AudioOutMessage audioMsg = new AudioOutMessage(); audioMsg.setChatId(incomingMsg.getChat().getId()); audioMsg.setReference(Utils.getUniqueId()); audioMsg.setCaption("Audio From Bot"); if (uploadedAudioId != null) { audioMsg.setAudio(uploadedAudioId); audioMsg.setTitle("Hello"); audioMsg.setPerformer("Male"); api.send(audioMsg); } else { System.out.println("Upload Failed"); } }
javascriptMediaTransfer.uploadFile(TOKEN, "./your_audio.mp3", config.UploadServer).then( (uploadedAudioId) => { let audioOutMsg = new AudioOutMessage(); audioOutMsg.chat_id = incomingMsg.chat.id; audioOutMsg.reference = Id(); audioOutMsg.audio = uploadedAudioId; audioOutMsg.performer = "Perfomer Man"; audioOutMsg.title = " Song"; audioOutMsg.caption = "Audio From Bot"; api.send(JSON.stringify(audioOutMsg)); } );
pythonnapi.send_audio("chatId","audioId",Utils.get_unique_id())
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" } }