HEMN MOVAFQI
HEMN MOVAFQI

Reputation: 33

how to get filename by file_id in telegram

for my new bot i need to get real file name. when i get the file_id and requesting for generate download link with "get file" commend, the file name is look like "file_370.mp3" but the real file name is:"michaeljackson.mp3".

i tried this code:

 $mp3name = $result['message']['audio']['title'];
   $mp3fileid = $result['message']['audio']['file_id'];

   file_get_contents( $url."/sendaudio?chat_id=118718802&audio=$mp3fileid&performer=awaperformer&title=awatitle");



$bot_url = "https://api.telegram.org/bot".$botToken;

$file_path_gen_url = $bot_url."/getfile?file_id=".$mp3fileid;
// file_get_contents( $url."/sendmessage?chat_id=118718802&text=lastfileid:filegen:$file_path_gen_url");


$file_path_result = file_get_contents($file_path_gen_url);

// echo "last file id: $last_file_id <br>";

$file_path_result = json_decode($file_path_result, TRUE);


$file_path = $file_path_result['result']['file_path'];

// echo "file_path: $file_path <br>";

$file_url = "https://api.telegram.org/file/bot".$botToken."/".$file_path;

how can i get real file name?

Upvotes: 2

Views: 10782

Answers (1)

Danil Pyatnitsev
Danil Pyatnitsev

Reputation: 2292

You can't get original file name for audio object.

here avaliable attributes : https://core.telegram.org/bots/api#audio

You can get original file name for document object.

Upvotes: 1

Related Questions