我正在使用ASK SDK V2 for node.js开发alexa技能。根据文档,我们需要添加Inprogress和完成的对话框处理程序来实现对话框委托。它工作正常,但是响应以某种方式覆盖了我期望的响应。
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"
}
}
谢谢