-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram_webhook_handler.py
More file actions
37 lines (28 loc) · 923 Bytes
/
Copy pathtelegram_webhook_handler.py
File metadata and controls
37 lines (28 loc) · 923 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
"""
telegram_webhook_handler.py
Called by GitHub Actions when a repository_dispatch event is received.
Reads the Telegram update from TELEGRAM_UPDATE env var and processes it.
"""
import asyncio
import json
import logging
import os
import sys
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
log = logging.getLogger("oracle.webhook")
async def main():
raw = os.environ.get("TELEGRAM_UPDATE")
if not raw:
log.error("TELEGRAM_UPDATE env var not set.")
sys.exit(1)
try:
update = json.loads(raw)
except json.JSONDecodeError as e:
log.error(f"Failed to parse TELEGRAM_UPDATE: {e}")
sys.exit(1)
log.info(f"Processing Telegram update: {json.dumps(update)[:200]}")
from core.telegram_bot import TelegramBot
bot = TelegramBot()
await bot.handle_update(update)
if __name__ == "__main__":
asyncio.run(main())