Last active
June 9, 2017 22:03
-
-
Save nwhitmont/025e594dc785d196ccae5267f16451c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = require('botbuilder'); | |
var restify = require('restify'); | |
//Server setup | |
var server = restify.createServer(); | |
server.listen(process.env.port || process.env.PORT || 3978, function () { | |
console.log('%s listening to %s', server.name, server.url); | |
}); | |
//Get secrets from server environment | |
var connector = new builder.ChatConnector({ appId: process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD }); | |
//Create chat bot | |
var bot = new builder.UniversalBot(connector); | |
//Handle bot framework messages | |
server.post('/api/messages', connector.listen()); | |
var colorOptions = [ | |
'red', | |
'orange', | |
'yellow', | |
'green', | |
'blue', | |
'white', | |
'black', | |
'grey', | |
'pink', | |
'purple' | |
]; | |
bot.dialog('/', [ | |
function (session) { | |
session.userData.ballColors = []; | |
session.send('Hello'); | |
session.send('Welcome to golf ball color picker demo'); | |
builder | |
.Prompts | |
.number(session, 'Enter the number of balls for your basket (1-5):'); | |
}, | |
function (session, results) { | |
session.send(`You picked: ${results.response} ball(s)`); | |
session.beginDialog("pickcolor", { amount: results.response, current: 1 }); | |
}, | |
function (session, results) { | |
console.log(session.userData.ballColors); | |
session.endDialog(`You have selected the following ball colors: ${session.userData.ballColors}`) | |
} | |
]); | |
bot.dialog('pickcolor', [ | |
function (session, args, next) { | |
var amount = session.dialogData.amount = args.amount; | |
var current = session.dialogData.current = args.current; | |
builder.Prompts.choice(session, 'Pick color nr ' + current, colorOptions) | |
}, | |
function (session, results, next) { | |
var selectedColor = results.response.entity; | |
session.userData.ballColors.push(selectedColor); | |
session.send(`You picked: ${selectedColor}`); | |
next(); | |
}, | |
function (session, results, next) { | |
if (session.dialogData.current < session.dialogData.amount) { | |
session.replaceDialog('pickcolor', { amount: session.dialogData.amount, current: session.dialogData.current + 1 }) | |
} else { | |
session.endDialog(); | |
} | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment