Search code examples
javascriptbotframework

Am I incorrectly using PromptOptions?


I'm trying to create a ChoicePrompt for my chatbot, but for some reason I can't import the PromptOptions interface. When I try including it in the botbuilder-dialogs imports:

const { DialogSet, WaterfallDialog, ChoicePrompt, WaterfallStepContext, PromptOptions } = require('botbuilder-dialogs');

VS Code doesn't recognize it as being part of the package, and try using it when creating the prompt in the WaterfallStepContext:

async (step = new WaterfallStepContext()) => {
       const semOptions = ["Fall", "Winter", "Summer"];
       options = new PromptOptions({ 
              prompt: `What semester are you currently in, ${this.name}?`, 
              choices: semOptions 
       });
       return await step.prompt("semPrompt", options);
}

I get a unhandled error:

TypeError: PromptOptions is not a constructor

I reinstalled the latest version botbuilder-dialog package several times but to no avail. Can anyone offer any insight as to what I may be doing wrong?


Solution

  • PromptOptions, is an interface with configurable options you pass in the prompt. You don't need to 'construct' it via new PromptOptions.

    Wrt you question you could do something like:

    Add 'ChoiceFactory' utilities

    const { WaterfallDialog, ChoiceFactory, ChoiceFactory, ConfirmPrompt, TextPrompt } = require('botbuilder-dialogs');
    

    In your dialogs constructor you add the prompt and add it to the dialogSet:

     this.addDialog(new ChoicePrompt(CHOICE_PROMPT_NAME));
    
    

    In your dialogstep you call the prompt and pass the options

    
        async Step(stepContext) {
            const SEMOPTIONS = ['Fall', 'Winter', 'Summer'];
            return await stepContext.prompt(CHOICE_PROMPT_NAME, {
                prompt: `What semester are you currently in, ${this.name}?`,
                retryPrompt: 'Please select one of the options',
                choices: ChoiceFactory.toChoices(SEMOPTIONS),
                style: 5
            });
        }
    
    

    Btw: It seems you are using C# / Python classes in your Javascript code. The SDK documentation for JS is located here: