Telegram Bot webhook not responding to messages despite successful setup

I’m having trouble with my Telegram bot webhook setup. The bot works when I test the URL directly in my browser, but it doesn’t respond when I send actual messages through Telegram.

I’m pretty new to working with Telegram bots. I already configured the webhook and it seemed to work fine during setup. When I visit my webhook URL manually, the bot processes everything correctly. However, when I try sending commands or regular text messages from the actual Telegram chat, nothing happens.

My webhook setup went smoothly and I’m using a self-signed SSL certificate that I uploaded during the webhook configuration process as required by Telegram’s documentation.

Here’s the PHP code I’m using:

<?php 
error_reporting(E_ALL);
$apiToken = "BOT_TOKEN_HERE";
$telegramAPI = "https://api.telegram.org/bot" . $apiToken;

$input = file_get_contents("php://input");
$data = json_decode($input, TRUE);

$userID = $data["message"]["chat"]["id"];
$userMessage = $data["message"]["text"];

switch ($userMessage) {
    case "/start":
        sendReply($userID, "Hello there!");
        break;
    case "/help":
        sendReply($userID, "Here's some help");
        break;
    default:
        sendReply($userID, "I don't understand that command");
        break;
}

function sendReply($chat_id, $text){
    $apiURL = $GLOBALS["telegramAPI"] . "/sendMessage?chat_id=" . $chat_id . "&text=" . urlencode($text);
    file_get_contents($apiURL);
}

Can anyone spot what might be going wrong with my setup?

also, double-check your ssl cert. Sometimes self-signed ones cause issues with telegram not being able to call the webhook properly. Good luck!

I encountered a similar issue recently, and the problem lies in the way Telegram sends updates. It’s essential to verify whether the incoming data contains a message before trying to access it. Telegram sends various types of updates, including callback queries and edited messages. If your script attempts to access $data[‘message’][‘text’] without ensuring that the message field exists, it will fail silently. Start by adding checks with isset for both ‘message’ and ‘text’. Avoiding this step may lead to your bot becoming unresponsive after encountering non-message updates.

Your webhook URL probably isn’t handling POST requests from Telegram’s servers. When you visit the URL in your browser, that’s a GET request - but Telegram sends webhook data via POST. Check your server logs to see if requests are actually hitting your endpoint. I had the same issue where my hosting provider was blocking external POST requests. Also verify your webhook is set correctly by calling getWebhookInfo - sometimes registration fails without any error. And add error checking around json_decode since it’ll break when there’s no message data.

Debugging Telegram webhooks manually sucks. You can’t see what data Telegram’s actually sending or log errors properly.

Had this exact problem last year. Wasted hours on SSL certs and server configs when it was just data validation issues.

You need proper webhook handling with logging and error management. Skip the raw PHP guesswork - try Latenode instead.

Latenode has built-in Telegram webhook handling that validates incoming data automatically and logs everything. You’ll see exactly what Telegram sends, catch errors in real time, and handle different update types without writing tons of validation code.

The visual workflow makes it easy to add conditions for message types, handle errors gracefully, and add features like user state management or database logging.

Moved all my Telegram bots to Latenode after similar webhook nightmares. Now I focus on bot logic instead of debugging webhook mysteries.

Check if ur hosting provider blocks Telegram’s webhook IPs - mine did this by default and I had to manually whitelist them. Also, add basic logging like file_put_contents('debug.log', $input); to see if any data’s coming through.