alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.13k stars 738 forks source link

Dialog Management Doesn't Accept Values for Manual Validation #540

Closed TheDreamSaver closed 5 years ago

TheDreamSaver commented 5 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

The Dialog Management doesn't accept values being reset after manual validation of slot values.

Expected Behavior

My use case is asking the user for city, state, zip code. I've made all of them required in dialog management and have disabled auto delegation. I ask the user where do your want to start. The user can say either city name or zip code in response. If he says zip code I manually validate in the in_progress handler below and prompt the user accordingly if the validation fails. The user is then expected to say correct zip code and skill proceeds.

Current Behavior

But when I prompt the user for wrong input and ask him to enter zip code again, the skill exits without any response.

Possible Solution

Not sure if this is a bug or am I missing something here.

Steps to Reproduce (for bugs)

In my code, I have three handlers for started, in_progress and completed. The following is the snippet from in_progress handler

    const currentIntent = handlerInput.requestEnvelope.request.intent;

    let speechText = '';
    let repromptText = '';

    if(currentIntent.slots.fromZip.hasOwnProperty('value')){
      let fromZip = handlerInput.requestEnvelope.request.intent.slots.fromZip.value;

      if(postcode.validate(fromZip, 'US')){
        currentIntent.slots.fromCity.value = "Default";
        currentIntent.slots.fromState.value = "Default";
      }
      else{
        currentIntent.slots.fromZip.value = null;
        speechText = `Sorry, ${fromZip} is not a valid US zip code. Please tell me a valid US zip code for your address or tell me the city you are in.`
        repromptText = `Please tell me a valid US zip code for your address or tell me the city you are in.`;
        return handlerInput.responseBuilder
          .speak(speechText) 
          .addDelegateDirective(currentIntent)
          .getResponse();
      }
    }

    return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();

The user can either say zipcode or city name to start dialog delegation. If he says zipcode, and city/state aren't provided yet, then, I get the zipcode from the user and validate it using postcode-validator library. If it gets validated I no longer need the user to give me city & state. But if it fails I'm setting the current value for the zip code to null and asking for it again.

Now when I prompt the user to give the zip code or city name again, if the user speaks zip code, the skill fails and gives

But if I answer the prompt with a city name it works and then even prompts for zip code.

Context

I want to minimize friction and ask the user for either zipcode or (city & state) and then proceed with business logic.

Your Environment

Node.js and NPM Info

ShenChen93 commented 5 years ago

Hi @TheDreamSaver

Thanks for posting this issue. Your use case seems reasonable. However, there's nothing we can help from SDK side, so I reached out to internal service team to see if they can provide any solutions for this case.

Thanks, Shen

ShenChen93 commented 5 years ago

Hi @TheDreamSaver

Thanks for your patient and sorry for getting back to you late. Do you still have the problem ? I create a similar test skill just like the one you described above. In the inprocessHandler, I set city value to null and alexa will ask user for it again. Here is my code:



handle(handlerInput){
    const currentIntent = handlerInput.requestEnvelope.request.intent;       
    let city = currentIntent.slots.city;
    let speechText = 'default speechText in progress';
    if (city.value === 'Seattle') {
      speechText = 'seattle is not a good place to play piongpong, please another one';
      currentIntent.slots.city.value = null;
      return handlerInput.responseBuilder
      .speak(speechText)
      .addDelegateDirective(currentIntent)
      .getResponse();
    } else if (city.value === 'Portland oregan'){
      currentIntent.slots.name.value = 'Bob';
      currentIntent.slots.Date.value = 'Tuesday';
      return handlerInput.responseBuilder
      .speak(speechText)
      .addDelegateDirective(currentIntent)
      .getResponse();
    } else {
      return handlerInput.responseBuilder
      .speak(speechText)
      .addDelegateDirective(currentIntent)
      .getResponse();
    }
  }
TheDreamSaver commented 5 years ago

Can you share your interaction model as well, so that I can try it out?

ShenChen93 commented 5 years ago

Sure. I paste my sample skill here. Let me know if there's differences between yours and this skill, so I can better reproduce the problem you meet.

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "ron wang",
            "intents": [
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                },
                {
                    "name": "PingPong",
                    "slots": [
                        {
                            "name": "city",
                            "type": "city",
                            "samples": [
                                "{city}"
                            ]
                        },
                        {
                            "name": "name",
                            "type": "name",
                            "samples": [
                                "{name}"
                            ]
                        },
                        {
                            "name": "Date",
                            "type": "DD",
                            "samples": [
                                "{Date} "
                            ]
                        }
                    ],
                    "samples": [
                        "play pingpong",
                        "play pingpong with {name} in {city} on {Date}"
                    ]
                }
            ],
            "types": [
                {
                    "name": "DD",
                    "values": [
                        {
                            "name": {
                                "value": "friday"
                            }
                        },
                        {
                            "name": {
                                "value": "tuesday"
                            }
                        },
                        {
                            "name": {
                                "value": "Monday"
                            }
                        }
                    ]
                },
                {
                    "name": "name",
                    "values": [
                        {
                            "name": {
                                "value": "dave"
                            }
                        },
                        {
                            "name": {
                                "value": "bob"
                            }
                        },
                        {
                            "name": {
                                "value": "sam"
                            }
                        }
                    ]
                },
                {
                    "name": "city",
                    "values": [
                        {
                            "name": {
                                "value": "tacoma"
                            }
                        },
                        {
                            "name": {
                                "value": "portland oregon"
                            }
                        },
                        {
                            "name": {
                                "value": "seattle"
                            }
                        }
                    ]
                }
            ]
        },
        "dialog": {
            "intents": [
                {
                    "name": "PingPong",
                    "delegationStrategy": "SKILL_RESPONSE",
                    "confirmationRequired": false,
                    "prompts": {},
                    "slots": [
                        {
                            "name": "city",
                            "type": "city",
                            "confirmationRequired": false,
                            "elicitationRequired": true,
                            "prompts": {
                                "elicitation": "Elicit.Slot.726075360390.985493275640"
                            }
                        },
                        {
                            "name": "name",
                            "type": "name",
                            "confirmationRequired": false,
                            "elicitationRequired": true,
                            "prompts": {
                                "elicitation": "Elicit.Slot.726075360390.1159756591376"
                            }
                        },
                        {
                            "name": "Date",
                            "type": "DD",
                            "confirmationRequired": false,
                            "elicitationRequired": true,
                            "prompts": {
                                "elicitation": "Elicit.Slot.726075360390.1406650753450"
                            }
                        }
                    ]
                }
            ],
            "delegationStrategy": "ALWAYS"
        },
        "prompts": [
            {
                "id": "Elicit.Slot.726075360390.985493275640",
                "variations": [
                    {
                        "type": "PlainText",
                        "value": "Where are you going to play?"
                    }
                ]
            },
            {
                "id": "Elicit.Slot.726075360390.1159756591376",
                "variations": [
                    {
                        "type": "PlainText",
                        "value": "Play pingpong with whom?"
                    }
                ]
            },
            {
                "id": "Elicit.Slot.726075360390.1406650753450",
                "variations": [
                    {
                        "type": "PlainText",
                        "value": "when to paly"
                    }
                ]
            }
        ]
    }
}
ShenChen93 commented 5 years ago

@TheDreamSaver Are you still having this issue? May I get any update :)

TheDreamSaver commented 5 years ago

Hey Sorry forgot to update. I am not having this exact issue anymore. Will open another request if I face something similar.