Permalink
Browse files

Added dateplanner example for built-in slot types: AMAZON.DATE and AM…

…AZON.NUMBER.
  • Loading branch information...
1 parent 215061d commit 6535574d4ef546f4863ca00070cf28c03856b6c5 @primaryobjects committed Oct 20, 2016
Showing with 75 additions and 1 deletion.
  1. +73 −0 dateplanner.js
  2. +2 −1 test.js
View
@@ -0,0 +1,73 @@
+//
+// 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":{"Booking":"AMAZON.DATE"}
+ ,"utterances":["{-|Booking}",
+ "book {-|Booking}",
+ "I choose {-|Booking}"]
+ },
+ function(req,res) {
+ // Store the date.
+ res.session('Date', req.slot('Booking'));
+
+ res.say("Ok, I've booked the date " + req.slot('Booking') + ' for your event. 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'));
+
+ res.say("Your event will be on " + req.slot('Date') + " and you are inviting " + req.session('GuestCount') + " guests. Is this correct?");
+ 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);
+ }
+ }
+);
View
@@ -19,8 +19,9 @@ require('./funny');
require('./horoscope');
require('./favoritecolor');
require('./pickfruit');
+require('./dateplanner');
-console.log('Welcome, here are some available commands to try:\nchatskills, ask hello to say hi\nchatskills, ask horoscope for Aries\nchatskills, ask funny to tell a joke\nchatskills, ask favoritecolor to run\nchatskills, ask pickfruit to run\n');
+console.log('Welcome, here are some available commands to try:\nchatskills, ask hello to say hi\nchatskills, ask horoscope for Aries\nchatskills, ask funny to tell a joke\nchatskills, ask favoritecolor to run\nchatskills, ask pickfruit to run\nchatskills, ask dateplanner to run\n');
// Example client.
var text = ' ';

0 comments on commit 6535574

Please sign in to comment.