I have a problem with sendAudio() function in php telegram bot.
if (strtoupper($text) == "MUSIC") {
$voice = curl_file_create('audio.ogg');
$content = array('chat_id' => $chat_id, 'audio' => $voice);
$telegram->sendAudio($content);
}
This don’t work with an audio lenghtof 9 or more seconds. I also tried with .mp3 but nothing. Same function with an audio lenght of 6 or less seconds works. I looked in the documentation and it says only 50MB files are restricted. Help pls.
Here’s my $telegram.
include("Telegram.php");
$bot_id = "xxxxxxx:yyyyyyyy_mytoken";
$telegram = new Telegram($bot_id);
And here Telegram.php:
class Telegram {
private $bot_id = "mytoken";
private $data = array();
private $updates = array();
public function __construct($bot_id) {
$this->bot_id = $bot_id;
$this->data = $this->getData();
}
public function endpoint($api, array $content, $post = true) {
$url = 'https://api.telegram.org/bot' . $this->bot_id . '/' . $api;
if ($post)
$reply = $this->sendAPIRequest($url, $content);
else
$reply = $this->sendAPIRequest($url, array(), false);
return json_decode($reply, true);
}
public function sendAudio(array $content) {
return $this->endpoint("sendAudio", $content);
}
5
Answers
Have you tried to use sendVoice for ogg file instead of sendAudio?
I am using this code to send mp3 audio file to telegram from my php application and It’s working fine for me.
Next code did work for me well:
you can use this code to send your audio file
function sendmessage($url, $post_params) {
Example using
westacks/telebot
library: