智慧.ai不解析数据聊天响应
Wit.ai Not Parsing Data to Chat Response
我的机智修改遇到了一些问题。ai的messenger.js在GitHub上。我添加了一些API调用来获得实时天气,但我在获得结果进入机器人的回复(context.forecast)时遇到了麻烦。上下文。天气预报线似乎无法"看到"我的天气数据。
最相关的行是:
context.forecast = 'Todays forecast is: ' + hourlyWeather +' in ' + location;
hourlyWeather有"今天晚上之前有小雨"这样的数据,但是机器人的回复忽略了它。
这里是相关的代码,我希望我只是在错误的地方/订单的东西,因为我是新的节点。谢谢你的帮助。
// Our bot actions
const actions = {
send({sessionId}, {text}, request) {
//const {context, entities} = request;
// Our bot has something to say!
// Let's retrieve the Facebook user whose session belongs to
const recipientId = sessions[sessionId].fbid;
if (recipientId) {
// Yay, we found our recipient!
// Let's forward our bot response to her.
// We return a promise to let our bot know when we're done sending
return fbMessage(recipientId, text)
.then(() => null)
.catch((err) => {
console.error(
'Oops! An error occurred while forwarding the response to',
recipientId,
':',
err.stack || err
);
});
} else {
console.error('Oops! Couldn''t find user for session:', sessionId);
// Giving the wheel back to our bot
return Promise.resolve()
}
},
// You should implement your custom actions here
// See https://wit.ai/docs/quickstart
//Problems start here. ----------------
getForecast({context, entities}) {
return new Promise(function(resolve, reject) {
var location = firstEntityValue(entities, 'location')
if (location) {
// we should call a weather API here
//API call to convert city name to longitude latitude
const requestw = require('request'),url = 'http://nominatim.openstreetmap.org/search?q='+location+'&format=json'
request(url, (error, response, body)=> {
if (!error && response.statusCode === 200) {
const fbResponse = JSON.parse(body)
//console.log("Got a response: ", fbResponse)
//convert JSON to array
var arr = [];
for(var x in fbResponse){
arr.push(fbResponse[x]);
}
//find latitude and longitude in array and store for later weather api call
if(arr[0].hasOwnProperty('lat')){
var lat = arr[0].lat;
}
if(arr[0].hasOwnProperty('lon')){
var lon = arr[0].lon;
}
console.log(lat, lon)
//API call for weather status
forecast.get([lat, lon], function(err, weather) {
if(err) return console.dir(err);
//console.dir(weather);
//Store weekly and daily report - Cant get to show up in forecast string. --------------
console.log(weather.hourly.summary)
var hourlyWeather = weather.hourly.summary;
console.log(weather.daily.summary)
var dailyWeather = weather.daily.summary;
});
} else {
console.log("Got an error while grabbing coordinates of city: ", error, ", status code: ", response.statusCode)
}
})
//Cant get hourlyWeather or dailyWeather to show here. Location works fine. Have tried declaring the variables elsewhere. -----------
//context.forecast = hourlyWeather;
context.forecast = 'Todays forecast is: ' + hourlyWeather +' in ' + location;
delete context.missingLocation;
} else {
context.missingLocation = true;
delete context.forecast;
}
return resolve(context);
});
},
};
机器人的回复只有"今天的天气预报是:亚特兰大"。
您需要根据上下文存储hourlyWeather。
var hourlyWeather = weather.hourly.summary;
context.hw = hourlyWeather;
然后通过上下文访问天气。
context.forecast = 'Todays forecast is: ' + context.hw +' in ' + location;
相关文章:
- 用程序搜索JQuery数据表中的文本
- 要求输入在数据列表中
- 正在将数据主题添加到所有项目
- 函数参数中的数据与指定变量之间的任何性能差异
- 在VanillaJS中模拟模型双向数据绑定
- CSS-如何定位内容数据标题
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 序列化数据属性中对象的最可靠方法
- 如何将JSON数据导入我的ejs模板
- Gmail 聊天如何在没有长轮询的情况下向用户发送数据
- 如何在JS socket.io聊天中处理异步用户数据
- 聊天和数据结构集成
- Node.js聊天服务器,当另一个用户发送数据时,客户端断开连接
- C#在聊天脚本中将数据附加到DIV
- Ajax重新加载数据聊天.js显示错误的鼠标悬停在图形上
- 在web聊天应用程序中存储数据的最佳实践
- 智慧.ai不解析数据聊天响应
- PHP Ajax聊天:数据一台PC到另一台PC不发送/接收
- 发送数据上点击- jquery ajax聊天