Skip to content

Instantly share code, notes, and snippets.

View jazzedge's full-sized avatar

Rocco Labellarte jazzedge

View GitHub Profile
//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);
@jazzedge
jazzedge / gist:20c07a5e7adef90f6214c73a8a44b624
Created July 28, 2017 05:55
Bot - ECommmerce Chatbot by P Veller
https://github.com/pveller/ecommerce-chatbot
@jazzedge
jazzedge / gist:f90e176b6265c69032d60d063927e673
Created July 28, 2017 06:01
Bot - Restart conversation if a major upgrade of the dialog system has taken place
// Anytime the major version is incremented any existing conversations will be restarted.
bot.use(builder.Middleware.dialogVersion({ version: 1.0, resetCommand: /^reset/i }));
@jazzedge
jazzedge / gist:0eb9646e1a43bed62d1888e8639b2443
Last active July 28, 2017 11:38
Bot - Load Anonymous Dialogs, Recognizers, Events, Intents
//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');
@jazzedge
jazzedge / gist:23fc1e2665e253e659375d8f00a4c0dc
Last active July 28, 2017 11:37
Bot - Luis and Regex recognizers and intents together
// 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);
@jazzedge
jazzedge / gist:800936d1de7dd15b571df819bddfff5d
Created July 28, 2017 09:06
Bot - Override Dialog behaviours
// 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();
}
}));
@jazzedge
jazzedge / gist:b2d4b7958e05413806a6580645322c16
Created July 28, 2017 10:06
Bot - Set default error messages
//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.",
@jazzedge
jazzedge / gist:8e96542b22b3b55662c2d8f0e98f8824
Last active August 4, 2017 09:29
Bot - Random salutation #1
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;
@jazzedge
jazzedge / gist:6fd0d6090ae066f601f931a4e9bb829d
Last active July 28, 2017 10:14
Bot - Restart a dialog: reloadAction
//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
});
@jazzedge
jazzedge / gist:fa644548c5983e6c7fd8eda7ae252080
Last active July 28, 2017 10:52
Bot - Error Handling & Global Error Handling
// 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();