Microsoft Bot Framework: How to validate user response to bot Prompts?

Microsoft Bot Framework has multiple prompts to get user response while having the conversation such as Prompts.textPrompts.numberPrompts.ChoicePrompts.confirm

But there is automatic validation for number, choice and confirm prompt. For example if the user responds with wrong choice then the chat bot will re-prompt the choices and ask yo to select again. Check documentation here.

This post will show how can we put validation response which we get form the Prompts.text

Bot Framework provides validatedPrompt  which is a function which validates the user prompt and returns the response back if the condition is true.

here is an example,

bot.dialog('/getDetail', [
    function (session) {
      session.beginDialog('/validateAge', { prompt: "What's your age?" });

      //if false response, then prmopts "I did not understand {age}""    

    function (session, results) {

        if (results.response) {
            session.send("Thank you for adding your age");
     matches: /^lets validate$/i


bot.dialog('/validateAge', builder.DialogAction.validatedPrompt(builder.PromptType.text, function (response) {
   if(response> 0 && response < 70){

    return response;

Source: My question and answer on StackOverflow here



One thought on “Microsoft Bot Framework: How to validate user response to bot Prompts?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s