使用 getWebhookInfo 检查 Telegram Webhook
getWebhookInfo 显示 Telegram 能否向你的机器人投递更新。下面介绍每个字段的含义以及常见投递错误的修复方法。
几次点击即可完成——无需写代码、无需服务器,直接在浏览器中操作。
检查我的 WebhookWebhookInfo 字段
| 字段 | 含义 |
|---|---|
url | 当前 Webhook URL。为空表示机器人使用 getUpdates(长轮询)。 |
pending_update_count | 等待投递的更新数。数量持续增长说明服务器没有接收。 |
last_error_date、last_error_message | 最近一次投递错误的时间(Unix)和内容。 |
last_synchronization_error_date | Telegram 数据中心之间同步更新时出错,通常是暂时的。 |
ip_address | Telegram 当前发送请求的 IP 地址。 |
max_connections | 最大同时连接数。 |
allowed_updates | 已订阅的更新类型;缺失表示使用默认集合。 |
has_custom_certificate | 是否上传了自签名证书。 |
使用 curl 检查
curl "https://api.telegram.org/bot$BOT_TOKEN/getWebhookInfo"响应示例:
{
"ok": true,
"result": {
"url": "https://example.com/telegram/webhook",
"has_custom_certificate": false,
"pending_update_count": 12,
"ip_address": "203.0.113.10",
"last_error_date": 1791446400,
"last_error_message": "Wrong response from the webhook: 502 Bad Gateway",
"max_connections": 40,
"allowed_updates": ["message", "callback_query"]
}
}常见的 last_error_message
SSL error {error:...:certificate verify failed}——证书链不完整、证书过期或为自签名。请安装完整证书链(fullchain.pem)或上传自签名证书的公钥。Connection timed out/Read timeout expired——服务器无法访问或响应太慢。请立即返回 200,再在后台处理更新。Connection refused——该端口没有服务在监听,或防火墙拦截了 Telegram 的 IP。Failed to resolve host: Name or service not known——域名 DNS 有问题。Wrong response from the webhook: 404 Not Found——URL 路径或路由错误。Wrong response from the webhook: 401 Unauthorized/403 Forbidden——服务器拒绝了请求,通常是 Secret Token 不匹配。Wrong response from the webhook: 500/502/503——处理程序崩溃,或反向代理后面的上游服务不可用。请查看服务器日志。
修复之后
刷新状态:last_error_date 会保留到下一次出错,因此请将其时间与当前时间比较。如果队列中有过期的更新,可用 drop_pending_updates 丢弃。
几次点击即可完成——无需写代码、无需服务器,直接在浏览器中操作。
检查我的 Webhook