chore: initial commit
This commit is contained in:
52
scripts/check_webhook.py
Normal file
52
scripts/check_webhook.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
检查并配置 Webhook
|
||||
"""
|
||||
import requests
|
||||
import json
|
||||
|
||||
BOT_TOKEN = "8410096573:AAFLJbWUp2Xog0oeoe7hfBlVqR7ChoSl9Pg"
|
||||
BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
|
||||
|
||||
def get_webhook_info():
|
||||
"""获取 webhook 信息"""
|
||||
response = requests.get(f"{BASE_URL}/getWebhookInfo")
|
||||
return response.json()
|
||||
|
||||
def delete_webhook():
|
||||
"""删除 webhook"""
|
||||
response = requests.get(f"{BASE_URL}/deleteWebhook")
|
||||
return response.json()
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("检查 Webhook 配置")
|
||||
print("=" * 60)
|
||||
|
||||
# 获取 webhook 信息
|
||||
webhook_info = get_webhook_info()
|
||||
print("\n当前 Webhook 配置:")
|
||||
print(json.dumps(webhook_info, indent=2, ensure_ascii=False))
|
||||
|
||||
if webhook_info.get('result', {}).get('url'):
|
||||
print("\n⚠️ 检测到 Webhook 已配置!")
|
||||
print("这会阻止 getUpdates 工作。")
|
||||
print("\n是否要删除 Webhook?这样就可以使用 polling 模式。")
|
||||
print("\n删除 Webhook...")
|
||||
|
||||
delete_result = delete_webhook()
|
||||
print("\n删除结果:")
|
||||
print(json.dumps(delete_result, indent=2, ensure_ascii=False))
|
||||
|
||||
if delete_result.get('ok'):
|
||||
print("\n✓ Webhook 已删除,现在可以使用 getUpdates 了")
|
||||
|
||||
# 再次检查
|
||||
webhook_info = get_webhook_info()
|
||||
print("\n新的 Webhook 状态:")
|
||||
print(json.dumps(webhook_info, indent=2, ensure_ascii=False))
|
||||
else:
|
||||
print("\n✓ 没有配置 Webhook,可以正常使用 getUpdates")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user