-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_webhook.py
More file actions
37 lines (27 loc) · 813 Bytes
/
Copy pathset_webhook.py
File metadata and controls
37 lines (27 loc) · 813 Bytes
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
36
37
import os
import sys
import requests
def main():
token = os.getenv("TELEGRAM_BOT_TOKEN")
webhook_url = os.getenv("WEBHOOK_URL")
secret = os.getenv("TELEGRAM_WEBHOOK_SECRET", "")
if not token:
print("Missing TELEGRAM_BOT_TOKEN")
sys.exit(1)
if not webhook_url:
print("Missing WEBHOOK_URL")
sys.exit(1)
api_url = f"https://api.telegram.org/bot{token}/setWebhook"
payload = {"url": webhook_url}
if secret:
payload["secret_token"] = secret
resp = requests.post(api_url, data=payload, timeout=15)
resp.raise_for_status()
data = resp.json()
if not data.get("ok"):
print(data)
sys.exit(1)
print("Webhook registered successfully.")
print(f"URL: {webhook_url}")
if __name__ == "__main__":
main()