Mohammad
Mohammad

Reputation: 790

Send mp3 file with php to telegram

I use this Api for manage robot .

https://github.com/mgp25/Telegram-Bot-API

I want send MP3 from URL to telegram user so i change class like this and add this line after line 399

'audio/mpeg'   =>  '.mp3',

mp3 send with success but my problem is function return json and not convert json to array;I echo returned data and I've got it at the end of json string add one 1 like this

{"ok":true,"result":{"message_id":46328,"from":{"id":115910361,"first_name":"Persian Robot","username":"TPersian_bot"},"chat":{"id":133180682,"first_name":"Mohammad Reza","last_name":"Behzadfar","username":"Lifesoul","type":"private"},"date":1457607231,"audio":{"duration":176,"mime_type":"audio\/mpeg","title":"Mozoo Chiye","performer":"Yasin","file_id":"BQADBAADKwAD2aboBniCRUQ1WE48Ag","file_size":7137408}}}1

and this my code:

    $Telegram = new Telegram(API);
$result = $Telegram->sendAudio(133180682, "https://rjmediamusic.com/media/mp3/Yasin-Mozoo-Chiye.mp3");
var_dump(json_decode(rtrim($result,'1'),TRUE));

Upvotes: 2

Views: 1638

Answers (1)

Littlebobbydroptables
Littlebobbydroptables

Reputation: 3731

About 1 in the end of json, there is plenty of question-answers on stackoverflow (for example). But if you will not change anything and still want to get an array, you can try this

$json = '{"ok":true,"result":{"message_id":46328,"from":{"id":115910361,"first_name":"Persian Robot","username":"TPersian_bot"},"chat":{"id":133180682,"first_name":"Mohammad Reza","last_name":"Behzadfar","username":"Lifesoul","type":"private"},"date":1457607231,"audio":{"duration":176,"mime_type":"audio\/mpeg","title":"Mozoo Chiye","performer":"Yasin","file_id":"BQADBAADKwAD2aboBniCRUQ1WE48Ag","file_size":7137408}}}1';
var_dump(json_decode(trim($json, '1')));

Upvotes: 2

Related Questions