-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
45 lines (40 loc) · 1.23 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
from flask import Flask
from flask import render_template,jsonify,request
import requests
import action_methods
from apiai_toolkit import *
app = Flask(__name__)
@app.route('/')
def hello():
"""
Sample flask hello world
"""
return render_template('home.html')
@app.route('/chat',methods=["POST"])
def chat():
"""
chat end point that performs NLU using rasa.ai
and constructs response from response.py
"""
message = request.form["text"]
print (message)
response = send_message(message)
if response["status"]["code"] == 200:
reply_message = response["result"]["fulfillment"]["speech"]
try:
intent,action,entitiy = get_intent_action_entity(response)
except KeyError:
pass
print (intent,entitiy,action)
if action:
try:
methodToCall = getattr(action_methods,action)
outcome = methodToCall(entitiy)
reply_message = format_message(action,reply_message,outcome)
except AttributeError:
pass
print (reply_message)
return jsonify({"status":"success","response":reply_message})
app.config["DEBUG"] = True
if __name__ == "__main__":
app.run(port=8000)