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/stevengum97/LoopPrompt_Example | |
| //Demonstration of session.replaceDialog() to incorporate a looping aspect when delivering an unspecified number of Prompts to the user. | |
| var builder = require('botbuilder'); | |
| var restify = require('restify'); | |
| var server = restify.createServer(); | |
| server.listen(process.env.port || process.env.PORT || 3978, function () { | |
| console.log('%s listening to %s', server.name, server.url); |
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
| https://github.com/pveller/ecommerce-chatbot |
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
| // Anytime the major version is incremented any existing conversations will be restarted. | |
| bot.use(builder.Middleware.dialogVersion({ version: 1.0, resetCommand: /^reset/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
| //See: https://github.com/DanielEgan/botstarter | |
| SAMPLE CODE FROM: botstarter/server.js | |
| ... | |
| let fs = require('fs'); | |
| let path = require('path'); | |
| let readdir = require('readdir-enhanced'); | |
| ... | |
| let bot = new builder.UniversalBot(connector, function (session) { | |
| session.beginDialog('/default'); |
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/issues/2456 | |
| // Install a custom recognizer to look for user saying 'help' or 'goodbye'. | |
| // Set the recognizeOrder to 'series', use RegExpRecognizers and the LuisRecognizer | |
| // Using 'series' stops the service checking Luis if the Hello or Hi recognizers return a positive | |
| // Without 'series', all of the recognizers including Luis are checked | |
| var recognizer = new builder.LuisRecognizer(model); | |
| var regExHi = new builder.RegExpRecognizer('Hi', /^hi$/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
| // See: http://www.pveller.com/smarter-conversations-part-2-open-dialogs/#Trigger-Actions | |
| // You can define your own dialog’s behaviors by overwriting begin, replyReceived, and even recognize on your dialogs: | |
| bot.dialog('custom', Object.assign(new builder.Dialog(), { | |
| begin: (session) => { | |
| session.send('I am built custom'); | |
| }, | |
| replyReceived: (session) => { | |
| 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
| //See: https://stackoverflow.com/questions/40437773/how-do-i-define-the-default-behaviors-of-a-bot-in-node-js | |
| To change the default error messages, we can simply add a file called 'BotBuilder.json' inside the folder | |
| BotProject/locale/<languageCode>/BotBuilder.json | |
| So the file contains the text message which override the default error as follows: | |
| { | |
| "default_text": "I didn't understand. Please try again.", | |
| "default_number": "I didn't recognize that as a number. Please enter a number.", |
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
| HELPERS.JS | |
| module.exports = function () { | |
| /** | |
| * Returns a random integer between min (inclusive) and max (inclusive) | |
| * Using Math.round() will give you a non-uniform distribution! | |
| */ | |
| global.getRandomInt = function (min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; |
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://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-dialog-actions | |
| // Order dinner. | |
| bot.dialog('orderDinner', [ | |
| //...waterfall steps... | |
| ]) | |
| // Once triggered, will restart the dialog. | |
| .reloadAction('startOver', 'Ok, starting over.', { | |
| matches: /^start over$/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
| // See:https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/core-MultiDialogs/README.md | |
| // also: https://github.com/Microsoft/BotBuilder/issues/1710 | |
| Handling dialog errors | |
| Errors can be signaled from child dialogs using session.error. This will signal the error via an on('error', err) event, for both the bot object and the session object. In flights.js we are signalling an error which the parent dialog handles using session.on('error'), as shown in app.js: | |
| session.on('error', function (err) { | |
| session.send('Failed with message: %s', err.message); | |
| session.endDialog(); |