If your Telegram webhook is not working, follow this troubleshooting guide to identify and fix the issue.
First, verify whether your webhook is set correctly.
Run this command in your terminal:
curl -X GET "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getWebhookInfo"
Expected response (if webhook is working):
{
"ok": true,
"result": {
"url": "https://yourdomain.com/webhook.php",
"has_custom_certificate": false,
"pending_update_count": 0,
"max_connections": 40
}
}
If "url": "" appears, the webhook is not set. Proceed to Step 2.
If the webhook is missing, register it manually:
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" -d "url=https://yourdomain.com/webhook.php"
Replace:
<YOUR_BOT_TOKEN> with your Telegram bot token.https://yourdomain.com/webhook.php with your actual webhook URL.Run getWebhookInfo again (Step 1) to verify the setup.
Telegram requires a 200 OK response from your webhook. Run:
curl -X POST -d "test=1" https://yourdomain.com/webhook.php
If it doesn't return 200, check Step 4.
Run:
curl -v https://yourdomain.com/webhook.php
If it shows SSL certificate problem, install a valid SSL:
sudo certbot --apache
or
sudo certbot --nginx
Test again with curl -v.
Ensure your webhook script is publicly accessible:
ping yourdomain.com
If there's no response, check firewall settings:
sudo ufw allow 443
Then restart your web server:
sudo systemctl restart apache2 # Apache
sudo systemctl restart nginx # Nginx
Check if your webhook.php correctly handles Telegram requests:
<?php
$data = json_decode(file_get_contents("php://input"), true);
file_put_contents("webhook.log", print_r($data, true), FILE_APPEND);
?>
Then check logs:
cat webhook.log
If nothing is logged, your server isn't receiving Telegram updates.
Try setting Telegram to long polling instead of webhooks:
curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates"
If updates appear, then Telegram is sending data, but your webhook isn't working.
Telegram needs a response within 5 seconds.
Modify webhook.php to send a quick response:
<?php
$data = json_decode(file_get_contents("php://input"), true);
file_put_contents("webhook.log", print_r($data, true), FILE_APPEND);
http_response_code(200);
echo json_encode(["status" => "OK"]);
?>
Test the webhook again!
| Issue | Fix |
|---|---|
| Webhook not set | Run setWebhook with the correct URL |
| SSL certificate issue | Install SSL via certbot |
| Webhook URL unreachable | Open port 443 and restart web server |
| PHP script not responding | Ensure it sends a 200 OK response |
Now your Telegram webhook should work!