-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.py
79 lines (58 loc) · 1.98 KB
/
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
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
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import json
try:
import apiai
except ImportError:
sys.path.append(
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
os.pardir,
os.pardir
)
)
import apiai
# demo agent acess token: e5dc21cab6df451c866bf5efacb40178
CLIENT_ACCESS_TOKEN = '23924058d57b46aa88f1babc72d53de0'
def main():
ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN)
while True:
print(u"> ", end=u"")
user_message = raw_input()
if user_message == u"exit":
break
request = ai.text_request()
request.query = user_message
response = json.loads(request.getresponse().read())
result = response['result']
action = result['action']
actionIncomplete = result.get('actionIncomplete', False)
print(u"< %s" % response['result']['fulfillment']['speech'])
if action == u"food":
print("-----------------")
print("We will use zomato api here")
if action is not None:
if action == u"send_message":
parameters = result['parameters']
text = parameters.get('text')
message_type = parameters.get('message_type')
parent = parameters.get('parent')
print (
'text: %s, message_type: %s, parent: %s' %
(
text if text else "null",
message_type if message_type else "null",
parent if parent else "null"
)
)
if not actionIncomplete:
print(u"...Sending Message...")
break
elif action is "food":
print("--------------------")
print(u"< %s" % response['result']['fulfillment']['speech'])
if __name__ == '__main__':
main()