Reputation: 330
I try to build an Alexa Skill that has an utterance with various slots. I implemented, that if a slot value is not given Alexa asks for that specific value. Everything works fine.
Now the problem is, that one of the Slots should be a Name. A User might also say 'I' instead of his name. In that case the value should again be undefined and alexa should ask for the Name. But I have no Idea how to set the value undefined in the Lambda funktion. I mean i can say: name = undefined or name = NONE but Alexa doesn't ask for it.
I guess that ASK saves the value somewhere and I can't touch that Value.
I've searched for Solutions but everything I found was about why slots are still undefined or things like that.
Thanks in advance
Upvotes: 0
Views: 462
Reputation: 1218
If you are using dialogs then you can easily validate a slot value like i have checked that the date is in past, if it is in future alexa asks the user to tell the date again (i'm using node sdk v2)
if (dialogState !== 'COMPLETED') {
var dateTakenSlot=handlerInput.requestEnvelope.request.intent.slots.dateTaken.value;
if (dateTakenSlot !== null || dateTakenSlot !== undefined) {
var dateTaken = new Date(dateTakenSlot);
if (dateTaken > new Date()) {
resolve(handlerInput.responseBuilder
.speak('You can not log any future slots, On what date did you took the medicine')
.addElicitSlotDirective(handlerInput.requestEnvelope.request.intent.slots.dateTaken.name)
.getResponse());
}
then check your slots after dialogState is COMPLETED like
else if (dialogStatus === 'COMPLETED') {
console.log('slots after confirmation: ', handlerInput.requestEnvelope.request.intent.slots);
}
Upvotes: 1
Reputation: 4387
Always validate slots in your backend, and whenever your name-slot
is not giving you expected values, use Dialog.ElicitSlot
directive to make Alexa ask for that particular slot.
Ex: If you are using ask-nodejs-sdk, then
return handlerInput.responseBuilder
.addElicitSlotDirective(slotToElicit)
.speak("Please provide a valid name")
.reprompt("Please provide a valid name")
.getResponse();
More on Dialog directives here
Upvotes: 2