我正在从 Nodejs Lambda 函数返回响应,并给出如下空白响应:
{
"version": "1.0",
"sessionAttributes": {
"outputSpeech": {
"type": "PlainText",
"text": "Welcome to Alexa Skill"
},
"shouldEndSession": true
},
"response": {}
}
session 属性应该为空,响应应该包含 session 属性的内容,但情况恰恰相反。这是生成响应的代码。
context.succeed(
buildResponse(
buildSpeechletResponse("Welcome to Alexa Skill", true),
{}
)
)
这些是辅助函数:
function buildSpeechletResponse(outputText, shouldEndSession) {
return {
outputSpeech: {
type: "PlainText",
text: outputText
},
// card: {
// type: "Simple",
// title: title,
// content: output
// },
// reprompt: {
// outputSpeech: {
// type: "PlainText",
// text: repromptText
// }
// },
shouldEndSession: shouldEndSession
};
}
function buildResponse(sessionAttributes, speechletResponse) {
return {
version: "1.0",
sessionAttributes: sessionAttributes,
response: speechletResponse
};
最佳答案
只需观察 buildResponse 辅助方法中的参数顺序即可。你正在反向传递它。只需更改如下即可。
context.succeed(
buildResponse({},
buildSpeechletResponse("Welcome to Alexa Skill", true)
)
)
关于javascript - Alexa Node js Lambda 函数给出响应 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48641763/