Answer the question
In order to leave comments, you need to log in
Telegram Bot how to find out the username, knowing his id?
Hello, how to get the user's first and last name when communicating through the bot, knowing the telegram user id?
The bot is not my own, but on the salebot constructor, I pass the user id along with the link, then on the server I get the id from this link. I was able to make a handler for this id that shows the user's avatar, it works fine. But how to get the user's first and last name? I went through all the documentation. Maybe there is some getUser method?
$uid = $_GET['tg_id'];
$request = 'https://api.telegram.org/botToken/getUserProfilePhotos?user_id='.$uid;
$response = file_get_contents($request);
$info = json_decode($response)->result;
$tg_photo_id = $info->photos[0][0]->file_id;
$request = 'https://api.telegram.org/botToken/getFile?file_id='.$tg_photo_id;
$response = file_get_contents($request);
$info = json_decode($response)->result;
$tg_photo_path = $info->file_path;
$request = 'https://api.telegram.org/file/botToken/'.$tg_photo_path;
$tg_photo_file = imagecreatefromjpeg($request);
header('Content-Type: image/jpeg');
imagejpeg($tg_photo_file);
imagedestroy($tg_photo_file);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question