Alexa Custom Slot Type: No value in intent

不打扰是莪最后的温柔 提交于 2019-12-02 21:23:09
Atlas7

(disclaimer: this post summarises my own "workaround". It might or might not be the "best way". Seems to have worked for me so thought I would share / document it here briefly)

I've recently bumped into similar issues for an utterance that looks like this:

"tell me about {townName}"

If I say "tell me about London", it works.

If I say "tell me about" (deliberately missing a {townName}), the program "dies" (and returns a JSON looking similar to your one, with undefined this.event.request.intent.slots.townName.value)

Though I'm not 100% sure whether this is meant to be a "feature" (i.e. we need to write smarter code to work around this) or "problem" (i.e. Alexa team needs to address or fix). This scenario has caused a real issue when it came to the certification process for me recently.

To get through this, I've implemented a workaround (or fix, whatever you call it) to avoid Alexa from "dying" as a result of this edge case.

From the Alexa skill-sample-nodejs-trivia index.js file, I've found a snippet function that helped me work around this (I've edited it a bit for my example for simplicity):

function isAnswerSlotValid(intent) {
    var answerSlotFilled = intent && intent.slots &&
        intent.slots.townName && intent.slots.townName.value;
    return answerSlotFilled
}

(i.e. this function returns True for valid values for the slot townName and and False for undefined / otherwise).

When it comes to defining the intent, I could use this function to "get around" an empty slot value scenario:

var startHandlers = Alexa.CreateStateHandler(states.START,{

  // bla bla bla//

  "AnswerIntent": function() {  

    // handel missing slot value
    var answerSlotValid = isAnswerSlotValid(this.event.request.intent);

    if (answerSlotValid && moreConditions) {
      // do something fun
    }
    else {
      // handle empty slot scenario
    }
  }

  // bla bla bla//

}

Would be interested to see if there are better / more "proper" solutions to this to handle empty / undefined slots more elegantly.

I have seen this happen when an intent has both utterances with and without a slot. For example:

myIntent what makes a car go fast myIntent what makes a {CAR_TYPE} go fast

where CAR_TYPE has a list of different types of cars.

myIntent still needs to define the slot CAR_TYPE for the myIntent in the schema, but the first intent doesn't use it. In this case, it might be best to include 'car' in CAR_TYPE and eliminate the first utterance. In other cases though, the sentence grammar really doesn't permit it, so you need to expect an empty slot like you're seeing.

I believe the issue is that utterances using a Custom Slot Type must be used with at least one other value.

For example

EmployeeDetailsIntent get {Person}

will work, while

EmployeeDetailsIntent {Person} 

will not

Had same thing, get custom slot name, but value was missing in Json Input. Worked with normal slots. Using Alexa Developer Console. Had to add an "ID" value to my custom slot values and then I started getting values. I thought I had tried that before but maybe I had not put an ID on each value. That did the trick for me though where the other answers did not work for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!