How to set up a prompt (Microsoft Botbuilder SDK)

Note

I am using Microsoft Botbuilder SDK node.js

with ES6 babel.

Problem

Based on this helpful StackOverflow post, https://stackoverflow.com/a/2424490 / ... , I'm trying to change the behavior of builder.Prompts.choice in the same way, so that I have more control over the retry prompt, instead of the default "I'm not understood. " However, when I try to follow this implementation pattern and apply it to builder.Prompts.choice, I just get the choice undefined

sent by the bot
, like this:

Screenshot Undefined Selection

code

// snippet showing how I call the choice function, where
// welcome_subtitle is a string, and menuOptions is an array of strings
builder.Prompts.choice(session, welcome_subtitle, menuOptions, {
    listStyle: builder.ListStyle.button
});

builder.Prompts.choice = (session, prompt, choices, options) => {
    let args = options || {};
    args.prompt = prompt || args.prompt;
    args.choices = choices || args.choices;

    args.retryPrompt = args.retryPrompt || args.prompt;
    session.beginDialog('BotBuilder:prompt-choice', args);
}

      

Desired behavior

I would expect the selection to appear if I just initialized args.choice

to choices || args.choices

, but that doesn't seem to be all that is needed.

Thanks for any help you can give.

+2


source to share


1 answer


In this case, passing to an array from strings

won't work as it looks like the invitation is expecting a list IChoice

.

builder.Prompts.choice = (session, prompt, choices, options) => {
    let args = options || {};
    args.prompt = prompt || args.prompt;
    args.choices = choices || args.choices;

    args.retryPrompt = args.retryPrompt || args.prompt;
    console.log(args);
    session.beginDialog('BotBuilder:prompt-choice', args);
}

bot.dialog('/', [
    (session, args) => {
        welcome_subtitle = 'Hello Stack Overflow!';
        menuOptions = [{value: '1st Choice'}, {value: '2nd Choice'}, '3rd Choice', '4th Choice'];
        builder.Prompts.choice(session, welcome_subtitle, menuOptions, {
            listStyle: builder.ListStyle.button
        });
    },
    (session, results) => {
        session.endDialog();
    }
]);

      



Here's a screenshot with the console.log(args)

inside builder.Prompts.choice

and an emulator displaying the first two options correctly, but not the last two:

enter image description here

+1


source







All Articles