1.0.5 • Published 2 years ago

comm100-app v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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-app

yarn

yarn add comm100-app

Examples

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.

  1. 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) {});
  1. 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);
  1. 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 () {});
  1. 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 () {});
  1. 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);
  1. 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);
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago