无法从get函数检索数据

问题描述 投票:0回答:1

我正在写一个lambda函数来处理alexa技能请求。在“建立LookUp意图”内部,在https.get()之后,没有任何内容被添加到响应中。

'BuildingLookUpIntent': function(){
        var response = "";
        https.get('https://*******.execute-api.us-east-1.amazonaws.com/active/building?*******', (res) => {
            res.on('data', (d) => {
                response += d;
            });
        });  

        var speechOutput = response;
        this.response.speak(speechOutput);
        this.emit(':responseReady');
    }

Alexa返回一个空白字符串。

node.js lambda https get alexa
1个回答
0
投票

Alexa在你的情况下什么都不会说。这是因为`

 var speechOutput = response;
 this.response.speak(speechOutput);
 this.emit(':responseReady');

`甚至在您的代码开始处理收到的响应之前执行`。解决这个问题的一种方法是将上面提到的代码移到“res.on”中,这样​​当你收到响应字符串时,它会被分配给“speechOutput”,而Alexa可以说出来。

© www.soinside.com 2019 - 2024. All rights reserved.