-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialogflow.py
More file actions
42 lines (33 loc) · 1.32 KB
/
Copy pathDialogflow.py
File metadata and controls
42 lines (33 loc) · 1.32 KB
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
import apiai,json
ai = apiai.ApiAI("760b8ea2538443cd9b464a579aeb044d")
while True:
print(u"> ", end=u"")
user_message = 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.get('action')
actionIncomplete = result.get('actionIncomplete', False)
res = (u"< %s" % response['result']['fulfillment']['speech'])
print (res)
# print(response)
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