Answer the question
In order to leave comments, you need to log in
Telegram Bot in PHP sends 3 messages in response to location 1. Can you help?
I created a Telegram bot that sends the same message to the user, but he sends 3 messages instead of one.
The code:
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$mess = 'https://api.telegram.org/bot***BOT_TOKEN***/getUpdates';
$com = file_get_contents($mess);
$com1 = json_decode($com);
$mess1 = end($com1->result)->message->message_id;
$mess2 = $mess1;
while(true){
$com = file_get_contents($mess);
$com1 = json_decode($com);
$mess1 = end($com1->result)->message->message_id;
if($mess2 != $mess1){
//end($com1->result)->message->chat->id
$send = 'https://api.telegram.org/bot***BOT_TOKEN***/sendMessage?chat_id=' . end($com1->result)->message->chat->id . '&text=' . end($com1->result)->message->text;
file_get_contents($send);
$mess2 = $mess1;
}
}
?>
Answer the question
In order to leave comments, you need to log in
Why read multiple messages in a row? The webhook URL is called every time you receive a message.
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$mess = 'https://api.telegram.org/bot***BOT_TOKEN***/getUpdates';
$com = file_get_contents($mess);
$com1 = json_decode($com);
$mess = end($com1->result)->message;
if (is_numeric($mess->chat->id) {
$send = 'https://api.telegram.org/bot***BOT_TOKEN***/sendMessage?'
.'chat_id=' . $mess->chat->id
.'reply_to_message_id=' . $mess->id
.'&text=' . $mess->text;
file_get_contents($send);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question