botframework choice invalid response typed

I am using nodejs SDK for creating my bot with MSFT botframework. The code snippet is as follows:

function(session, args, next){
builder.Prompts.choice(session, "Please select one of the options:", ['AAA', 'BBB','CCC'], {retryPrompt: "Invalid choice, Please pick below listed choices",
            listStyle: builder.ListStyle.button,
            maxRetries: 1
            });
},
function(session,results){
    if (results.response) {
        //Do something
    }
}

I have 2 questions:

  1. I would like to navigate to a different dialog Flow in case the user types anything other then the options("AAA","BBB","CCC"). Is that possible?

  2. I would like to change the retryPrompt everytime lets say pick the utterances from a list. Is that possible?

Upvotes: 0

Views: 108

Answers (2)

Gary Liu
Gary Liu

Reputation: 13918

I would like to navigate to a different dialog Flow in case the user types anything other then the options("AAA","BBB","CCC"). Is that possible?

Yes, it's possible. You can define several dialogs with required waterfall steps related to the choices. Like:

bot.dialog('AAA',[...])

And leverage replaceDialog to redirect your user to new dialog flows:

 (session,result)=>{
        //result.response.entity should be one of string `AAA`,`BBB`,`CCC` 
        session.replaceDialog(result.response.entity);
  }

I would like to change the retryPrompt everytime lets say pick the utterances from a list. Is that possible?

Yes, it's possible. According the choice definition, we can set options extends IPromptChoiceOptions which extends [IPromptOptions][2], we can find that retryPrompt?: TextOrMessageType;, dig into the source code for the definition of TextOrMessageType:

/**
 * Flexible range of possible prompts that can be sent to a user.
 * * _{string}_ - A simple message to send the user.
 * * _{string[]}_ - Array of possible messages to send the user. One will be chosen at random. 
...
...
 */
export type TextOrMessageType = string|string[]|IMessage|IIsMessage;

So we can set a string list for retryPrompt, bot builder will pick one randomly. Please try following:

builder.Prompts.choice(session, "Please select one of the options:", ['AAA', 'BBB', 'CCC'], {
            listStyle: builder.ListStyle.button,
            maxRetries: 1,
            retryPrompt:['utterance 1','utterance 2','utterance 3','utterance 4']
        });

Upvotes: 1

OmG
OmG

Reputation: 18858

As you can call a function in retryPrompt you can do both of them:

builder.Prompts.choice(
    session,
    'This is just a question?',
    'Yes|No',
    { retryPrompt: particularRetry() }
);

In the above, you can do what you want in particularRetry function. For example for the second question, you can call the new propmt with new choices. You can see more details in this post.

Upvotes: 0

Related Questions