Files
funstat-mcp/scripts/check_webhook.py
2025-11-01 21:58:03 +08:00

53 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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()