[英]Alexa skip slot or set it programmatically?
我正在研究一种Alexa技能,该技能基本上是一个测验,其中Alexa连续询问用户多个问题,主题随发电机表中存储的用户状态而变化。 这可行。 我的目的是为每个答案提供一个插槽,并且使用对话框管理来引发每个响应,直到所有答案都被填满。 这是一些代码:
if(!answers.NewWordSpanishAnswer) {
const newWordIntroAudio = sound('intro');
const promptAudio = sound(`new-word-${word}-spanish-intro`);
return handlerInput.responseBuilder
.speak(newWordIntroAudio + promptAudio)
.reprompt(promptAudio)
.addElicitSlotDirective('NewWordSpanishAnswer')
.getResponse();
}
if(!answers.NewWordEnglishAnswer) {
const responseAudio = sound(`new-word-${word}-spanish-correct`);
const promptAudio = sound(`new-word-${word}-english-intro`);
return handlerInput.responseBuilder
.speak(responseAudio + promptAudio)
.reprompt(promptAudio)
.addElicitSlotDirective('NewWordEnglishAnswer')
.getResponse();
}
// etc. repeat for each question
问题是我需要创建一个需要可变数量问题的测验,但是插槽是在模型中定义的,因此我无法更改完成意图所需的答案数量。 我认为执行此操作的方法是提供任意数量的answer
插槽,并将默认值分配给我不需要的answer
插槽(因此,如果测验中有3个问题,但有5个插槽,则将分配最后2个插槽占位符值)。
我该怎么做? 有没有办法以编程方式设置插槽值?
这个Alexa博客帖子似乎描述了我的需求,但是不幸的是,它是使用ASK SDK v1编写的,因此我不确定如何使用v2完成它。
是的,可以跳过1个或多个插槽值。
我可以想到两种解决您的问题的方法。
1)使用addDelegateDirective代替addElicitSlotDirective收集槽值和填充时dialogState是“ 已启动 ”像下面的代码片段你不一些任意值,需要的插槽。
const { request } = handlerInput.requestEnvelope; const { intent } = request; if (request.dialogState === 'STARTED') { intent.slots.slotToSkip.value = 'skipped' return handlerInput.responseBuilder .addDelegateDirective(intent) .withShouldEndSession(false) .getResponse() }
2)在第二个解决方案中,您可以使用会话变量来跟踪要引发的插槽数量。 喜欢
let sessionAttributes = handlerInput.attributesManager.getSessionAttributes(); sessionAttributes.count = 3 //Suppose you want to elicit 3 slots; handlerInput.attributesManager.setSessionAttributes(sessionAttributes); if (sessionAttributes.count >= 0) { //addElecitSlotDirective sessionAttributes.count = sessionAttributes.count--; handlerInput.attributesManager.setSessionAttributes(sessionAttributes); } else{ //here you will get the required number of slots }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.