-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_bot_inline.py
More file actions
35 lines (33 loc) · 1.58 KB
/
check_bot_inline.py
File metadata and controls
35 lines (33 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import frappe
from frappe.utils.password import get_decrypted_password
import requests
def run():
frappe.init(site="erp.bespo.et", sites_path="/home/frappe/frappe-bench/sites")
frappe.connect()
print("--- TESTING BOT CREDENTIALS ---")
bots = frappe.get_all("Telegram Bot", fields=["name", "bot_username"])
for b in bots:
print(f"\nBot '{b.name}' (Username: {b.bot_username})")
token = get_decrypted_password("Telegram Bot", b.name, "bot_token", raise_exception=False)
bot_api_url = frappe.db.get_value("Telegram Bot", b.name, "bot_api_url") or "https://api.telegram.org/bot"
api_url = bot_api_url.rstrip('/')
if not token:
print(" [ERROR] Token missing from DB")
continue
print(" [OK] Token retrieved from DB")
try:
resp = requests.post(f"{api_url}{token}/getWebhookInfo", timeout=10)
data = resp.json()
if data.get("ok"):
wh = data.get("result", {})
print(f" [OK] Telegram API reachable. Webhook URL: {wh.get('url', 'Not Set')}")
if wh.get('pending_update_count', 0) > 0:
print(f" [WARN] Webhook has {wh['pending_update_count']} pending updates")
if wh.get('last_error_message'):
print(f" [ERROR] Webhook last error: {wh['last_error_message']}")
else:
print(f" [ERROR] Telegram API failed: {data.get('description')}")
except Exception as e:
print(f" [EXCEPTION] Connection error: {e}")
if __name__ == "__main__":
run()