-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (26 loc) · 865 Bytes
/
main.py
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
import json
import os
from flask import Flask, render_template, request
app = Flask(__name__)
WEBHOOK_DATA: dict = {}
@app.route("/")
def index():
return render_template('index.html', data=WEBHOOK_DATA)
@app.route('/webhook', methods=['POST', 'GET'])
def webhook():
global WEBHOOK_DATA
if request.method == 'POST':
try:
WEBHOOK_DATA = request.json
data = {"status": "success"}
return data, 200
except Exception:
bytes_value = request.data
decode_json = bytes_value.decode('utf8').replace("'", '"')
data = {"status": "success"}
WEBHOOK_DATA = json.loads(decode_json)
return data, 200
if request.method == 'GET':
return WEBHOOK_DATA
if __name__ == '__main__':
app.run(debug=True, port=os.getenv("PORT", default=5000))