npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wenyluo/botbuilder-dialogs

v1.0.1

Published

A dialog stack based conversation manager for Microsoft BotBuilder.

Downloads

36

Readme

A dialog stack based conversation manager for Microsoft BotBuilder.

Installing

To add the preview version of this package to your bot be sure include the @preview tag:

npm install --save botbuilder-dialogs@preview

While this package is in preview it's possible for updates to include build breaks. To avoid having any updates break your bot it's recommended that you update the dependency table of your bots package.json file to lock down the specific version of the package you're using:

{
    "dependencies": {
        "botbuilder": "4.0.0-preview1.2",
        "botbuilder-dialogs": "4.0.0-preview1.2"
    }
}

What's included?

This module includes a system for managing multi-turn conversations within a Microsoft Botbuilder app, including tools for creating and managing dialog systems, a means for creating custom interoperable dialog systems, and a series of useful prompts that provide type checking and validation of input.

Use

After adding the module to your application, modify your app's code to import the multi-turn dialog management capabilities. Near your other import and require statements, add:

// Import some of the capabities from the module. 
const { DialogSet, WaterfallDialog } = require("botbuilder-dialogs");

Then, create one or more DialogSet objects to manage the dialogs used in your bot. A DialogSet is used to collect and execute dialogs. A bot may have more than one DialogSet, which can be used to group dialogs logically and avoid name collisions.

Then, create one or more dialogs and add them to the DialogSet. Use the WaterfallDialog class to construct dialogs defined by a series of functions for sending and receiving input that will be executed in order. More sophisticated multi-dialog sets can be created using the ComponentDialog class, which has many of the capabilities of a DialogSet, but behaves and can be called like a single dialog.

// Set up a storage system that will capture the conversation state.
const storage = new MemoryStorage();
const convoState = new ConversationState(storage);

// Define a property associated with the conversation state.
const dialogState = convoState.createProperty('dialogState');

// Initialize a DialogSet, passing in a property used to capture state.
const dialogs = new DialogSet(dialogState);

// Each dialog is identified by a unique name used to invoke the dialog later.
const DIALOG_ONE = 'dialog_identifier_value';

// Add a dialog. Use the included WaterfallDialog type, or build your own
// by subclassing from the Dialog class.
dialogs.add(new WaterfallDialog(DIALOG_ONE, [
    async (step) => {
        // access user input from previous step
        var last_step_answer = step.result;

        // send a message to the user
        await step.context.sendActivity('Send a reply');

        // continue to the next step
        return await step.next();

        // OR end
        // return await step.endDialog();
    },
    step2fn,
    step3fn,
    ...,
    stepNfn
]));

Finally, from somewhere in your bot's code, invoke your dialog by name:

// Receive and process incoming events into TurnContext objects in the normal way
adapter.processActivity(req, res, async (turnContext) => {
    // Create a DialogContext object from the incoming TurnContext
    const dc = await dialogs.createContext(turnContext);

    // ...evaluate message and do other bot logic...

    // If the bot hasn't yet responded, try to continue any active dialog
    if (!turnContext.responded) {
        const status = await dc.continueDialog();
    }

    // Invoke the dialog we created above.
    if (!turnContext.responded) {
        await dc.beginDialog(DIALOG_ONE);
    }
});

Learn More

Prompts This module contains several types of built-in prompt that can be used to create dialogs that capture and validate specific data types like dates, numbers and multiple-choice answers.

DialogSet DialogSet is a container for multiple dialogs. Once added to a DialogSet, dialogs can be called and interlinked.

WaterfallDialog WaterfallDialogs execute a series of step functions in order, passing the resulting user input from each steo into the next step's function.

ComponentDialog ComponentDialogs are containers that encapsulate multiple sub-dialogs, but can be invoked like normal dialogs. This is useful for re-usable dialogs, or creating multiple dialogs with similarly named sub-dialogs that would otherwise collide.