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
// Setup help system | |
bot.recognizer(new builder.RegExpRecognizer('HelpIntent', /^(help|options)/i)); | |
bot.dialog('helpDialog', function (session, args) { | |
switch (args.action) { | |
default: | |
// args.action is '*:/help' indicating the triggerAction() was matched | |
session.endDialog("You can say 'flip a coin' or 'roll dice'."); | |
break; | |
case 'flipCoinHelp': | |
session.endDialog("Say 'heads' or 'tails'."); |
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/Microsoft/BotBuilder/blob/master/Node/examples/basics-help/apps.js | |
function switchTasks(session, args, next, alreadyActiveMessage) { | |
// Check to see if we're already active. | |
// - We're assuming that we're being called from a triggerAction() some | |
// args.action is the fully qualified dialog ID. | |
var stack = session.dialogStack(); | |
if (builder.Session.findDialogStackEntry(stack, args.action) >= 0) { | |
session.send(alreadyActiveMessage); | |
} else { | |
// Clear stack and switch tasks |
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. First example | |
// https://github.com/Microsoft/BotBuilder/blob/master/Node/examples/basics-logging/app.js | |
// Install logging middleware | |
bot.use({ | |
botbuilder: function (session, next) { | |
if (/^log on/i.test(session.message.text)) { | |
session.userData.isLogging = true; | |
session.send('Logging is now turned on'); | |
} else if (/^log off/i.test(session.message.text)) { | |
session.userData.isLogging = false; |
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/Microsoft/BotBuilder/blob/master/Node/examples/basics-loops/app.js | |
//This Bot demonstrates how to use session.replaceDialog() to create a simple | |
// loop that dyanmically populates a form. | |
// Add Q&A dialog | |
bot.dialog('q&aDialog', [ | |
function (session, args) { | |
// Save previous state (create on first call) | |
session.dialogData.index = args ? args.index : 0; | |
session.dialogData.form = args ? args.form : {}; |
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/Microsoft/BotBuilder/blob/master/Node/examples/basics-menus/app.js | |
//This Bot demonstrates how to create a simple menu for a bot. We've also added a | |
//reloadAction() to the menus dialog which lets you return to the menu from any | |
//child dialog by simply saying "menu" or "back". | |
bot.dialog('rootMenu', [ | |
function (session) { | |
builder.Prompts.choice(session, "Choose an option:", 'Flip A Coin|Roll Dice|Magic 8-Ball|Quit'); | |
}, | |
function (session, results) { |
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/Microsoft/BotBuilder-Samples/tree/master/Node/demo-ContosoFlowers | |
Bot Libraries for Creating Reusable Dialogs | |
Libraries of reusable parts can be developed by creating a new Library instance and adding dialogs just as you would to a bot. | |
Your library should have a unique name that corresponds to either your libraries website or NPM module name. | |
Bots can then reuse your library by simply adding your parts Library instance to their bot using UniversalBot.library(). | |
To invoke dialogs within the bot, we use session.beginDialog() with a fully qualified dialog id in the form of ':'. | |
E.g.: To start the shopping's experience root dialog we use session.beginDialog('shop:/'). |
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/Microsoft/BotBuilder-Samples/tree/master/Node/demo-ContosoFlowers | |
This is how you could package an email validation: | |
var EmailRegex = new RegExp(/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/); | |
var lib = new builder.Library('validators'); | |
lib.dialog('email', | |
new builder.IntentDialog() |
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 welcomeCard = new builder.HeroCard(session) | |
.title('welcome_title') | |
.subtitle('welcome_subtitle') | |
.images([ | |
new builder.CardImage(session) | |
.url('https://placeholdit.imgix.net/~text?txtsize=56&txt=Contoso%20Flowers&w=640&h=330') | |
.alt('contoso_flowers') | |
]) | |
.buttons([ | |
builder.CardAction.imBack(session, session.gettext(MainOptions.Shop), MainOptions.Shop), |
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'); | |
var rp = require('request-promise'); | |
var azure = require('botbuilder-azure'); | |
var Request = require('tedious').Request; | |
var Connection = require('tedious').Connection; |
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
function clearData(session) { | |
var name = session.userData.myName; | |
var email = session.userData.myEmail; | |
session.userData = {}; | |
session.userData.myName = name; | |
session.userData.myEmail = email; | |
} |
OlderNewer