audio - php telegram sendAudio -
i have problem 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 audio lenghtof 9 or more seconds. tried .mp3 nothing. same function audio lenght of 6 or less seconds works. looked in documentation , says 50mb files restricted. pls. here's $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); }
i using code send mp3 audio file telegram php application , it's working fine me.
$bot_token = 'yourbottoken'; $chat_id = '@yourchannel'; $filepath = 'your/path/file'; define('botapi', 'https://api.telegram.org/bot' . $bot_token . '/'); $cfile = new curlfile(realpath($filepath)); $data = [ 'chat_id' => $chat_id, 'audio' => $cfile, 'caption' => $message ]; $ch = curl_init(botapi . 'sendaudio'); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $data); curl_setopt($ch, curlopt_ssl_verifypeer, true); curl_exec($ch); curl_close($ch);
Comments
Post a Comment