How to use the botbuilder-dialogs.DialogSet function in botbuilder-dialogs

To help you get started, we’ve selected a few botbuilder-dialogs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github howdyai / botkit / packages / botkit / lib / core.js View on Github external
this.addDep('booted');
        debug('Booting Botkit ', this.version);
        if (!this._config.storage) {
            // Set up temporary storage for dialog state.
            this.storage = new botbuilder_1.MemoryStorage();
            console.warn('** Your bot is using memory storage and will forget everything when it reboots!');
            console.warn('** To preserve dialog state, specify a storage adapter in your Botkit config:');
            console.warn('** const controller = new Botkit({storage: myStorageAdapter});');
        }
        else {
            this.storage = this._config.storage;
        }
        this.conversationState = new conversationState_1.BotkitConversationState(this.storage);
        // TODO: dialogState propertyname should maybe be settable to avoid collision
        const dialogState = this.conversationState.createProperty('dialogState');
        this.dialogSet = new botbuilder_dialogs_1.DialogSet(dialogState);
        if (!this._config.webserver) {
            // Create HTTP server
            this.addDep('webserver');
            this.webserver = express();
            this.webserver.use(bodyParser.json());
            this.webserver.use(bodyParser.urlencoded({ extended: true }));
            this.http = http.createServer(this.webserver);
            hbs.registerPartials(this.PATH + '/../views/partials');
            hbs.localsAsTemplateData(this.webserver);
            // hbs.handlebars.registerHelper('raw-helper', function(options) {
            //     return options.fn();
            // });
            // From https://stackoverflow.com/questions/10232574/handlebars-js-parse-object-instead-of-object-object
            hbs.registerHelper('json', function (context) {
                return JSON.stringify(context);
            });
github microsoft / botbuilder-js / samples / dialogs / oauthbot-ts / lib / app.js View on Github external
// Create server
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
    console.log(`${server.name} listening to ${server.url}`);
});
// Create adapter
const adapter = new botbuilder_1.BotFrameworkAdapter({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});
const connectionName = process.env.CONNECTION_NAME;
// Add conversation state middleware
const conversationState = new botbuilder_1.ConversationState(new botbuilder_1.MemoryStorage());
adapter.use(conversationState);
// Create empty dialog set
const dialogs = new botbuilder_dialogs_1.DialogSet();
// Listen for incoming requests 
server.post('/api/messages', (req, res) => {
    // Route received request to adapter for processing
    adapter.processActivity(req, res, (context) => __awaiter(this, void 0, void 0, function* () {
        // Use this command to have the emulator send mocked tokens to the bot rather than authenticating
        // adapter.emulateOAuthCards(context, true);
        if (context.activity.type === 'message') {
            if (context.activity.text === 'signout') {
                yield adapter.signOutUser(context, connectionName);
                yield context.sendActivity("You are now signed out.");
            }
            else {
                // Create dialog context and continue executing the "current" dialog, if any.
                const state = conversationState.get(context);
                const dc = dialogs.createContext(context, state);
                yield dc.continueDialog();
github microsoft / botbuilder-js / samples / 10. sidecarDebugging / lib / bot.js View on Github external
constructor(conversationState) {
        this.conversationState = conversationState;
        // Create a property used to store dialog state.
        // See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
        this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
        // Create a dialog set to include the dialogs used by this bot.
        this.dialogs = new botbuilder_dialogs_1.DialogSet(this.dialogState);
        // Set up a series of questions for collecting the user's name.
        const fullnameSlots = [
            new slotDetails_1.SlotDetails('first', 'text', 'Please enter your first name.'),
            new slotDetails_1.SlotDetails('last', 'text', 'Please enter your last name.')
        ];
        // Set up a series of questions to collect a street address.
        const addressSlots = [
            new slotDetails_1.SlotDetails('street', 'text', 'Please enter your street address.'),
            new slotDetails_1.SlotDetails('city', 'text', 'Please enter the city.'),
            new slotDetails_1.SlotDetails('zip', 'text', 'Please enter your zipcode.')
        ];
        // Link the questions together into a parent group that contains references
        // to both the fullname and address questions defined above.
        const slots = [
            new slotDetails_1.SlotDetails('fullname', 'fullname'),
            new slotDetails_1.SlotDetails('age', 'number', 'Please enter your age.'),
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 09.message-routing / bot.js View on Github external
constructor(conversationState, userState, botConfig) {
        if (!conversationState) throw new Error('Missing parameter.  conversationState is required');
        if (!userState) throw new Error('Missing parameter.  userState is required');
        if (!botConfig) throw new Error('Missing parameter.  botConfig is required');

        // Create the property accessors for user and conversation state
        this.greetingStateAccessor = userState.createProperty(GREETING_STATE_PROPERTY);
        this.dialogState = conversationState.createProperty(DIALOG_STATE_PROPERTY);

        // Create top-level dialog(s)
        this.dialogs = new DialogSet(this.dialogState);
        this.dialogs.add(new GreetingDialog(GREETING_DIALOG, this.greetingStateAccessor, userState));
        this.conversationState = conversationState;
        this.userState = userState;
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 05.multi-turn-prompt / bot.js View on Github external
constructor(conversationState, userState) {
        // Create a new state accessor property. See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
        this.conversationState = conversationState;
        this.userState = userState;

        this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);

        this.userProfile = this.userState.createProperty(USER_PROFILE_PROPERTY);

        this.dialogs = new DialogSet(this.dialogState);

        // Add prompts that will be used by the main dialogs.
        this.dialogs.add(new TextPrompt(NAME_PROMPT));
        this.dialogs.add(new ChoicePrompt(CONFIRM_PROMPT));
        this.dialogs.add(new NumberPrompt(AGE_PROMPT, async (prompt) => {
            if (prompt.recognized.succeeded) {
                if (prompt.recognized.value <= 0) {
                    await prompt.context.sendActivity(`Your age can't be less than zero.`);
                    return false;
                } else {
                    return true;
                }
            }

            return false;
        }));
github microsoft / botbuilder-js / samples / dialogs / alarmbot-ts / src / bot.ts View on Github external
constructor(conversationState: ConversationState, userState: UserState) {
        // Define state properties
        this.alarmsProperty = userState.createProperty(ALARMS_PROPERTY);
        this.dialogStateProperty = conversationState.createProperty(DIALOG_STATE_PROPERTY);

        // Create top level dialogs
        this.dialogs = new DialogSet(this.dialogStateProperty);
        this.dialogs.add(new AddAlarmDialog(ADD_ALARM_DIALOG, this.alarmsProperty));
        this.dialogs.add(new DeleteAlarmDialog(DELETE_ALARM_DIALOG, this.alarmsProperty));
        this.dialogs.add(new ShowAlarmsDialog(SHOW_ALARMS_DIALOG, this.alarmsProperty));
    }
github microsoft / botbuilder-js / samples / dialogs / list-ts / lib / app.js View on Github external
if (utterance.includes('images')) {
                const startImage = Math.floor(Math.random() * 100);
                await dc.endAll().begin('imageList', { filter: { start: startImage } });
            }
            else {
                await dc.continueDialog();
                // Check to see if anyone replied.
                if (!context.responded) {
                    await context.sendActivity(`To show a list send a reply with "images".`);
                }
            }
        }
    });
});
const listControl_1 = require("./listControl");
const dialogs = new botbuilder_dialogs_1.DialogSet();
dialogs.add('imageList', new listControl_1.ListControl((dc, filter, continueToken) => {
    // Render a page of images to hero cards 
    const page = typeof continueToken === 'number' ? continueToken : 0;
    const cards = [];
    for (let i = 0; i < 10; i++) {
        const imageNum = i + (page * 10) + 1;
        const card = botbuilder_1.CardFactory.heroCard(`Image ${imageNum}`, [`https://picsum.photos/100/100/?image=${filter.start + imageNum}`]);
        cards.push(card);
    }
    // Render cards to user as a carousel
    const activity = botbuilder_1.MessageFactory.carousel(cards);
    // Return page of results
    return { results: activity, continueToken: page < 4 ? page + 1 : undefined };
}));
github microsoft / BotBuilder-Samples / MigrationV3V4 / Node / core-MultiDialogs-v4 / dialogs / main.js View on Github external
async run(turnContext, accessor) {
        const dialogSet = new DialogSet(accessor);
        dialogSet.add(this);

        const dialogContext = await dialogSet.createContext(turnContext);
        const results = await dialogContext.continueDialog();
        if (results.status === DialogTurnStatus.empty) {
            await dialogContext.beginDialog(this.id);
        }
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 06.using-cards / dialogs / mainDialog.js View on Github external
async run(turnContext, accessor) {
        const dialogSet = new DialogSet(accessor);
        dialogSet.add(this);

        const dialogContext = await dialogSet.createContext(turnContext);
        const results = await dialogContext.continueDialog();
        if (results.status === DialogTurnStatus.empty) {
            await dialogContext.beginDialog(this.id);
        }
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 11.qnamaker / dialogs / rootDialog.js View on Github external
async run(context, accessor) {
        const dialogSet = new DialogSet(accessor);
        dialogSet.add(this);

        const dialogContext = await dialogSet.createContext(context);
        const results = await dialogContext.continueDialog();
        if (results.status === DialogTurnStatus.empty) {
            await dialogContext.beginDialog(this.id);
        }
    }