插槽答案给出错误答案时返回未定义"/>
插槽答案给出错误答案时返回未定义
在我的测验中,我正在捕获用户的答案,并使用它
handlerInput.requestEnvelope.request.intent.slots.answer.resolutions.resolutionsPerAuthority[0].values[0].value.name
并将其与sessionAttributes中的答案集进行比较。问题是当给出错误答案时,请求对象看起来像这样,没有值可以与我的会话答案进行比较:
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.1e4d598d-2cb8-45fa-80d7-4ea75f544401",
"timestamp": "2020-05-09T15:12:37Z",
"locale": "en-US",
"intent": {
"name": "AnswerIntent",
"confirmationStatus": "NONE",
"slots": {
"answer": {
"name": "answer",
"confirmationStatus": "NONE"
}
}
}
}
当您给出正确答案时,插槽答案将被正确捕获,然后可以与sessionAttribute值进行比较:
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.6da39547-7039-49f4-8138-a9105bb6f010",
"timestamp": "2020-05-09T15:13:10Z",
"locale": "en-US",
"intent": {
"name": "AnswerIntent",
"confirmationStatus": "NONE",
"slots": {
"answer": {
"name": "answer",
"value": "project manager",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.c933b50a-faf5-4f49-8551-838fc1f47fc4.QuizAnswers",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Project manager",
"id": "00f87ea316ec965ecda65285f4e273b6"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}
我该如何做,以便无论答案是正确还是不正确,我都可以访问它?
谢谢!
回答如下:您还可以执行以下操作:
getSpokenWords: function (handlerInput, slot) {
if (handlerInput.requestEnvelope
&& handlerInput.requestEnvelope.request
&& handlerInput.requestEnvelope.request.intent
&& handlerInput.requestEnvelope.request.intent.slots
&& handlerInput.requestEnvelope.request.intent.slots[slot]
&& handlerInput.requestEnvelope.request.intent.slots[slot].value)
return handlerInput.requestEnvelope.request.intent.slots[slot].value;
else return undefined;
}
我将在后面编辑此内容并提供其他信息。
更多推荐
插槽答案给出错误答案时返回未定义
发布评论