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
| // See: https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/core-MultiDialogs/README.md | |
| //Requires promises (bluebird) et.al. | |
| Inevitably, you're going to want to make some asynchronous network call to retrieve data and then send those results to the user using the session object. This is completely fine but there are a few best practices you'll want to follow. | |
| Use session.send within your callback or event handler. | |
| Do not call session.endDialog() immediately after starting the asynchronous call; | |
| Instead call session.endDialog() from within your callback or event handler. | |
| Check out hotels.js where we are calling an asynchronous method that returns a Promise. Our fulfill method calls session.send() and is also responsible for calling session.endDialog(). |
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
| //This waterfall dialog shows how to wait until the content is returned and .then move onto the next part of the waterfall. | |
| //It also shows how to catch erors | |
| bot.dialog('synch', [ | |
| function (session, results, next) { | |
| session.sendTyping(); | |
| html = getContent('https://api.tfl.gov.uk/Line/Mode/tube/Status?detail=true&app_id=...') | |
| .then((html) => { | |
| session.send(html); | |
| next(); | |
| }) |
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
| // Calculates the maximum depth of a JSON object. You must pass the string before converting it to JSON! | |
| function getDepth(obj) { //Pass a string, not a JSON obj | |
| var i = 0; | |
| var depth = 0; | |
| var maxDepth = 0; | |
| while (i < obj.length) | |
| { | |
| switch (obj.substr(i,1)) { | |
| case "{": | |
| depth++; |
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
| // This code has been specialised to work only for the API https://api.tfl.gov.uk/Line/Mode/tube/Status?detail=true | |
| // Requires JSON to be passed in as (o). Convert a string to JSON with: var htmlJSON = JSON.parse(html); | |
| var arr = []; | |
| var previousKey = ""; | |
| var parentKey = ""; | |
| function traverseJSON (o) { | |
| for (var i in o) { | |
| if(typeof (o[i]) =='object') { | |
| //console.log('key : ' + i + ', value is an object'+ o[i]); |
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
| 'use strict'; | |
| var myData = []; | |
| // w ww. j a va 2 s. c o m | |
| myData.push(1); // add at the end | |
| console.log(myData); // prints [1] | |
| myData.unshift(2); // add to the top | |
| console.log(myData); // prints [2,1] | |
| // Arrays are zero index based: |
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
| //01. Configure Blob storage | |
| var builder = require('botbuilder'); | |
| var azure = require('azure-storage'); | |
| var request = require('request').defaults({ encoding: null }); | |
| var accessKey = 'XdU6cKUYRT ... 5Bf3yzgjY1JKIg=='; | |
| var storageAccount = 'roccoblob01'; | |
| var containerName = 'roccoblobcontainer1'; |
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
| // 01. Root Dialog | |
| var bot = new builder.UniversalBot(connector, | |
| function (session) { | |
| // echo the user's message | |
| session.send("You said: %s", session.message.text); | |
| } | |
| ); | |
| // 01. Root Dialog | |
| var bot = new builder.UniversalBot(connector, [ |
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 locationDialog = require('botbuilder-location'); //Bing Maps | |
| bot.library(locationDialog.createLibrary(process.env.BING_MAPS_KEY)); | |
| //Bing Maps Demo | |
| bot.dialog("bingmap", [ | |
| function (session) { | |
| var options = { | |
| prompt: "Where should I ship your order?", | |
| useNativeControl: true, |
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 intents = new builder.IntentDialog(); | |
| bot.dialog('/', intents); | |
| intents.matches(/^Hi/i, [ | |
| function(session) | |
| { | |
| builder.Prompts.text(session, 'Hi there! How are you today?'); | |
| }, | |
| function(session, results) | |
| { | |
| session.send('%s! How can I help you?', results.response); |
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
| 'use strict'; | |
| // 01. Include required files | |
| require('dotenv-extended').load(); | |
| var restify = require('restify'); | |
| var builder = require('botbuilder'); | |
| // --------------------------------------------------------------------------------------------------------------------- | |
| // 02. Setup Restify Server | |
| var server = restify.createServer(); | |
| // 03. Configure listen for messages |