Voximplant telephony integration

Contents


Telephony connection

1. To connect Voximplant telephony, go to the «Channels» section and click «Add Channel».



2. Click on «Telephony».


3. Fill in «Channel Name» — required field, which will be displayed in the general list of channels in the «Channels» section and when working with requests.
4. Choose any telephony except «Gravitel», «Mango», «Telfin».

5. In the agent's profile in the «Telephony» block, select «Voximplant», specify the login and password of the operator provided by the provider and save.


In this case, a ticket with information about the conversation will be automatically assigned to the user who communicates with the client by phone.

6. Configure access rights so that the agents you need can work in the telephony channel (important — an employee with «Internal employee» rights cannot make calls). How to set up the rights, we tell you in the article by the link.


Note! Settings may differ from operator to operator, so it is best to contact Voximplant support to help with the connection. If you need any advice or additional help, write to us at support@usedesk.com.

For more information on how telephony works in Usedesk, please see here.


Outgoing calls

For outgoing calls, the agent must have the operator's ID registered in the profile settings — it can be found in your personal account of your telephony.

To call a client, click on his/her phone number in the client's card, client list, or in the «Client info» block in the ticket card.



Incoming calls

Important! This instruction is for the Voximplant script developers. You can contact the Voximplant support team with any questions about script development.

For incoming calls, you need to implement additional features in your Voximplant app script and create a trigger in Usedesk. You can learn more about this in the documentation for developers following the link.


The Usedesk library for working with tickets

Create a new script with an arbitrary name and insert the following code:

function jsonRequest(url, cb, opt) {
    opt = opt || {};
    opt.headers = opt.headers || [];
    opt.headers.push('Content-type: application/json');
    if('json' in opt) {
        opt.postData = JSON.stringify(opt.json);
    }
    Net.httpRequest(url, cb, opt);
}
class SafeJson {
    static parse(raw) {
        try {
            return JSON.parse(raw);
        }catch(e) {
            return null;
        }
    }
}
class Usedesk {
    constructor(token, baseUrl = '<https://api.usedesk.ru>') {
        this.token = token;
        this.baseUrl = baseUrl;
    }
    createTicket(data) {
        data.api_token = this.token;
        return new Promise((resolve) => {
            jsonRequest(
                this.baseUrl + '/create/ticket', 
                ({text}) => {
                    const maybeJson = SafeJson.parse(text);
                    const result = maybeJson && 'ticket_id' in maybeJson ? maybeJson.ticket_id : -1;
                    resolve(result);
                }, 
                {method: 'POST', json: data}
            )
        })
    }
    createComment(ticketId, message) {
        const data = {
            api_token: this.token,
            ticket_id: ticketId,
            message: message,
            type: "private"
        }
        return new Promise(resolve => {
            jsonRequest(
                this.baseUrl + '/create/comment',
                ({text}) => {
                    const maybeJson = SafeJson.parse(text);
                    const result = !!maybeJson && 'comment_id' in maybeJson;
                    resolve(result);
                },
                {method: 'POST', json: data}
            )
        })
    }
}
	


Important! If you use the Usedesk on-premise version on your own server, your baseUrl will be different. Check the URL to work with the API, contacting our support — support@usedesk.com.


Implementing the library into the script

1) In the script you need to define the global constant TOKEN with your API token value and define Usedesk. How to get the token, is explained in the article at the link.

const TOKEN = 'Your Usedesk API token';
const usedesk = new Usedesk(TOKEN);
	


2) When a call is successful, the CallEvents.Connected callback is executed. Thus, when a connection is established, a ticket should be created in Usedesk. Below is an example of a piece of code that will create a ticket in a channel, specified in the channel_id parameter, with the following data:

  • A ticket subject: a new call with an agent %a login user in Voximplant%;
  • A message in a ticket: a new successful call from a number %a client number%;
  • A ticket will be bound to a client with a name %a client number%, a number will be added to a card.
inc.addEventListener(CallEvents.Connected, <<<<<<<<$1>$1>$1>$1>$1>$1>$1>$1> () => {
      sessionTicketId = await usedesk.createTicket({
        subject: "New call with agent " + inc.username(),
        message: "New successful call from the number " + inc.callerid(),
        client_name: inc.callerid(),
        client_phone: inc.callerid(),
        channel_id: 12345
      })
  })<<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1><<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></<$1>$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1></$1>
    
	


3) You can also add a processor for the cases, when a connection fails for some reasons:

inc.addEventListener(CallEvents.Disconnected, <<<<<<<$1>$1>$1>$1>$1>$1>$1> () => {
    if(sessionTicketId > 0) {
      await usedesk.createComment(sessionTicketId, 'Failed to connect');
    }
  });
});<<$1>$1><<$1>$1><<$1>$1>    </<$1>$1></<$1>$1></<$1>$1></<$1>$1></$1></$1></$1></$1></$1></$1></$1></$1>
    
	


Creating triggers in Usedesk

In Usedesk you can use triggers to match a user in Voximplant with an agent in Usedesk. Below there is an example of the trigger, when calls for the Voximplant user with the nickname Smith will be assigned to the agent Neo in Usedesk: