我正在关注 Wit AI 教程,但我遇到了困难。我正在尝试扩展快速入门天气教程以调用实际的天气 API,但我没有运气。
这是我修改后的 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;
});
},
};