I am writing a telegram bot response handler. To do this, I created a page in laravel
Route::get('url/tg', [BotController::class, 'tg'])->name('tg_index');
Then I write the following code in this method
public function tg() {
$data = json_decode(file_get_contents('php://input'), TRUE);
// created array
if (!$data) {
// Some Error
}
elseif( !isset($data['update_id']) || !isset($data['message']) )
{
// Some Error output (request has not message)
}
else
{
//helmet in response to the user's message
$params = [
'chat_id' => $data['message']['chat']['id'],
'text' => $data['message']['text'],
];
}
$token = '616340****:******NVqNNK93On-cT8TLtNMiZWE*****';
file_get_contents('https://api.telegram.org/bot'.$token.'/sendMessage?'.http_build_query($params));
}
The web hook page
https://api.telegram.org/bot616340****:******FNVqNNK93On-cT8TLtNMiZWEO****/setwebhook?url=https://157.**.***.134/public/url/tg
Answer:
{“ok”:true,”result”:true,”description”:”Webhook was set”}
There are no errors in the laravel logs regarding this code.
I do not receive a response from the bot when I write a message. What am I doing wrong?
1