feat: Webhooks (Aufgaben 6-10) — webhook.py, worker.py, Flask-App, WhatsApp + Telegram Routes + Tests
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user