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
+36
View File
@@ -0,0 +1,36 @@
"""Flask-Blueprint für WhatsApp-Webhook-Endpunkt."""
from flask import Blueprint, request, jsonify
from src.queue.webhook import verify_whatsapp_signature
from src.models.submission import Submission
whatsapp_bp = Blueprint("whatsapp", __name__)
@whatsapp_bp.route("/webhook/whatsapp", methods=["GET", "POST"])
def whatsapp_webhook() -> tuple:
"""WhatsApp Webhook-Endpunkt.
GET = Verifikation (Hub Challenge)
POST = Eingehende Nachricht mit Signaturprüfung
"""
# GET = Verifikation (Hub Challenge)
if request.method == "GET":
mode = request.args.get("hub.mode")
token = request.args.get("hub.verify_token")
challenge = request.args.get("hub.challenge")
if mode == "subscribe" and token == "bsn_verify_token":
return challenge, 200
return "Verification failed", 403
# POST = Eingehende Nachricht
signature = request.headers.get("X-Hub-Signature-256", "")
payload = request.get_data()
if not verify_whatsapp_signature(payload, signature):
return jsonify({"error": "Invalid signature"}), 401
# Hier würde die Submission in die Queue eingereiht werden
# qh = current_app.queue_handler
return jsonify({"status": "accepted"}), 200