forked from llSourcell/API_Chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
49 lines (37 loc) · 1.11 KB
/
demo.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
from api.ai import Agent
import json
#initialize the agent
agent = Agent(
'<subscription-key>',
'<client-access-token>',
'<developer-access-token>',
)
# actions defined in the API.AI console that fire locally when an intent is
# recognized
def saveType(flowerType):
print 'do something here'
def saveColor(color):
print 'do something here'
def createOrder(address):
print 'do something here'
def main():
user_input = ''
#loop the queries to API.AI so we can have a conversation client-side
while user_input != 'exit':
#parse the user input
user_input = raw_input("me: ")
#query the console with the user input, retrieve the response
response = agent.query(user_input)
#parse the response
result = response['result']
fulfillment = result['fulfillment']
print 'bot: ' + fulfillment['speech']
#if an action is deteted, fire the appropriate function
if result['action'] == 'saveFlowerType':
saveType(user_input)
if result['action'] == 'saveColor':
saveColor(user_input)
if result['action'] == 'createOrder':
createOrder(user_input)
if __name__ == "__main__":
main()