acontactcenter-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

ACONTACTCENTER.COM API BINDINGS

INSTALLATION

yarn add acontactcenter-api
yarn add ts-node
yarn add typescript
yarn add @types/node

TO RUN A SCRIPT

yarn ts-node <your script>

EXAMPLE - LOGIN and QUERY script

import { Api } from 'acontactcenter-api/dist/api';
import { Pagination } from 'acontactcenter-api/dist/utility';
const api = Api.instance();
api.isSsl = api.isTrue(process.env.ACC_SSL) || true;

// ******************************
// Vendor  details.  
// ******************************
var VENDOR_SUBDOMAIN = "PASTE YOUR ACC SUBDOMAIN HERE"
var VENDOR_LOGIN = "PASTE YOUR API LOGIN HERE"
var VENDOR_SECRET =  "PASTE YOUR API SECRET HERE"

// ******************************
api.hostname = VENDOR_SUBDOMAIN + "-api.acontactcenter.com";

console.log("Connecting to %s", api.hostname);
api.login(VENDOR_LOGIN, VENDOR_SECRET).then(async (loginResponse) => {
    console.log(loginResponse);

    //
    // EXAMPLE QUERY
    //

    //Create pagination with default sort
    let pagination = new Pagination("trip_id");
    //Add as many filters as you like 
    pagination.setFilter("trip_status", ["ACCEPTED"], "=");
    pagination.setFilter("trip_seconds_to_pickup", [0], "<");

    // Set your company ID - Data security will always filter by your company id
    // If you don't specify it the request will fail
    pagination.params.push(api.activeCompanyID);
    // Set you page size
    let options = pagination.getRequestOptions(0, 100);
    let page = await api.queryPaginated("itinerary.by_provider", options);
    console.log(page.data);

    process.exit(0);
}).catch((e) => {
    console.error("Login failed: %o", e);
    process.exit(1);
});

EXAMPLE BOT SCRIPT

import { Api } from 'acontactcenter-api/dist/api';
import { DispatchBotHelper } from 'YOUR BOT CODE';
const api = Api.instance();
api.isSsl = api.isTrue(process.env.ACC_SSL) || true;

// ******************************
// Vendor bot details.  
// ******************************
var VENDOR_SUBDOMAIN = "PASTE YOUR PROVIDED ACC SUBDOMAIN HERE"
var VENDOR_BOT_LOGIN = process.env.VENDOR_BOT_LOGIN || "PASTE YOUR API LOGIN HERE"
var VENDOR_BOT_SECRET = process.env.VENDOR_BOT_SECRET || "PASTE YOUR API SECRET HERE"


// ******************************
// bot connection and duration details
// ******************************
// Bot logins only work on -api domains
api.hostname = VENDOR_SUBDOMAIN + "-api.acontactcenter.com";
var BOT_LIFE_MINUTES = process.env.BOT_LIFE_MINUTES || 10;
var BOT_INTERVAL_SECONDS = process.env.BOT_INTERVAL_SECONDS || 5;


console.log("Connecting to %s", api.hostname);
api.login(VENDOR_BOT_LOGIN, VENDOR_BOT_SECRET).then(async (loginResponse) => {
    console.log(loginResponse)
    try {
        let lifeInterval: any | null = null;
        let actionInterval: any | null = null;
        let botHelper: DispatchBotHelper | null = null;
        let c = loginResponse.company;
        if (c) {
            function lifeEnd() {
                if (actionInterval) {
                    clearInterval(actionInterval);
                }
                console.log("%s BOT INEVITABLE DEATH EVENT!", c.company_name);
                process.exit(0);
            }
            function botAction() {
                let stamp = api.now.format("YYYY-MM-DD HH:mi:ss")
                console.log("BOT ACTION company:%s time:%s", c.company_name, stamp);
                botHelper!.act();
            }
           
            botHelper = new DispatchBotHelper(api);
            await botHelper.refreshLists();
            console.log("%s BOT BORN FOR %s minutes", operatorRec.name, BOT_LIFE_MINUTES);
            lifeInterval = setInterval(lifeEnd, Number(BOT_LIFE_MINUTES) * 60 * 1000);
            console.log("%s BOT WILL ACT EVERY  %s seconds", operatorRec.name, BOT_INTERVAL_SECONDS);
            actionInterval = setInterval(botAction, Number(BOT_INTERVAL_SECONDS) * 1000);

        } else {
            console.log("Error Company " + operatorRec.name + " not found");
            process.exit(1);
        }
    } catch (e) {
        console.error("failed: %o", e);
        process.exit(1);
    }
}).catch((e) => {
    console.error("Login failed: %o", e);
    process.exit(1);
});

Readme

Keywords

none

Package Sidebar

Install

npm i acontactcenter-api

Weekly Downloads

4

Version

1.0.10

License

Apache-2.0

Unpacked Size

582 kB

Total Files

210

Last publish

Collaborators

  • omasri