-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
40 lines (33 loc) · 1.15 KB
/
app.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
36
37
38
39
40
from cli import generate_toml
from flask import Flask, Response, request
import os
import requests
app = Flask(__name__)
app.config.from_object("config.BaseConfig")
@app.route("/webhook", methods=["POST"])
def webhook():
if request.method == 'POST':
json = request.get_json()
print(json)
if "challenge" in json:
return Response(json["challenge"], mimetype="text/plain")
return "pong"
@app.route("/matterbridge.toml")
@app.route("/")
def index():
content_auto = generate_toml()
template_url = app.config["TEMPLATE_URL"]
if template_url:
r = requests.get(template_url)
content_tmpl = r.text
content = content_tmpl.replace("{{AUTOGENERATED}}", content_auto)
else:
content = content_auto
# Supposed to be application/toml, but would rather it render in browser
# instead of downloading file.
# See: https://github.com/toml-lang/toml/issues/465#issuecomment-364506403
return Response(content, mimetype="text/toml")
if __name__ == "__main__":
port = os.environ.get("PORT", 5000)
print("Serving app at http://localhost:{} ...".format(port))
app.run(port=port)