I've already posted this question to the amazon developer forum but don't receive an answer there. I guess Stackoverflow should've been the first choice from the beginning:
From my understanding if I use a Custom Slot Type even if the list of its possible values does not contain the spoken word the spoken word is still passed to the function. The documentation says
A custom slot type is not the equivalent of an enumeration. Values outside the list may still be returned if recognized by the spoken language understanding system.
Now I have a Custom Slot Type LIST_OF_PERSONS
with values Matthias|Max
and an utterance of
EmployeeDetailsIntent {Person}
If I call this intend with a value not in LIST_OF_PERSONS
the Intent still gets called but the JSON does not contain a "value" key for the Slot:
"request": {
"type": "IntentRequest",
"requestId": "EdwRequestId.a943e233-0713-4ea5-beba-d9287edb6083",
"locale": "de-DE",
"timestamp": "2017-03-09T14:38:29Z",
"intent": {
"name": "EmployeeDetailsIntent",
"slots": {
"Person": {
"name": "Person"
}
}
}
}
Is this "works as designed" or a bug? How do I access the spoken word in the Intent then? As this.event.request.intent.slots.Person.value
is undefined?
My code lives in AWS lambda and I'm using the nodejs alexa-sdk Version 1.0.7. The language of my Skill is German.
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With