Botframework-sdk: How to handle wrong input from the user?

Created on 14 Oct 2016  Â·  5Comments  Â·  Source: microsoft/botframework-sdk

Hi,
I have two questions for which I am not able to figure out a solution. Both of them are about handling wrong input from the user.
1)For the below Prompts.Choice if the user inputs lets say 3, then I am displayed "default_choice" in the cmd prompt, how do I handle this and lets say I want to display "Please select from the available list of policies." if the user enters 3 and "Please select an option." message if the user enters a character or a string that doesnt match the Choices.
2)In the below example if the user enter a wrong name the appropriate error message is displayed but when I reenter correctly or even wrongly it runs from the beginning of the /getName i.e it prints out as follows.

Hi! What is your name?
Vignesh
Please enter your full name
Vignesh
Hi! What is your name? _//It should ask me again to enter my full name_
Vignesh
Please enter your full name
Vignesh S
Hi! What is your name? _//In the last response I have correctly entered my full name but still it asks me what is my name and only after this time it accepts._
Vignesh S
Dialog GetName Ended
Welcome Vignesh S...
hi

What type of plan you are looking for? _//All the dialogs are finished no more dialogs are present then why the default dislog is triggering again how do I prevent it I have already ended this dialog using session.endDialog(), then why it is showing up again?_

  1. Car
  2. Bike
bot.dialog('/', [
    function(session) {
        builder.Prompts.choice(session, 'What type of vehicle you are looking for?', ["Car", "Bike"]);
    },
    function(session, results) {
        if (results.response) {
            if (availableVehicleTypes.indexOf(results.response["entity"]) > -1 && results.response["entity"] != "default_choice") {
                //In the array
                typeOfVehicle = results.response["entity"];
                session.send("Hmm so want a " + typeOfVehicle);
                session.endDialog();
                session.beginDialog('/getName');
            }
            else {
                //Not in the array
                session.send("Please select from the available list of policies.");
            }
        }
        else {
            session.send("Please select an option.");
        }
    }
]);
bot.dialog('/getName', [
    function(session) {
        builder.Prompts.text(session, "Hi! What is your name?");
    },
    function(session, results) {
        if (results.response) {
            //This will run for a valid string
            if (isNaN(results.response) && isValid(results.response)) {
                //Lets check if it is a full name
                if (results.response.split(' ').length > 1) {
                    name = results.response;
                    session.send("Welcome %s...", name);
                    session.endDialog();
                }
                else {
                    session.send("Please enter your full name");
                }
            }
            else {
                session.send("Please enter a valid name");
            }
        }
        else {
            // if user didnt enter anything
            session.send("Please enter your name");
        }
    }
]);
help wanted

All 5 comments

For 1 you can do:

let options = {
    retryPrompt: 'Please select from the available list of policies.'
};
builder.Prompts.choice(
    session,
    'What type of vehicle you are looking for?',
    ["Car", "Bike"],
    options // pass options here
);

For 2 you can take a look at DialogAction#validatedPrompt https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.dialogaction.html#validatedprompt

How can I do the same but on current version ?

@enKoding
The Microsoft Bot Framework team prefers that how to questions be submitted on Stack Overflow. The official Bot Framework Github repo  is the preferred platform for submitting bug fixes and feature requests.

Docs for how to use Prompts with validation in Bot Builder V4 can be found here: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-prompts?view=azure-bot-service-4.0&tabs=javascript

Docs for how to use Prompts with validation in Bot Builder V4 can be found here: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-prompts?view=azure-bot-service-4.0&tabs=javascript

You're right, but it only talks about validating numbers and dates but simple text... such as "LOCATION_PROMPT" 😞

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hailiang-wang picture hailiang-wang  Â·  3Comments

sebsylvester picture sebsylvester  Â·  3Comments

somprabhsharma picture somprabhsharma  Â·  3Comments

kenyeung128 picture kenyeung128  Â·  3Comments

Vigneshramkumar picture Vigneshramkumar  Â·  3Comments