-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (30 loc) · 1.09 KB
/
Copy pathapp.py
File metadata and controls
40 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, request, jsonify
import os
import logging
from dotenv import load_dotenv
from util.verify_webhook_signature import verify_webhook_signature
from controllers.webhooks import handle_create, handle_update, handle_cancel
load_dotenv()
app = Flask(__name__)
port = int(os.getenv("PORT", 3000))
@app.route("/webhook-catcher", methods=["POST"])
@verify_webhook_signature
def webhook_catcher():
req = request.get_json()
notification_type = req.get("notification_type")
if notification_type == "create":
return handle_create(req)
elif notification_type == "change":
return handle_update(req)
elif notification_type == "cancel":
return handle_cancel(req)
else:
app.logger.info(f"Some other webhook was received: {notification_type}")
return jsonify({"status": "ignored"}), 200
if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
app.logger.setLevel(logging.INFO)
app.run(host="0.0.0.0", port=port, debug=True)