Skip to content
Last updated

The sdk object is the one which provides you the functionality of our App Integration SDK. There are 4 available functionalities that you can access with the sdk object. This is also the first argument that is passed into the perform function.

sdk.console

The console function provides a simple debugging console that is similar to the Node.js console module. To write a log you can do the following:

sdk.console.log('This is my first log');

Read more about logging here.

sdk.request

The request function provides you the functionality of doing Http requests. The request function has the following signature: request(requestOptions)

ArgumentsDescriptionVALUE TYPE
requestOptionsThe options to pass into the request functionRequestOptions (See below)

RequestOptions

The options that you can send into the request function

PROPERTIESDESCRIPTIONVALUE TYPEDEFAULT VALUE
url *The URL for the http requeststring
methodThe HTTP Request methodstringGET
bodyThe body to ve passed along with your requeststringobject
allowGetBodyAn option to pass body into GET requestbooleanfalse
headersThe HTTP headersobject
redirectHow to handle a redirect response. follow: Automatically follow redirects. Unless otherwise stated the redirect mode is set to follow. error: Abort with an error if a redirect occurs. manual: Caller intends to process the response in another context.
followmaximum redirect count. 0 to not follow redirectnumber20
compresssupport gzip/deflate content encoding. false to disablebooleantrue
agentThe Http agent to use to do the request.stringfunction
timeoutThe time limit on which the request should respondnumber
sizethe maximum response body size in bytes. 0 to disablenumber0
formThe object to pass formdata into. If passed, it converts the header to have content-type 'application/x-www-form-urlencoded'object
skipThrowForStatusReturn request status instead of throwing error on request directlybooleanfalse
let {clientId, questionId, answer} = bundle.inputData;
return sdk.request({
    method: "POST",
    url: `YOUR_URL_HERE`,
    body: {
        clientId,
        questionId,
        answer,
    },
}).then((res) => {
    if (res.status === 201) {
        return res.data;
    }
    throw new Error("Something went wrong");
});

sdk.store

This object provides you the access to an asynchronous key-value store that is provided by our SDK. With this object, you can have access to the get and set methods.

set

With the set method, you can add key value pairs into our key-value store.

const res = await sdk.store.set("key", "value");

Arguments

ARGUMENTSDESCRIPTIONVALUE TYPE
keyAn unique identifier for some item of data to be storedstring
valueThe actual value to be stored into the store.string

Return

It returns you the value that you just stored.

Keep in mind that if you try to set the value of the key that already exists, it replaces the old value with the new one.

The key and value both are of type string. So it is recommended that you don't store huge data sets by converting them into strings

const key = bundle.inputData.key;
const value = bundle.inputData.sessionId;
const res = await sdk.store.set(key, value);
sdk.console.log(`${res} has been stored with key: ${key}`);

The above code stores the data we get from bundle.inputData and logs them in the console.

sdk.require

The require function provides user with features provided by the Node.js require method. It basically can be used to import modules, JSON, and local files. Modules can be imported from node_modules.

const moduleName = sdk.require("MODULE_NAME");

Arguments

ARGUMENTSDESCRIPTIONVALUE TYPE
MODULE_NAMEThe name of the module that you want to import into your methodstring

Example

function removeDuplicates(val) {
    if (!val) return val;
    if (val.length < 2) return val;
    const _ = sdk.require('lodash');
    return _.uniq(val);
}

If you want to import modules that are not a part of your app then make sure that they are added in the package.json file of your app so that they will be part of your node_modules.