我正在研究 Alexa 技能并使用 Node.js 编写我的 lambda 函数。我还使用Alexa SDK来处理 Alexa 的请求和响应。我面临的问题是我无法访问“此指针”作为响应。代码如下:
var handler = Alexa.CreateStateHandler();
handler['hi'] = function( ) {
console.log("hi intent");
request(url, function (error, response, body) {
const message = "Hello there. Best of luck!";
const reprompt = "Hello there.";
this.response.speak(message).listen(reprompt);
this.emit(':responseReady');
});
};
错误:找不到this.response
仅供参考: handler['hi'] 是一个侦听器,并从 Alexa 自动调用。我可以在请求块之外访问这个指针。
我在 SO 上阅读了不同的答案,但没有一个回答我的问题。请帮忙,我怎样才能在响应中访问“this”。