I’m building a Telegram bot using Laravel but it’s not sending replies back to users. I set up a webhook endpoint and configured everything but messages aren’t getting responses.
Here’s my route setup:
Route::post('webhook/telegram', [ChatBotController::class, 'handleMessage'])->name('telegram_webhook');
And here’s the controller method:
public function handleMessage() {
$input = json_decode(file_get_contents('php://input'), true);
if (!$input) {
return response('Invalid input', 400);
}
if (!isset($input['update_id']) || !isset($input['message'])) {
return response('Missing required fields', 400);
}
$messageData = [
'chat_id' => $input['message']['chat']['id'],
'text' => 'Echo: ' . $input['message']['text'],
];
$botToken = '123456789:ABCDEF_your_bot_token_here';
file_get_contents('https://api.telegram.org/bot' . $botToken . '/sendMessage?' . http_build_query($messageData));
return response('OK', 200);
}
The webhook was set successfully and I got a positive response from Telegram API. Laravel logs don’t show any errors either. But when I send messages to the bot, nothing comes back. What could be the issue here?