从 JSON 数组中获取特定用户名并显示在 BOT 界面中

Fetch particular username from JSON array and Display in BOT interface

我可以在 .js 文件的帮助下调用 site24x7api 在终端中获取所有客户详细信息(例如 user_id、姓名、zaaid)

输入:

var request = require('request');

var headers = {
    'Content-Type': 'application/json;charset=UTF-8',
    'Accept': 'application/json; version=2.0',
    'Authorization': 'Zoho-authtoken xxx12sdc231xx'
};

var options = {
    url: 'https://www.site24x7.com/api/short/msp/customers',
    headers: headers
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);

输出(在终端):

{
"user_id":"12345678912123",
"name":"abc",
"zaaid":"12341234"
},
{
"user_id":"98123141231233",
"name":"Xyz",
"zaaid":"43241123"
} ... and many more

现在假设,BOT 要求用户输入姓名,用户输入姓名

abc

程序应匹配用户输入的名称(存储在 '${session.dialogData.Companyname}' 中)和终端中存在的名称,BOT 应 return zaaid(int) 或 user_id( int) 与特定用户相关,在本例中为 12341234 到 BOT 接口

我试过了

Link 1

Link 3

使用数组遍历您的 json 文件,例如:

var users = [{
"user_id":"12345678912123",
"name":"abc",
"zaaid":"12341234"
},
{
"user_id":"98123141231233",
"name":"Xyz",
"zaaid":"43241123"
}]

for (i=0; i<users.length; i++) {
  if (users[i].name = "the_name") {
    do_something....
  }
}