-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
dateplanner.js
95 lines (84 loc) · 2.96 KB
/
dateplanner.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Example of using a dictionary to allow the user to choose from a pre-selected list of values in a custom slot type.
//
var chatskills = require('./lib/chatskills');
// Create a new skill.
var dateplanner = chatskills.add('dateplanner');
dateplanner.dictionary = { "yesNo": [ 'yes', 'no' ] };
dateplanner.intent('run', {
"slots": {},
"utterances": ["{to|} {run|start|go|launch}"]
}, function(req, res) {
var prompt = "What date would you like to book?";
res.say(prompt).reprompt(prompt).shouldEndSession(false);
}
);
// Example using the built-in slot type: AMAZON.DATE.
dateplanner.intent('getDate',{
"slots":{"Date":"AMAZON.DATE"}
,"utterances":["{-|Date}",
"book {-|Date}",
"I choose {-|Date}"]
},
function(req,res) {
// Store the date.
res.session('Date', req.slot('Date'));
res.say('What time will the event start?');
res.shouldEndSession(false);
}
);
// Example using the built-in slot type: AMAZON.TIME.
dateplanner.intent('getTime',{
"slots":{"Time":"AMAZON.TIME"}
,"utterances":["{-|Time}",
"at {-|Time}"]
},
function(req,res) {
// Store the time.
res.session('Time', req.slot('Time'));
res.say('How many guests will be attending?');
res.shouldEndSession(false);
}
);
// Example using the built-in slot type: AMAZON.NUMBER.
dateplanner.intent('getNumber',{
"slots":{"GuestCount":"AMAZON.NUMBER"}
,"utterances":["{-|GuestCount}",
"about {-|GuestCount}",
"{-|GuestCount} guests",
"{-|GuestCount} people",
"There will be {-|GuestCount} guests"]
},
function(req,res) {
// Store the guest count.
res.session('GuestCount', req.slot('GuestCount'));
if (req.session('Date') && req.session('Time')) {
res.say("Your event will be on " + req.session('Date') + " at " + req.session('Time') + " and you are inviting " + req.slot('GuestCount') + " guests. Is this correct?");
}
else {
// User has not provided all info yet.
res.say("You are inviting " + req.slot('GuestCount') + " guests. What date would you like to book?");
}
res.shouldEndSession(false);
}
);
dateplanner.intent('confirm', {
'slots': { "Confirm": "YESNO" },
'utterances': [ '{yesNo|Confirm}' ]
},
function(req, res) {
if (req.session('GuestCount') && req.session('Date')) {
if (req.slot('Confirm').toLowerCase() == 'yes') {
res.say("Great! Your event is successfully booked.").shouldEndSession(true);
}
else {
// User wants to start over.
res.say("What date would you like to book?").shouldEndSession(false);
}
}
else {
// User has not provided all info yet.
res.say("What date would you like to book?").shouldEndSession(false);
}
}
);