-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
45 lines (37 loc) · 1.32 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
41
42
43
44
45
import requests
from flask import Flask, render_template, request
from flask_restful import Api, Resource
from resources import Authorization, Chatbot, Contexta
app = Flask(__name__, template_folder="templates")
# Web section begins here
@app.route("/", methods=["GET", "POST"])
def get_access_token():
"""
Renders the page for the user to place his client_id and client_secret
Calls the authentication system and stores the access token
"""
if request.method == "GET":
return render_template("index.html")
elif request.method == "POST":
# Authenticate
auth = Authorization()
response = auth.post()
return render_template("index.html", data=response[0])
@app.route("/contexta/intents", methods=["GET"])
def get_intents():
"""
Gets the intent for the example transcription
"""
contexta = Contexta()
response = contexta.get()
normal_dict = {
key: value for key, value in response[0].items()
} # Default dict has an error key that we don't want
return render_template("contexta.html", data=normal_dict)
# API section begins here
api = Api(app)
api.add_resource(Authorization, "/v1/auth")
api.add_resource(Chatbot, "/v1/receive-sms")
api.add_resource(Contexta, "/v1/contexta")
if __name__ == "__main__":
app.run(port="5003", debug=True)