【问题标题】:Alexa Skill Kit and Lambda: Make given Slot Value undefinedAlexa Skill Kit 和 Lambda:使给定的 Slot Value 未定义
【发布时间】:2018-08-23 08:24:18
【问题描述】:
我尝试构建一个 Alexa 技能,该技能具有各种插槽的话语。我实现了,如果没有给定插槽值,Alexa 会要求该特定值。
一切正常。
现在的问题是,其中一个插槽应该是名称。用户也可能会说“我”而不是他的名字。在这种情况下,该值应该再次未定义,并且 alexa 应该询问名称。
但我不知道如何在 Lambda 函数中设置未定义的值。我的意思是我可以说:name = undefined 或 name = NONE 但 Alexa 并没有要求它。
我猜 ASK 将值保存在某处,而我无法触及该值。
我已经搜索了解决方案,但我发现的所有内容都是关于为什么插槽仍然未定义或类似的事情。
提前致谢
【问题讨论】:
标签:
dialog
alexa-skills-kit
alexa-skill
【解决方案1】:
始终在您的后端验证插槽,并且当您的 name-slot 未给您预期值时,请使用 Dialog.ElicitSlot 指令让 Alexa 请求该特定插槽。
例如:
如果你使用的是 ask-nodejs-sdk,那么
return handlerInput.responseBuilder
.addElicitSlotDirective(slotToElicit)
.speak("Please provide a valid name")
.reprompt("Please provide a valid name")
.getResponse();
更多关于对话框指令here
【解决方案2】:
如果您使用对话框,那么您可以轻松验证插槽值,就像我检查过日期是否过去一样,如果是将来,alexa 会要求用户再次告知日期
(我正在使用节点 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());
}
然后在 dialogState 完成后检查您的插槽
else if (dialogStatus === 'COMPLETED') {
console.log('slots after confirmation: ', handlerInput.requestEnvelope.request.intent.slots);
}