7/8/2017 - 1:45 PM

Bot libraries #1

Bot libraries #1

// 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
                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;
    // ...