Robbie
Robbie

Reputation: 477

dynamic prompt choices in bot-framework v4 (node.js)

I've got a prompt for an SMS bot in which the user can make multiple choices. I'm looking for a pattern for a ChoicePrompt that allows me to do this:

I'd like to avoid creating a new prompt w/switch cases for each answer tier, as this pattern needs to be implemented in a lot of places...

Example:

bot: User, what do you do to relax?

  1. Exercise
  2. Read a book
  3. Nothing

user: Exercise

bot: Exercise, cool. What else?

  1. Read a book
  2. Nothing else

user: Read a book

bot: OK, you've done everything so we're moving on!

Upvotes: 1

Views: 969

Answers (1)

ShuffleModeON
ShuffleModeON

Reputation: 26

The botframework don't have a ListPrompt that I can see, at least for v4. They do however, have Suggested Actions you can use for this!!! The Botbuilder-Samples repo has a Suggested Action sample that shows a list of three colors:

async onTurn(turnContext) {
    // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
    if (turnContext.activity.type === ActivityTypes.Message) {
        const text = turnContext.activity.text;

        // Create an array with the valid color options.
        const validColors = ['Red', 'Blue', 'Yellow'];

        // If the `text` is in the Array, a valid color was selected and send agreement.
        if (validColors.includes(text)) {
            await turnContext.sendActivity(`I agree, ${ text } is the best color.`);
        } else {
            await turnContext.sendActivity('Please select a color.');
        }

        // After the bot has responded send the suggested actions.
        await this.sendSuggestedActions(turnContext);
    } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
        await this.sendWelcomeMessage(turnContext);
    } else {
        await turnContext.sendActivity(`[${ turnContext.activity.type } event detected.]`);
    }
}

An option would be to programatically create the array (in the example above, it's "const validColors") and if the reply is in the list of colors, recreate the array however you want without the chosen option.

Upvotes: 1

Related Questions