import hmac
import hashlib
from flask import Flask, request, jsonify
app = Flask(__name__)
# Replace with your actual Team API Key
TEAM_API_KEY = "YOUR_TEAM_API_KEY_HERE"
@app.route("/webhook", methods=["POST"])
def verify_webhook():
raw_body = request.data
received_sig = request.headers.get("x-sendx-signature", "")
algo = request.headers.get("x-sendx-signature-alg", "")
if algo.lower() != "hmac-sha256":
return jsonify({"error": "unsupported signature algorithm"}), 400
computed_sig = hmac.new(
TEAM_API_KEY.encode("utf-8"),
raw_body,
hashlib.sha256
).hexdigest()
if hmac.compare_digest(computed_sig, received_sig):
print("✅ Webhook signature verified successfully!")
return jsonify({"verified": True}), 200
else:
print("❌ Invalid webhook signature!")
return jsonify({"verified": False}), 400
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)