Rate this page:

VoximplantKit

Constructors

constructor

Copy URL

Voximplant Kit class, a middleware for working with functions.

module.exports = async function(context, callback) {
 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Some code
 console.log(Date.now());
 // End of function
 callback(200, kit.getResponseBody());
}

Parameters

  • context:

    ContextObject

Methods

addTags

Copy URL
addTags(tags: 

number[]

):

boolean

Add tags by id.

 const kit = new VoximplantKit(context);
 kit.addTags([12, 34]);
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • tags:

    number[]

Returns

  • type:

    boolean

apiProxy

Copy URL
apiProxy(url: 

string

,
data:

any

):

Promise<unknown>

Allows you to use the Voximplant Kit API.

// Example of getting an account name
 const kit = new VoximplantKit(context);
 try {
    const { success, result } = await kit.apiProxy('/v2/account/getAccountInfo');
    if (success) {
       console.log('Account name', result.domain.name);
    }
 } catch (err) {
    console.log(err);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • url:

    string

    URL address

  • data:

    any

Returns

  • type:

    Promise<unknown>

cancelFinishRequest

Copy URL
cancelFinishRequest(): 

boolean

Reopens the client's request.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (this.isMessage()) {
   kit.finishRequest();
 }
 // ...
 // Сondition for reopening
 const shouldCancel = true;
 if (shouldCancel) {
   kit.cancelFinishRequest();
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    boolean

cancelTransferToQueue

Copy URL
cancelTransferToQueue(): 

boolean

Cancels transferring a client to the queue.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Transfer a client to the queue
 kit.transferToQueue({queue_id: null, queue_name: 'some_queue_name'});
 //...
 // Condition for canceling the transfer to the queue
 const shouldCancel = true;
 if (shouldCancel) {
   kit.cancelTransferToQueue();
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    boolean

dbCommit

Copy URL
dbCommit(): 

Promise<boolean>

Adds changes to the database. Available only after loadDatabases() execution.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 try {
   // Connect available databases
   await kit.loadDatabases();
   // Get a value from the function scope by key
   const _test = kit.dbGet('test_key', 'function')
   // If there is no data
   if (_test === null) {
     kit.dbSet('test_key', 'Hello world!!!', 'function');
   }
   // Write changes to the database
   kit.dbCommit()
 } catch(err) {
   console.log(err);
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    Promise<boolean>

dbGet

Copy URL
dbGet(key: 

string

,
scope:

DataBaseType

):

string

|

null

Gets a value from the database scope by key. Available only after loadDatabases() execution.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 try {
   // Connect available databases
   await kit.loadDatabases();
   // Get the value from the function scope by key
   const _test = kit.dbGet('test_key', 'function')
   console.log(_test);
 } catch(err) {
   console.log(err);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • key:

    string

    Key

  • Defaults on:  "global"

    Database scope

Returns

  • type:

    string

  • type:

    null

dbGetAll

Copy URL
dbGetAll(scope: 

DataBaseType

):

ObjectType

|

null

Gets the whole database scope by name. Available only after loadDatabases() execution.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 try {
   // Connect available databases
   await kit.loadDatabases();
   // Read contents from the global scope
   const global_scope = kit.dbGetAll('global');
   console.log(global_scope)
 } catch(err) {
   console.log(err);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

Returns

dbSet

Copy URL
dbSet(key: 

string

,
value:

any

,
scope:

DataBaseType

):

boolean

Adds a value to the database scope or updates it if the key already exists. Available only after loadDatabases() execution.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 try {
   // Connect available databases
   await kit.loadDatabases();
   // Get a value from the function scope by key
   const _test = kit.dbGet('test_key', 'function')
   // If there is no data
   if (_test === null) {
     kit.dbSet('test_key', 'Hello world!!!', 'function');
   }
   // Write changes to the database
   kit.dbCommit()
 } catch(err) {
   console.log(err);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • key:

    string

    Key

  • value:

    any

    Value

  • Defaults on:  "global"

    Database scope

Returns

  • type:

    boolean

deleteVariable

Copy URL
deleteVariable(name: 

string

):

boolean

Deletes a variable by name.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 kit.deleteVariable('my_var');
 // Console will print null
 console.log(kit.getVariable('my_var'));
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

    Variable name

Returns

  • type:

    boolean

finishRequest

Copy URL
finishRequest(): 

boolean

Closes the client's request.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (this.isMessage()) {
   kit.finishRequest();
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    boolean

getCallData

Copy URL
getCallData(): 

CallObject

|

null

Gets all call data.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (kit.isCall()) {
   const call = kit.getCallData();
   // Get the phone number from which the call is made
   console.log(call.phone_a);
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

getCallHeaders

Copy URL
getCallHeaders(): 

ObjectType

|

null

Gets call headers.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (kit.isCall()) {
   const headers = kit.getCallHeaders();
   console.log(headers);
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

getEnvVariable

Copy URL
getEnvVariable(name: 

string

):

string

|

null

Gets an environment variable by name

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 const my_var = kit.getEnvVariable('myEnv');
 if (my_var) {
   console.log(my_var);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

    Variable name

Returns

  • type:

    string

  • type:

    null

Static

getEnvironmentVariable

Copy URL
getEnvironmentVariable(name: 

string

):

string

|

null

Gets an environment variable by name (Static method).

 const my_var = VoximplantKit.getEnvironmentVariable('myEnv');
 if (my_var) {
   console.log(my_var);
 }

Parameters

  • name:

    string

Returns

  • type:

    string

  • type:

    null

getIncomingMessage

Copy URL
getIncomingMessage(): 

MessageObject

|

null

Gets an incoming message.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Check if the function is called from a channel
 if (kit.isMessage()) {
   // Get text from an incoming message
   const message = kit.getIncomingMessage();
   console.log(message.text);
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

getPriority

Copy URL
getPriority(): 

number

Gets call priorities.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Return a number from 0 to 10
 const priority = kit.getPriority();
 if (priority === 10) {
   // Something to do
 } else if (priority === 5) {
   // Something to do
 } else {
   // Something to do
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    number

getResponseBody

Copy URL
getResponseBody(): 

{SKILLS: SkillObject[], TAGS: number[], VARIABLES: ObjectType}

|

{payload: MessagePayloadItem[], text: string, variables: ObjectType}

Gets a function response. Needs to be called at the end of each function.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // End of function
 callback(200, kit.getResponseBody());

Returns

getSkills

Copy URL
getSkills(): 

SkillObject[]

Gets all skills.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (this.isCall()) {
   const all_skills = kit.getSkills();
   console.log('All skills:', all_skills);
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

getTags

Copy URL
getTags(withName: 

boolean

):

Promise<number[]>

|

Promise<GetTagsResult[]>

Get tags

 const kit = new VoximplantKit(context);
 await kit.getTags(); // [12, 34]
 await kit.getTags(true); // [{id: 12, tag_name: 'my_tag'}, {id: 34, tag_name: 'my_tag2'}]
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • withName:

    boolean

    Optional

    If the argument is true, it returns the array with the id and tag names. Otherwise, it will return the array with the id tags

Returns

getVariable

Copy URL
getVariable(name: 

string

):

string

|

null

Gets a variable by name

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 const my_var = kit.getVariable('my_var');
 if (my_var) {
   console.log(my_var);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

    Variable name

Returns

  • type:

    string

  • type:

    null

getVariables

Copy URL
getVariables(): 

ObjectType

Gets all variables.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 const all_vars = kit.getVariables();
 console.log(all_vars);
 // End of function
 callback(200, kit.getResponseBody());

Returns

isCall

Copy URL
isCall(): 

boolean

The function is called from a call.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (kit.isCall()) {
   console.log('This function is called from the call')
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    boolean

isMessage

Copy URL
isMessage(): 

boolean

The function is called from a message.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (kit.isMessage()) {
   console.log('This function is called from the channel');
   const message = kit.getIncomingMessage();
   //...
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    boolean

loadDatabases

Copy URL
loadDatabases(): 

Promise<void>

Loads the databases available in the scope.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 try {
   // Connect available databases
   await kit.loadDatabases();
   // Read contents from the global scope
   const global_scope = kit.dbGetAll('global');
   console.log(global_scope)
 } catch(err) {
   console.log(err);
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    Promise<void>

removeSkill

Copy URL
removeSkill(name: 

string

):

boolean

Removes a skill by name.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (this.isCall()) {
   kit.removeSkill('some_skill_name');
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

    Name of the skill to remove

Returns

  • type:

    boolean

replaceTags

Copy URL
replaceTags(tags: 

number[]

):

boolean

Replace all tags

 const kit = new VoximplantKit(context);
 kit.replaceTags([12, 34]);
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • tags:

    number[]

Returns

  • type:

    boolean

setPriority

Copy URL
setPriority(value: 

number

):

boolean

Sets the call priority. The higher the priority, the less time a client will wait for the operator's response.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Transfer a client to the queue
 kit.transferToQueue({queue_id: null, queue_name: 'some_queue_name'});
 // Set the highest priority
 kit.setPriority(10);
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • value:

    number

    Priority value, from 0 to 10

Returns

  • type:

    boolean

setReplyMessageText

Copy URL
setReplyMessageText(text: 

string

):

boolean

Sets a reply message text.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Check if the function is called from a channel
 if (kit.isMessage()) {
   // Get text from an incoming message
   const message = kit.getIncomingMessage();
   console.log(message.text);
   // Set text of the reply
   kit.setReplyMessageText('you wrote ' + message.text);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • text:

    string

    Reply text

Returns

  • type:

    boolean

setSkill

Copy URL
setSkill(name: 

string

,
level:

number

):

boolean

Adds a skill or updates it if the skill name already exists.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (this.isCall()) {
   kit.setSkill('some_skill_name', 5);
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

    Skill name

  • level:

    number

    Proficiency level

Returns

  • type:

    boolean

setVariable

Copy URL
setVariable(name: 

string

,
value:

any

):

boolean

Adds a variable or updates it if the variable name already exists.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 kit.setVariable('my_var', 'some_value');
 console.log(kit.getVariable('my_var'));
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

    Variable name

  • value:

    any

    Variable value

Returns

  • type:

    boolean

transferToQueue

Copy URL
transferToQueue(queue: 

QueueInfo

):

boolean

Transfers a client to the queue.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Transfer a client to the queue
 kit.transferToQueue({queue_id: 82});
 // End of function
 callback(200, kit.getResponseBody());

Parameters

Returns

  • type:

    boolean

version

Copy URL
version(): 

string

Gets a client’s SDK version.

 const kit = new VoximplantKit(context);
 // Get a client’s SDK version
 kit.version();
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    string