"""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