【问题标题】:Can't retrieve data from get function无法从 get 函数中检索数据
【发布时间】:2019-04-05 03:29:07
【问题描述】:

我正在编写一个 lambda 函数来处理 alexa 技能请求。在“BuildingLookUpIntent”内部,在 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】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-06-26
      • 2021-10-06
      • 1970-01-01
      • 2014-04-20
      • 2018-10-04
      • 1970-01-01
      相关资源
      最近更新 更多