Files
agent-zero/plugins/_telegram_integration/api/webhook.py
T
Jan Tomášek 188cff2073 Move optional runtimes into persistent gVisor plugin sandboxes
Move tunnel, browser, document, speech and integration runtimes into plugin-owned
sandboxes with lazy dependencies and instance-scoped lifecycle management.
Reuse Tuxee display assets and the sandbox image's Python/Node runtimes, enable
automatic Desktop login, and show elapsed time for each browser launch.

Slim the outer image, use offline ONNX embeddings, and calculate sandbox storage
only on demand. Include regression coverage and updated runtime documentation.
Exclude local handoff notes and temporary verification artifacts from publication.
2026-11-08 21:43:22 +01:00

53 lines
1.7 KiB
Python

import secrets
from helpers.api import ApiHandler, Request, Response
from helpers.print_style import PrintStyle
class TelegramWebhook(ApiHandler):
"""Receives Telegram updates authenticated by the webhook secret header."""
@classmethod
def requires_auth(cls) -> bool:
return False
@classmethod
def requires_csrf(cls) -> bool:
return False
@classmethod
def get_methods(cls) -> list[str]:
return ["POST"]
async def process(self, input: dict, request: Request) -> dict | Response:
from plugins._telegram_integration.helpers.bot_manager import get_bot
# Identify which bot this update is for
bot_name = request.args.get("bot", "")
if not bot_name:
return Response("Missing ?bot= parameter", 400)
instance = get_bot(bot_name)
if not instance:
return Response(f"Bot not found: {bot_name}", 404)
# Polling and incompletely configured bots must never accept HTTP updates.
secret_header = request.headers.get("X-Telegram-Bot-Api-Secret-Token", "")
if (
not instance.webhook_active
or not instance.webhook_secret
or not secrets.compare_digest(secret_header.encode(), instance.webhook_secret.encode())
):
return Response("Invalid secret token", 403)
# Parse and feed the update to aiogram
try:
from plugins._telegram_integration.helpers.bot_manager import feed_webhook
await feed_webhook(instance, input)
except Exception as e:
PrintStyle.error(f"Telegram webhook ({bot_name}): {e}")
return Response("Internal error", 500)
return {"ok": True}