-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
maule edited this page Aug 16, 2026
·
1 revision
Common issues and solutions.
curl "https://api.telegram.org/bot<YOUR_TOKEN>/getWebhookInfo"Expected:
{
"ok": true,
"result": {
"url": "https://your-domain.com/webhook.php",
"has_custom_certificate": false,
"pending_update_count": 0
}
}Problems:
| Issue | Solution |
|---|---|
"url": "" |
Register webhook again |
pending_update_count > 0 |
Bot is not processing updates |
"has_custom_certificate": true |
Use standard certificate |
# Send test update
curl -X POST "https://your-domain.com/webhook.php" \
-H "Content-Type: application/json" \
-H "X-Telegram-Bot-Api-Secret-Token: your_secret" \
-d '{
"update_id": 123456,
"message": {
"message_id": 1,
"date": '$(date +%s)',
"chat": {"id": 123456, "type": "private"},
"text": "test"
}
}'# PHP errors
tail -f /var/log/php-errors.log
# Web server logs
tail -f /var/log/nginx/error.log # Nginx
tail -f /var/log/apache2/error.log # Apache
# Bot logs
tail -f /var/log/telegram-bot.log# Check certificate
openssl s_client -connect your-domain.com:443
# Renew Let's Encrypt
certbot renew --force-renewalProblem: HTTP endpoint registered instead of HTTPS
Solution:
# Re-register with HTTPS
curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \
-d "url=https://your-domain.com/webhook.php"Telegram only accepts:
- HTTPS (not HTTP)
- Valid certificate
- Public domain (not localhost or IP)
- Port 443
{"ok":false,"error_code":401,"description":"Unauthorized"}
Solutions:
- Verify token spelling
- Copy from @BotFather (not from URL)
- Check for extra spaces
- Token might be revoked
Revoke and get new token:
- Message @BotFather
- Select bot
-
/revokeor/newtoken
Immediate Action:
- Revoke old token (in @BotFather)
- Get new token
- Update environment variables
- Redeploy bot
Connection timeout to Telegram API
Solutions:
- Check network connectivity:
ping api.telegram.org
curl -v https://api.telegram.org/- Check firewall:
sudo ufw status
# Should allow port 443- Check cURL:
php -m | grep curlSSL certificate problem: self signed certificate
Solution:
// Temporarily disable SSL verification (not recommended)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Better: install CA certificates
apt install ca-certificates{"ok":false,"error_code":400,"description":"Bad Request: message text is empty"}
Solutions:
- Check if text is empty
- Use null-safe operator:
$text = $bot->getTextMessage() ?? "default";- Validate input:
if (!$bot->getTextMessage()) {
return;
}{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
Solutions:
- Get correct chat ID:
echo $bot->getChatId(); // Verify it's correct- Check message before sending:
if (!$bot->getChatId()) {
error_log("No chat ID available");
exit;
}{"ok":false,"error_code":400,"description":"Bad Request: reply_markup_invalid"}
Solutions:
- Verify keyboard structure:
$keyboard = $bot->buildKeyboardOfInline([
"Button" => "data", // Both key and value must be strings
]);
// Verify JSON
echo json_encode($keyboard);- Check for encoding issues:
// Use UTF-8
header('Content-Type: text/html; charset=utf-8');// Check file exists
if (!file_exists($photoPath)) {
error_log("Photo not found: $photoPath");
}
// Validate path
$safe = validatePhotoPath($photo);
if (!$safe) {
error_log("Invalid photo path");
}{"ok":false,"error_code":413,"description":"Payload Too Large"}
Telegram limits:
- Photos: 5 MB
- Documents: 50 MB
Solution:
$maxSize = 5 * 1024 * 1024; // 5 MB
if (filesize($photo) > $maxSize) {
error_log("Photo too large");
}Causes:
- Slow database queries
- Inefficient code
- Network latency
Solutions:
// Measure execution time
$start = microtime(true);
// ... bot code ...
$elapsed = microtime(true) - $start;
error_log("Bot took {$elapsed}s");
// Cache frequently accessed data
$user = $cache->get("user_$id") ?? fetchUser($id);
// Optimize database queries
SELECT * FROM users WHERE id = 123; // Good
SELECT * FROM users; // Bad - loads all usersSolutions:
- Check for infinite loops
- Monitor with:
top -p $(pgrep -f php)
ps aux | grep php- Reduce logging verbosity
- Cache API responses
Fatal error: Allowed memory size exhausted
Solutions:
// Increase memory limit (temporary)
ini_set('memory_limit', '256M');
// Debug memory usage
echo memory_get_usage() / 1024 / 1024 . " MB";
// Unset large variables
unset($largeArray);
gc_collect_cycles();Connection refused to localhost:3306
Solutions:
# Check MySQL is running
systemctl status mysql
# Start MySQL
systemctl start mysql
# Test connection
mysql -h localhost -u bot -p// Enable error reporting
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Catch errors
try {
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$userId]);
} catch (Exception $e) {
error_log("Database error: " . $e->getMessage());
}$bot = new botTG(
token: $token,
updates: $updates,
debug: true, // Enable debug
debugFile: '/var/log/bot-debug.log'
);// Log all incoming updates
error_log("Webhook received: " . file_get_contents("php://input"));// Simulate webhook update
$testUpdate = json_encode([
'update_id' => 123456,
'message' => [
'message_id' => 1,
'date' => time(),
'chat' => ['id' => 123456, 'type' => 'private'],
'text' => 'test',
],
]);
$bot = new botTG(token: $token, updates: $testUpdate, debug: true);# Test PHP
php -v
php -m | grep curl
# Test specific extension
php -i | grep "curl"| Code | Meaning | Solution |
|---|---|---|
| 400 | Bad Request | Check message/keyboard format |
| 401 | Unauthorized | Verify bot token |
| 403 | Forbidden | Check webhook URL/certificate |
| 404 | Not Found | Endpoint or chat doesn't exist |
| 409 | Conflict | Webhook already registered |
| 429 | Too Many Requests | Rate limited - wait before retrying |
| 500 | Server Error | Telegram API issue - retry later |
# Get bot info
curl "https://api.telegram.org/bot<TOKEN>/getMe"
# Check webhook
curl "https://api.telegram.org/bot<TOKEN>/getWebhookInfo"
# Get updates manually
curl "https://api.telegram.org/bot<TOKEN>/getUpdates"- GitHub Issues: https://github.com/LightYagami28/TGbotPHP/issues
- GitHub Discussions
- Stack Overflow tag:
telegram-bot
Still stuck? Check Security Guide or open an issue.