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
| // 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
| 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
| function clearData(session) { | |
| var name = session.userData.myName; | |
| var email = session.userData.myEmail; | |
| session.userData = {}; | |
| session.userData.myName = name; | |
| session.userData.myEmail = email; | |
| } |
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
| 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'); |
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
| //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 }); |
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
| //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(); |
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
| 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"), |
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
| console.log("Channel:", session.message.address.channelId); |
OlderNewer