Skip to content

Instantly share code, notes, and snippets.

View jazzedge's full-sized avatar

Rocco Labellarte jazzedge

View GitHub Profile
// 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'.");
@jazzedge
jazzedge / gist:df3f81d58467e9a8c2337e6629ad97e9
Created July 8, 2017 13:21
Bot check if dialog already active
// 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
@jazzedge
jazzedge / gist:223937f6a242bc77cdba3d5130651336
Created July 8, 2017 13:27
Bot - choice menu and reload menu
// 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) {
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),
@jazzedge
jazzedge / gist:453e160fbf5d44d2124e68100bb5bbbd
Created July 10, 2017 08:08
Bot Clear UserData specific to the questions
function clearData(session) {
var name = session.userData.myName;
var email = session.userData.myEmail;
session.userData = {};
session.userData.myName = name;
session.userData.myEmail = email;
}
bot.dialog('email', [
function (session, results) {
builder.Prompts.text(session, 'What is your email address?');
},
function (session, results) {
var validEmail = helpers.isEmailAddress(results.response);
console.log('EMAIL VALIDATION: ', validEmail);
if (validEmail == false) {
session.say('That is not a valid email address.');
session.replaceDialog('email');
@jazzedge
jazzedge / gist:8c76bdc40c4cd2cc906f62765ede3278
Created July 10, 2017 08:11
Bot endConversation and reset all data
//End Conversation and clear all data (restart the conversation completely)
bot.dialog('reset', function (session) {
session.dialogData = {};
session.userData = {};
session.conversationData = {};
session.privateConversationData = {};
session.endConversation("End Conversation");
}).triggerAction({ matches: /^(exit)|(quit)|(goodbye)|(finish)|(stop)|(end)|(terminate)/i });
//DEMO-QNA2.JS
// Demonstrates use of the QnA Service
// Combines:
//https://stackoverflow.com/questions/42629688/begin-dialog-with-qna-maker-bot-framework-recognizer-node-js
//and
//https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/master/Node/samples/QnAMakerSimpleBot/app.js
'use strict';
// 01. Include required files
require('dotenv-extended').load();
@jazzedge
jazzedge / gist:1707c8382e62f307797cf558be784d6a
Created July 10, 2017 15:50
Bot - Prompt with buttons that disappear and re-prompt if answer not permitted
bot.dialog('/', [
function (session) {
var msg = new builder.Message(session)
.text("Thank you for expressing interest in our premium golf shirt! What color of shirt would you like?")
.suggestedActions(
builder.SuggestedActions.create(
session, [
builder.CardAction.imBack(session, "green", "green"),
builder.CardAction.imBack(session, "blue", "blue"),
@jazzedge
jazzedge / gist:5b2ee2859f36ab45e5089ef747ca58d8
Created July 10, 2017 17:17
Bot Get channel ID (eg. emulator)
console.log("Channel:", session.message.address.channelId);