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

Adds 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

cancelTransferToUser

Copy URL
cancelTransferToUser(): 

boolean

Cancels transferring a client to the user.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 // Transfer a client to the queue
 kit.transferToUser({user_id: 12});
 //...
 // Condition for canceling the transfer to the queue
 const shouldCancel = true;
 if (shouldCancel) {
   kit.cancelTransferToUser();
 }
 // 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
   await kit.dbCommit();
 } catch(err) {
   console.log(err);
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    Promise<boolean>

dbDelete

Copy URL
dbDelete(key: 

string

,
scope:

DataBaseType

):

boolean

Deletes a value from the database scope, if the key already exists. Available only after laodDatabase(). execution.

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

Parameters

Returns

  • type:

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

deleteCustomData

Copy URL
deleteCustomData(name: 

string

):

boolean

Delete custom data.

 const kit = new VoximplantKit(context);
 kit.deleteCustomData('my_data');
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

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

getAvatarReply

Copy URL
getAvatarReply(): 

AvatarMessageObject

|

null

Gets an avatar reply

 const kit = new VoximplantKit(context);
 if (kit.isCall()) {
  const reply = kit.getAvatarReply();
  console.log('Reply: ', reply);
 } // End of function
 callback(200, kit.getResponseBody());

Returns

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

getConversationUuid

Copy URL
getConversationUuid(): 

string

|

null

Get the conversation uuid. Only applicable when called from a channel or when calling the function as a callbackUri in the sendMessageToAvatar method.

 const kit = new VoximplantKit(context);
 if (kit.isMessage() || kit.isAvatar()) {
   const uuid = kit.getConversationUuid();
   //... do something
 }
 // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    string

  • type:

    null

getDfKey

Copy URL
getDfKey(id: 

number

):

ObjectType

|

null

Get DialogFlow key by id.

 const kit = new VoximplantKit(context);
 const dfKey = kit.getDfKey(15);
 if (dfKey) {
   console.log('My DF key:', dfKey);
   //... do something
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • id:

    number

Returns

getDfKeysList

Copy URL
getDfKeysList(): 

string[]

Gets a list of available DialogFlow keys

 const kit = new VoximplantKit(context);
 const dfKeyList = kit.getDfKeysList();
 console.log('My DF keys:', dfKeyList);
 //... do something // End of function
 callback(200, kit.getResponseBody());

Returns

  • type:

    string[]

getEnvVariable

Copy URL
getEnvVariable(name: 

string

):

string

|

null

Gets an environment variable by name. More details here.

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

A static method used outside the function body that gets environment variables.

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

Parameters

  • name:

    string

Returns

  • type:

    string

  • type:

    null

getFunctionUriById

Copy URL
getFunctionUriById(id: 

number

):

string

|

null

Get the function URI by its id.

 const kit = new VoximplantKit(context);
 const uri = kit.getFunctionUriById(31);
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • id:

    number

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

getMessageObject

Copy URL
getMessageObject(): 

ChannelDataObject

|

ObjectType

Gets a message object.

 const kit = new VoximplantKit(context);
 if (kit.isMessage() || kit.isAvatar()) {
   const messageObject = kit.getMessageObject();
   // ...do something
 }
 // End of function
 callback(200, kit.getResponseBody());

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(): 

CallDataObject

|

ChannelDataObject

|

undefined

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[]>

Gets 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

isAvatar

Copy URL
isAvatar(): 

boolean

The function is called by the avatar.

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

Returns

  • type:

    boolean

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(id: 

number

):

boolean

Removes a skill by id.

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

Parameters

  • id:

    number

    Name of the skill to remove

Returns

  • type:

    boolean

replaceTags

Copy URL
replaceTags(tags: 

number[]

):

boolean

Replaces all tags.

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

Parameters

  • tags:

    number[]

Returns

  • type:

    boolean

setCustomData

Copy URL
setCustomData(name: 

string

,
data:

unknown

):

boolean

Set custom data.

 const kit = new VoximplantKit(context);
 kit.setCustomData('my_data', {a: 1, b 'some text'}); // [12, 34]
 // End of function
 callback(200, kit.getResponseBody());

Parameters

  • name:

    string

  • data:

    unknown

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

setReplyWebChatInlineButtons

Copy URL
setReplyWebChatInlineButtons(buttons: 

WebChatInlineButton[]

):

boolean

Adds buttons for the web chat channel

 const kit = new VoximplantKit(context);
 if (kit.isMessage() || kit.isAvatar()) {
   // Text is required for each button and must not be greater than 40 char.
   // The max number of buttons is 13.
   const buttons = [
     {type: 'text', text: 'Some btn text', data: 'Some btn data'}
     {type: 'text', text: 'Another btn text', data: JSON.stringify({name: 'Jon Doe', age: 30})}
   ]
   kit.setReplyWebChatInlineButtons(buttons);
 } // End of function
 callback(200, kit.getResponseBody());

Parameters

Returns

  • type:

    boolean

setSkill

Copy URL
setSkill(skill: 

SkillObject

):

boolean

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

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (kit.isCall()) {
   kit.setSkill({skill_id: 234, level: 5});
 } else if (kit.isMessage()) {
   kit.setSkill({skill_id: 35, level: 3});
   kit.transferToQueue({queue_id: 72});
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

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

transferToUser

Copy URL
transferToUser(user: 

UserInfo

):

boolean

Transfers a client to the user. Only for text channels and Avatar.

 // Initialize a VoximplantKit instance
 const kit = new VoximplantKit(context);
 if (this.isMessage() || this.isAvatar()) {
   // Use user_id or user_email.
   kit.transferToUser({user_id: 12});
 }
 // End of function
 callback(200, kit.getResponseBody());

Parameters

Returns

  • type:

    boolean

version

Copy URL
version(): 

string

|

void

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

  • type:

    void

Props

avatar

Copy URL
avatar: 

Avatar