【问题标题】:Alexa ASK SDK V2 Nodejs Dialog Delegate Directive overriding the card responseAlexa ASK SDK V2 Nodejs Dialog Delegate Directive 覆盖卡响应
【发布时间】:2018-09-25 08:25:14
【问题描述】:

我正在使用 ASK SDK V2 for node.js 来开发 alexa 技能。根据文档,我们需要添加 Inprogress 以及 Completed 对话处理程序来实现对话委托。它工作正常,但响应以某种方式覆盖了我期望的响应。

Inprogress 意图处理程序:

const InProgressGetAuthors = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
            handlerInput.requestEnvelope.request.intent.name === 'GetAuthors' &&
            handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED';
    },
    handle(handlerInput) {
        const currentIntent = handlerInput.requestEnvelope.request.intent;
        if (handlerInput.requestEnvelope.request.dialogState === "STARTED") {
            return handlerInput.responseBuilder
                .addDelegateDirective(currentIntent)
                .getResponse();
        } else if (handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED') {
            return handlerInput.responseBuilder
                .addDelegateDirective()
                .getResponse();
        } else {
            return currentIntent;
        }
    }
}

完成的意图处理程序:

const CompletedGetAuthors = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
            handlerInput.requestEnvelope.request.intent.name === 'GetAuthors';
    },
    handle(handlerInput) {
        return handlerInput.responseBuilder
            .speak(author_propmt)
            .reprompt(author_propmt)
            .withStandardCard(
                author_title,
                author_copy,
                author.imageUrl,
                author.imageUrl
            )
            .withShouldEndSession(false)
            .getResponse(); 
    }
}

在完成的意图处理程序中,我在响应中发送卡片。它确实说出了文字,但没有显示卡片作为响应。

响应对象:

{
    "body": {
        "version": "1.0",
        "response": {
            "directives": [
                {
                    "type": "Dialog.Delegate"
                }
            ]
        },
        "sessionAttributes": {},
        "userAgent": "ask-node/2.0.9 Node/v6.10.3"
    }
}

如果您查看响应正文,则卡片丢失。我究竟做错了什么 ?谁能告诉我?

谢谢

【问题讨论】:

    标签: node.js alexa alexa-skills-kit


    【解决方案1】:

    对于遇到此问题的任何人,请在 Inprogress 意图处理程序中添加以下条件:

        handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED' &&
        handlerInput.requestEnvelope.request.dialogState !== 'IN_PROGRESS';
    

    卡片现在正在显示。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-25
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 2018-11-03
      相关资源
      最近更新 更多