Skip to content

Instantly share code, notes, and snippets.

View jazzedge's full-sized avatar

Rocco Labellarte jazzedge

View GitHub Profile
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 });
@jazzedge
jazzedge / gist:39e3271ce16c2084855efd5e9ae5c39f
Last active August 12, 2017 17:41
Bot - onSelectAction: trigger new dialog without clearing stack
bot.dialog('help', function (session, args, next) {
session.endDialog("I'm a virtual assistant that can help decide whether or not you require planning permission for a loft. <br/>Please say 'ok' to continue");
})
.triggerAction({
matches: /^help$/i,
onSelectAction: (session, args, next) => {
// Add the help dialog to the dialog stack
// (override the default behavior of replacing the stack)
session.beginDialog(args.action, args);
}
//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:45b61659d0442f1f6e67c40bdb0604d1
Last active July 28, 2017 16:27
Bot Simple waterfall example
bot.dialog('greetings', [
// Step 1
function (session, args, next) {
builder.Prompts.text(session, 'Hi! What is your name?');
},
// Step 2
function (session, args, next) {
session.endDialog('Hello %s!', args.response);
}
]);
@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:07c39f7414d05d0d069ca76ad4f943ac
Last active July 24, 2017 10:10
Bot - Action card displayed when new user joins conversation
//Dialog when user joins conversation
var cFirstRun = true;
bot.on('conversationUpdate', function (message) {
if (cFirstRun == true) {
cFirstRun = false;
var reply = new builder.Message()
.address(message.address) //Required
.text("This is Yaddop's Geography Chatbot")
.addAttachment({
contentUrl:"https://roccobot02gghwh4.blob.core.windows.net/images/chatbot1.jpg",
@jazzedge
jazzedge / gist:5b2ee2859f36ab45e5089ef747ca58d8
Created July 10, 2017 17:17
Bot Get channel ID (eg. emulator)
console.log("Channel:", session.message.address.channelId);
@jazzedge
jazzedge / gist:84ded7b463be66684c88ad3fca501c12
Last active July 28, 2017 17:01
Bot - Full Example: Synchronous remote file GET using promises
'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
// Call like this:
var r = randomInt(1,10);
//Display like this:
session.send ('Random n.'+ r); // Use the plus sign, not a comma.
// Generate a random integer between low and high
function randomInt (low, high) {
return Math.floor(Math.random() * (high - low) + low);
}