Alexa技能.getResponse()有什么作用?

时间:2019-02-16 22:27:21

标签: javascript alexa

我正在学习js并创建简单的Alexa技能。 我想更好地理解模板代码,正在研究https://ask-sdk-for-nodejs.readthedocs.io上的文档,但找不到该问题的答案。 每个处理程序模板中都使用.getResponse()方法。它也用在SessionEndedIntent处理程序中,这意味着它不能成为等待用户输入的方法。我尝试使用谷歌搜索,但找不到答案。 谁能解释.getResponse()的作用,还是将我指向相关文档?谢谢。

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
    // Any cleanup logic goes here.
    return handlerInput.responseBuilder.getResponse();
}

1 个答案:

答案 0 :(得分:0)

如果有人需要,我已经指出了正确的答案: https://developer.amazon.com/blogs/alexa/post/f167aa0f-8abe-4602-b985-65118b3032ca/code-deep-dive-slots-and-session-attributes-in-the-ask-sdk-for-node-js

.getResponse()生成一个JSON答案以与Alexa通信:

  

生成JSON响应

     

最后,我们添加了getResponse()方法以与我们的speechOutput一起生成JSON响应。