feat: Webhooks (Aufgaben 6-10) — webhook.py, worker.py, Flask-App, WhatsApp + Telegram Routes + Tests

This commit is contained in:
hermes
2026-06-22 07:58:25 +00:00
parent 6f7c5eada2
commit 56b02c1c2d
11 changed files with 629 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Telegram-Webhook-Route und Queue-Integration."""
from flask import Blueprint, request, jsonify, current_app
from src.models.submission import Submission
telegram_bp = Blueprint("telegram", __name__)
@telegram_bp.route("/webhook/telegram", methods=["POST"])
def telegram_webhook() -> tuple:
"""Telegram Webhook-Endpunkt.
Nimmt eingehende Telegram-Bot-Nachrichten entgegen,
baut eine Submission und reiht sie in den QueueHandler ein.
"""
data = request.get_json(silent=True)
if not data:
return jsonify({"error": "Invalid JSON"}), 400
qh = current_app.queue_handler
message = data.get("message", {})
message_id = str(message.get("message_id", ""))
chat_id = str(message.get("chat", {}).get("id", ""))
text = message.get("text", "")
if not message_id or not text:
return jsonify({"error": "Missing message_id or text"}), 400
submission = Submission(
message_id=message_id,
plattform="telegram",
absender=chat_id,
text=text,
)
qh.enqueue(submission)
return jsonify({"status": "accepted"}), 200