-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
68 lines (49 loc) · 1.48 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pprint
from flask import Flask, request, make_response, jsonify
from q_and_a import QandAHandler
handler = QandAHandler()
app = Flask(__name__)
pp = pprint.PrettyPrinter()
def dflow_response():
req = request.get_json(force=True)
pp.pprint(req)
action = req['queryResult']['intent']['displayName']
if action == 'Ask Question Intent':
fulfill_text = handler.supply_question()
elif action == 'Evaluate Response':
print("eval")
user_input = req['queryResult']['queryText']
fulfill_text = handler.evaluate_response(user_input)
print("fulfill")
elif action == 'test intent':
fulfill_text = 'hi'
print(fulfill_text)
return {
"fulfillmentText": fulfill_text,
"payload": {
"google": {
"expectUserResponse": True,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": fulfill_text
}
}
]
}
}
}
}
# Called when dialogflow tries to access our server
@app.route('/dialogflow', methods=['GET', 'POST'])
def dialogflow():
return make_response(jsonify(dflow_response()))
# Just for testing server is up in browser
@app.route('/')
def index():
return 'Hi'
def main():
app.run(debug=True)
if __name__ == '__main__':
main()