Node.js Alexa任务问题
我目前正在通过AWS Lambda编写Node.js Alexa任务,我一直在尝试编写一个函数,该函数从OpenWeather API接收信息并将其解析为一个名为的变量weather.相关代码如下:
var request = require('request');
var weather = "";
function isBadWeather(location) {
var endpoint = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "&APPID=205283d9c9211b776d3580d5de5d6338";
var body = "";
request(endpoint, function (error, response, body) {
if (!error && response.statusCode == 200) {
body = JSON.parse(body);
weather = body.weather[0].id;
}
});
}
function testWeather()
{
setTimeout(function() {
if (weather >= 200 && weather < 800)
weather = true;
else
weather = false;
console.log(weather);
generateResponse(buildSpeechletResponse(weather, true), {});
}, 500);
} …Run Code Online (Sandbox Code Playgroud)