0
我正在關注Wit AI教程,並且我遇到了困難。 我想延長快速啓動天氣教程來調用實際的天氣API,我沒有運氣。Wit AI和異步函數
這是我修改的getForecast方法。原來可以在這裏找到:https://wit.ai/docs/quickstart
var weather = require('weather-js');
const actions = {
send(request, response) {
const {sessionId, context, entities} = request;
const {text, quickreplies} = response;
console.log('sending...', JSON.stringify(response));
},
getForecast({context, entities}) {
var location = firstEntityValue(entities, 'location');
weather.find({search: location, degreeType: 'F'}, function(err, result) {
if(err){
context.missingLocation = true;
delete context.forecast;
}else{
var temperature = result[0].current.temperature;
context.forecast = temperature+ ' degrees in '+location; // we should call a weather API here
delete context.missingLocation;
fs.writeFile("weather.json",JSON.stringify(result));
}
return context;
});
},
};