【问题标题】:Fetch particular username from JSON array and Display in BOT interface从 JSON 数组中获取特定用户名并在 BOT 界面中显示
【发布时间】:2018-07-18 16:15:23
【问题描述】:

我可以在 .js 文件的帮助下调用 site24x7api 来获取终端中的所有客户详细信息(例如 user_id、name、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 应返回与该特定用户相关的 zaaid(int) 或 user_id(int),即 12341234案例到 BOT 接口

我试过了

Link 1

Link 2

Link 3

【问题讨论】:

    标签: json api azure-bot-service site24x7


    【解决方案1】:

    使用数组遍历你的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....
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-06
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 2019-09-14
      • 2018-09-20
      • 1970-01-01
      相关资源
      最近更新 更多