Brekeke Contact Center Suite Wiki

CRM - Push Call Lists

Requirements

Brekeke CRM v.2.7.8.0.15457 or later

 

About Web-If API (only some part are translated to English)

http://www.brekeke-sip.com/download/ccs/crm_2_7_5_web_if_v140_190906_en.odt

 

Steps
  • Create a new script as “calllist” from the Tenant menu > [Script] page.
  • Copy & paste the entire text from the script_calllist.txt and save.
  • Place the webif.html under webapps/crm folder on the server.
  • Open https://xxxxx/crm/webif.html with the browser and fill the fields like below;
    • URL – https://xxx/crm/adminif.action
    • Tenant, User, Pass – Account information of a tenant administrator
    • Project ID – The project ID (number) to which you want to import the list. (See below “How to check the project ID”)
    • Script – calllist
    • Function — upload
    • Params — Json array of a string value
      • 1 – ‘$project‘ (to pass the project object to the function.)
      • 2 – options. To change the priority, set “{“changePriority”:true}
      • 3 – columns. Json array of field ID. (Not field names, please check the field ID from the Workspace > Customer > Field Settings page.)
      • 4 – data. Json array of an array of import data.
[ "$project","{\"changePriority\":true}",
 "[\"telno1\",\"telno2\",\"telno3\",\"email\",\"firstname\",\"lastname\",\"priority\"]",
 "[[\"2501111104\",\"\",\"2501111100\",\"user1@brekeke.com\",\"User1\",\"\",\"Low\"],
[\"2501111105\",\"\",\"2501111100\",\"user2@brekeke.com\",\"User2\",\"\",\"Low\"],
[\"2501111106\",\"\",\"2501111100\",\"user3@brekeke.com\",\"User3\",\"\",\"High\"]]" 
]

To change the priority

Create a field with the field ID “property” in the field settings.

 

How to check the project ID

Go to the Workspace > Project page to see the project list. Mouseover on the project name at the bottom of the browser (Chrome or Firefox) and the link “javascript:window.parent.window.sel_pj_func(‘27‘,’p1’)” should appear. In this example, 27 is the project ID.

 

script_calllist.txt:
var BaseTenant = Java.type('jp.brekeke.common.business.BaseTenant');
var log = Java.type('jp.brekeke.common.common.BaseLog').getMyLogger();
var HashMap = Java.type('java.util.HashMap');
var ArrayList = Java.type('java.util.ArrayList');
var Timestamp = Java.type('java.sql.Timestamp');
var Date = Java.type('java.util.Date');
var SoManager = Java.type('com.brekeke.crm.common.SoManager');
var MapA = Java.type('java.util.Map[]');
function getTstamp(manager, tenant_name, project_id, mxmn) {
  var sql =
    'SELECT ' +
    mxmn +
    '(cl.dialer_tstamp) tstamp FROM `' +
    'm_project_calllist_' +
    tenant_name +
    '_' +
    project_id +
    '` cl WHERE cl.process_mode=0';
  var con = null;
  var stm = null;
  var ret = null;

  try {
    con = manager.getJdbcOptions().getConnection();
    stm = con.createStatement();
    var rs = stm.executeQuery(sql);
    if (rs.next()) {
      ret = rs.getTimestamp(1);
    } else {
      log.error('Failed to get tstamp:' + sql);
    }
    rs.close();
    return ret;
  } finally {
    if (stm) {
      stm.close();
    }
    if (con) {
      con.close();
    }
  }
}
/*
  columns - Array of the column names
  data - Array of the arrays of import data
*/

function upload(project, options, columns, data) {
  options = options ? JSON.parse(options) : null;
  columns = JSON.parse(columns);
  data = JSON.parse(data);
  var manager = SoManager.instance;
  var tenant_name = project.getTenant_name();
  var project_id = project.getProject_id();
  var change_priority = false;
  if (options) {
    if (options.changePriority) {
      change_priority = true;
    }
  }

  var maxTstamp = null;
  var minTstamp = null;

  if (change_priority) {
    maxTstamp = getTstamp(manager, tenant_name, project_id, 'max');
    minTstamp = getTstamp(manager, tenant_name, project_id, 'min');
    maxTstamp = new Timestamp(maxTstamp.getTime() + 1000);
    maxTstamp = maxTstamp.toString();
    maxTstamp = maxTstamp.replaceAll('-', '/').substring(0, 19); // 2022/02/08 21:20:00
    log.info(maxTstamp);
    minTstamp = new Timestamp(minTstamp.getTime() - 1000);
    minTstamp = minTstamp.toString();
    minTstamp = minTstamp.replaceAll('-', '/').substring(0, 19);
  }

  var al = new ArrayList();
  for (var i = 0; i < data.length; i++) {
    var row = data[i];
    var hm = new HashMap();
    var max = row.length > columns.length ? columns.length : row.length;
    for (var c = 0; c < max; c++) {
      hm.put(columns[c], row[c]);
      if (change_priority && columns[c] == 'priority') {
        if (row[c] == 'High') {
          hm.put('dialer_tstamp', minTstamp);
        } else {
          hm.put('dialer_tstamp', maxTstamp);
        }
      }
    }
    al.add(hm);
  }

  var ary = new MapA(al.size());
  al.toArray(ary);
  var errorContinue = true;
  if (options) {
    if (options.errorContinue === false || options.errorContinue === 'false') {
      errorContinue = false;
    }
  }

  var res = project.importCall(ary, errorContinue);
  var em = '';
  var e = res.getErrorMessages();
  if (e.size() > 0) {
    em = ',first_error=' + e.get(0);
  }
  return (
    'OK:success=' + res.getSuccess() + ',errCount=' + res.getErrorCnt() + em
  );
}

 

webif.html:
<!DOCTYPE html>
<html>
  <head>
    <title>Brekeke CCS Web-If</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script>
      function go() {
        var url = document.f.url.value;
        var tenant = document.f.tenant.value;
        var user = document.f.user.value;
        var pass = document.f.pass.value;
        var script = document.f.script.value;
        var project_id = document.f.project_id.value;
        var func = document.f.func.value;
        var params = JSON.parse(document.f.params.value);
        var operationParam = {
          scriptName: script,
          functionName: func,
          functionParams: params,
          projectId: project_id,
        };
        var ifParams = {
          operationId: 'callScriptFunction',
          operationParam: operationParam,
          tenantName: tenant,
          userId: user,
          userPassword: pass,
        };
        var p = JSON.stringify(ifParams);
        document.f.request.value = p;
        fetch(url, {
          method: 'POST',
          body: p,
          referrer: 'no-referrer', // *client, no-referrer
          headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
          },
        })
          .then(function (response) {
            document.f.response.value = JSON.stringify(response);
          })
          .catch(function (e) {
            document.f.response.value = JSON.stringify(e);
          });
      }
      function init() {}
    </script>
    <style type="text/css">
      .test {
        line-height: 28px;
      }
      .test label {
        padding: 3px 10px 3px 0px;
        min-width: 200px;
      }
      .test textarea {
        width: 300px;
        height: 150px;
      }
    </style>
  </head>
  <body class="test" onload="init();">
    <form name="f">
      <div>
        <label>URL</label
        ><input
          type="text"
          name="url"
          value="https://xxxxxx/crm/adminif.action"
          size="150"
        />
      </div>
      <div>
        <label>Tenant</label><input type="text" name="tenant" value="" />
      </div>
      <div><label>User</label><input type="text" name="user" value="" /></div>
      <div>
        <label>Pass</label><input type="password" name="pass" value="" />
      </div>
      <div>
        <label>Project ID</label
        ><input type="text" name="project_id" value="" />
      </div>
      <div>
        <label>Script</label><input type="text" name="script" value="" />
      </div>
      <div>
        <label>Function</label><input type="text" name="func" value="" />
      </div>
      <div><label>Params</label><textarea name="params"></textarea></div>
      <div><input type="button" value="Submit" onclick="go();" /></div>
      <div><label>Request</label><textarea name="request"></textarea></div>
      <div><label>Response</label><textarea name="response"></textarea></div>
    </form>
  </body>
</html>
Yes No
Suggest Edit