comm100-app
v1.0.5
Published
Comm100 App SDK
Downloads
19
Readme
How to use Agent Console API SDK
The JavaScript SDK must be fully loaded before you can call the JavaScript APIs.
Installation
npm
npm add comm100-appyarn
yarn add comm100-appExamples
We have several examples on the github. Here is the first one to get you started.
import { APPClient } from "comm100-app";
const Example = () => {
const handleClick = async () => {
const client = APPClient.init();
const agent = await client.get("agentconsole.currentAgent");
};
return (
<>
<button onClick={handleClick}>Get Agent</button>
</>
);
};What APIs We Provide
We provide 6 fundamental APIs to help you interact with the Comm100 Agent Console.
- GET
To get necessary information, you can use client.get.
/**
* @param {string} name - Name of data
* @param {...any} args - Any specific argument required
* @return {Promise<any>} result
*/
const client = APPClient.init();
client.get(name, ...args).then(function (data) {});- SET
To set information, you can use client.set.
/**
* @param {string} name - Name of data
* @param {any} value - Value
* @param {...any} args - Any specific data needs to be set
*/
const client = APPClient.init();
client.set(name, value, ...args);- ON
To register event callback function, please use client.on.
/**
* @param {string} type - Name of event
* @param {function} callback - Callback function. Params will be provided accordingly. Callback
* will be triggered after event, which means callback cannot prevent default behavior of event
* from happening.
*/
const client = APPClient.init();
client.on(name, function () {});- OFF
Remove event callback function registered by the ON API.
/**
* @param {string} type - Name of event
* @param {function} callback - Callback function.
*/
const client = APPClient.init();
client.on(name, function () {});- DO
To execute the action of the Agent, please use client.do.
/**
* @param {string} name - Name of action
* @param {...any} args - Any args required
* @return {Promise<any>} Return promise to indicate if action is done successfully
*/
const client = APPClient.init();
client.do(name, args);- REQUEST
When sending a backend request, if you don't provide the credentials for authorization, it brings current credentials.
/**
* @param {string} url - The request address
* @param {object} config - optional The configuration of web request, the configuration is the same with AXIOS, view this link https://axios-http.com/docs/req_config
* @return {Promise<any>} Return request data
*/
const client = APPClient.init();
client.request(url, config);