When I use file_get_contents function in PHP to get UPDATES of my Telegram Bot, I know how to get first Chat ID or Text But this page is not just for a one user & every user that types a text, comes to this page. Also every user has its Chat ID & Text. So How can I detect the latest Text & Chat ID to react to that ? For Example: When I use this code :
$Updates['result'][0]['message']['chat']['id']
It gets the first user Chat ID that has typed in my Bot. When I react to his text, I will send my message to the latest USER uses my bot ... How can I do that ?
I suppose you use webhooks.
Each session starts with some sort of data(text message, photo,...) that user send to bot and ends with process of these data(your bot could send something in reply to user or not)
Keep in mind : In each session your bot script just have the latest message and its sender data, No more no less.
for retrieve text message that user sent,use: $update->message->text or similar.
And for retrieve sender chat_id use : $update->message->chat->id
UPDATED
If you do not use webhooks:
process is similar except that you ask telegram to send you messages one by one. Each time your script process the first unread message and script ends. If you make a loop you should save data in a db and refresh
chat_idand other message data to lates READ message to not loose correspondence.Else your message and its sender wouldn't be in relation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With