Last active
July 11, 2016 19:44
-
-
Save DirkSonguer/b0dc43e4054cfeb2229d6ca655f70a26 to your computer and use it in GitHub Desktop.
Gist with example bot for the MS Bot Framework, used to showcase problem between Mac (command emulator) and Windows (GUI emulator). See https://postimg.org/image/ru01yqfdz/ for output.
This file contains 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
// include restify server | |
var restify = require('restify'); | |
// include ms botbuilder sdk | |
var builder = require('botbuilder'); | |
// setup restify server | |
var server = restify.createServer(); | |
server.listen(3798, function () { | |
console.log('%s listening to %s', server.name, server.url); | |
}); | |
var connector = new builder.ChatConnector({ | |
// WARNING: activate this for production! | |
// appId: process.env.MICROSOFT_APP_ID, | |
// appPassword: process.env.MICROSOFT_APP_PASSWORD | |
}); | |
// create a universal bot based on the connector | |
var bot = new builder.UniversalBot(connector); | |
// this is the endpoint you need to define in yout bot settings | |
server.post('/api/messages', connector.listen()); | |
bot.dialog('/', [ | |
function (session, args, next) { | |
console.log("1: " + session.userData.name); | |
if (!session.userData.name) { | |
console.log("2"); | |
session.beginDialog('/profile'); | |
} else { | |
console.log("3"); | |
next(); | |
} | |
}, | |
function (session, results) { | |
console.log("4"); | |
session.send('Hello %s!', session.userData.name); | |
} | |
]); | |
bot.dialog('/profile', [ | |
function (session) { | |
console.log("5"); | |
builder.Prompts.text(session, 'Hi! What is your name?'); | |
}, | |
function (session, results) { | |
console.log("6"); | |
session.userData.name = results.response; | |
console.log("7" + session.userData); | |
session.endDialogWithResult(results.response); | |
} | |
]); | |
server.get(/.*/, restify.serveStatic({ | |
'directory': '.', | |
'default': 'index.html' | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment