Rate this page:

Creating functions

Functions help you create a serverless environment that allows developers to create production-ready Voximplant Kit applications in accordance with their business requirements.

Note

In Voximplant Kit, functions are written on Node.js. You can add extra functionality by uploading the appropriate packages.

Creating a function

Use the Function section to bring together functions, dependencies, and environment variables. Using this section, you can also access all functions to edit or delete them if needed.

Important

To avoid any problems affecting the Voximplant Kit work, please, make sure you know the rules of functions in programming languages.

  1. Log in to your Voximplant Kit account.
  2. Click Functions on the right sidebar.
  3. In the Manage tab, click Blank function. The system opens the Create function window where you can configure your function.
Blank function
  1. In the Properties area, enter the name of the function.
  2. In the Code area, enter the code you want to execute.
  3. Click Create.
Create a function

Click the Logs tab to review the information about the executed code.

Learn here about methods that you can use in your functions.

By using the provided methods, you can process inbound chats in your contact center. For example, you can configure a chatbot.

Moreover, by using getVariable and setVariable methods, you can extend manipulations with variables used in a scenario.

Here are the examples of using functions in Voximplant Kit.

Creating a dependence

The system allows functions to use external Node.js modules as well as local data. Dependencies in Node.js are managed with npm and stored in a package.json file.

To import npm modules to Voximplant Kit functions, do the following:

  1. Click the Configure tab.
  2. Select the API token from the drop-down list.
  3. In the Dependencies area, enter the name of the dependence and select or enter the version of the npm module.
Create a dependance
  1. Click Save changes to install and deploy the npm module.

Adding a variable

Variables are key and value pairs that you can add to a specific environment. The system encrypts variables, so you can use them as a preferred way to store API keys, passwords, and any other data. By using variables, you don’t need to deploy a new code every time you update a variable – the system immediately reflects the new value in subsequent function executions.

To add a variable, do the following:

  1. Click the Variables tab.
  2. Click Add variable.
  3. In the Add variable dialog window, enter the name and value of the variable.
  4. Click Confirm. The system saves the variable in an .env file.
Add a variable

To edit a variable, do the following:

  1. Click the More options icon next to the required variable.
  2. Select Edit.
  3. In the dialog window that opens, edit the name or value of the variable.
  4. Click Save changes. The system updates the variable.

To delete a variable, do the following:

  1. Click the More options icon next to the required variable.
  2. Select Delete.
  3. Confirm the deletion.