我正在使用IbmWatson创建一个聊天机器人。当用户向我的聊天机器人询问某些产品的成本时,这些值来自MySQL服务器。我完成所有设置也获得了价值。但是这些值在命令提示符中显示而不是在Chatbot中。
如何在Chat bot中显示这些值。
我正在使用Node.js
我正在尝试这段代码:
function updateMessage(input, response){
var responseText = null;
if (response.intents && response.intents[0]) {
var intent = response.intents[0];
if (intent.intent==='Sales-1'){
var rsp = con.query("SELECT Mobiles from Salestb", function (err,
result, fields) {
if (err) throw err;
console.log(result);
result.forEach( (row) => {
console.log(`${row.Mobiles}`);
});
});
response.output.text = "This is the modified Output :"+ rsp;
} }
我正在尝试上面的代码来获取命令提示符中的值是:
[ RowDataPacket { Mobiles: '2,894,564' } ]
2,894,564
在Chat bot中:这是修改后的输出:[object Object]
值以对象格式显示。但我想要显示值。怎么解决这个?
您在命令提示符下获取输出,因为yopu使用console.log:
console.log(`${row.Mobiles}`);
你应该将响应更改为:
response.output.text = "This is the modified Output :"+ ${row.Mobiles};
编辑把你的内部问题放在这里
function updateMessage(input, response){
var responseText = null;
if (response.intents && response.intents[0]) {
var intent = response.intents[0];
if (intent.intent==='Sales-1'){
var rsp = con.query("SELECT Mobiles from Salestb", function (err,result, fields) {
if (err) throw err;
console.log(result);
result.forEach( (row) => {
console.log(`${row.Mobiles}`);
});
response.output.text = "This is the modified Output :"+ ${row.Mobiles};
});
}
}
}