Last active
August 10, 2017 11:45
-
-
Save jazzedge/7e350ebf47369ba82017cdc77226c947 to your computer and use it in GitHub Desktop.
Bot libraries #1
This file contains 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:/'). | |
// /bot/dialogs/shop.js | |
var lib = new builder.Library('shop'); | |
lib.dialog('/', [ | |
function (session) { | |
// Ask for delivery address using 'address' library | |
session.beginDialog('address:/', | |
{ | |
promptMessage: session.gettext('provide_delivery_address', session.message.user.name || session.gettext('default_user_name')) | |
}); | |
}, | |
function (session, args) { | |
// Retrieve address, continue to shop | |
session.dialogData.recipientAddress = args.address; | |
session.beginDialog('product-selection:/'); | |
}, | |
// ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment