【问题标题】:Slot answer returning undefined when wrong answer is given给出错误答案时,槽答案返回未定义
【发布时间】:2020-08-25 22:20:42
【问题描述】:

在我的测验中,我正在捕捉用户的答案

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"
                        }
                    }
                }
            }

我怎样才能让它无论正确还是错误都可以访问答案?

谢谢!

【问题讨论】:

  • 如何定义槽类型答案?
  • 这里是用户答案和正确答案的代码。我只是将两者与 if 语句进行比较。当用户说出错误答案时,请求对象不会在对象的任何地方记录用户的答案。 const userAnswer = handlerInput.requestEnvelope.request.intent.slots.answer.resolutions.resolutionsPerAuthority[0].values[0].value.name; const session = handlerInput.attributesManager.getSessionAttributes(); const correctAnswer = session.CORRECT_ANSWER;
  • 这是您检查正确性的唯一地方吗?您对该技能有任何验证吗?
  • 我没有任何验证,尽管我在开发控制台中看到了该选项。但我对他们不是很熟悉。我将如何使用它们?谢谢!
  • 如果您有一个更静态且只有一个小域的插槽,您会使用它们。例如,如果您有一家只出售袜子的商店,您的位置可能是袜子,并且可以选择黑色或白色。听起来您正在以正确的方式来解决您的用例

标签: node.js alexa alexa-slot


【解决方案1】:

你也可以这样做:

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;
}

稍后我将使用其他信息对其进行编辑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多