T
T
ti_cho2019-09-12 12:59:07
PHP
ti_cho, 2019-09-12 12:59:07

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

1 answer(s)
E
Enj0y, 2019-09-12
@Enj0y

With each message, along with the content, objects are sent to you, including the user who sent them
https://core.telegram.org/bots/api#message

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question