​Sipuni telephony connection

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



2. Click on API:


3. Fill in the "Channel name" – a mandatory field that will be displayed in the general list of channels in the "Channels" section and when working with tickets.
4. Check the boxes next to "JSON request" and "send in UTF-8" and click "Save".
5. After saving the channel, copy the secret key and transfer the created channel to the monitored ones. Click "Save" again.


On the Usedesk side, the settings are completed; go to the personal Sipuni telephony account.
IMPORTANT! Integration is available in the extended Sipuni plan.
6. Go to your Sipuni account> "Integrations" section> Usedesk.

7. In the "Authorization in Usedesk" section, insert the saved secret key from item 5 into the "API Key" field.

8. In the "Users" section, match the employees who will participate in the integration. The list of employees is automatically pulled from Usedesk after saving the API key.


You can create an internal number in the section "Design" – "Employees".


Immediately you will be prompted to install an extension or communicator.


If you are installing an extension, then to enter, enter the key from the "Edit employee" card (example in the previous screenshot).



Check again that all users are assigned correctly and save the configuration settings


Important!
Sipuni's support department will answer your questions about purchasing a room, setting up schemes, adding employees, etc. Also, some details on telephony work are described in the Sipuni Knowledge Base.

And we will continue to configure the integration.
9. Next, you need to configure the integration scenario.
Features that can be configured in telephony:
  • Incoming call to an external number
  • Incoming call to an extension number
  • Outgoing call
  • Pick up the phone while incoming call
  • Incoming call skipped
  • Outgoing not answered
  • Incoming call ended
  • Outgoing calln ended
  • CRM call


Using the Sipuni Function, you can use the already written code or write your own and start using the integration entirely.

An example of written code (Sipuni functions) for a script:

  • Client verification by phone number (if there is no phone, a client is created).
  • Checking a ticket for a client (if there is no open ticket for a client, create a new one).
  • Adding a call to a ticket with a comment and a link to the post.

Incoming call to an external number

1. Go to the "Settings" - "Integrations" section and click the node.


2. Select Usedesk as CRM.

3. Click "Create function" - "Incoming call to the external number."

4. Before writing any code, clear the page. Add this code:


const SipuniUsedeskApi = require ('@ sipuni / usedesk');

<< $ 1> $ 1> function findClient (api, phone) {
const clients = await api.clients.list ({
offset: 0,
query: phone, // search by subscriber number
search_type: 'full_match',
});
if (clients.length> 0) {
return clients [0];
}
return null;
}
<< $ 1> $ 1> function createClient (api, phone) {
const client = await api.clients.create ({
name: phone,
phone: phone,
});
client.id = client.client_id; // add the id field, like the client returned from findClient
return client;}
<< $ 1> $ 1> function findOpenTicket (api, client) {
const found = await api.tickets.list ({
client_id: client.id,
fstatus: '1,8', // Tickets with statuses Open and New
});
if (! found.length) {
return null;
} else {
return found [0]; // Take the first ticket
}
}
<< $ 1> $ 1> function createTicket (api, client, phone) {
const ticket = await api.tickets.create ({
subject: `Incoming call from $ {phone}`,
message: 'Incoming request',
client_id: client.id,
});
ticket.id = ticket.ticket_id;
return ticket;
}
module.exports = << $ 1> $ 1> (args) => {
const phone = args.call_args.src_num;
const token = args.settings.api_key;
let client = null;
let isExistingClient = true;
let ticket = null;
const api = new SipuniUsedeskApi ({token});
// Looking for a client, create if not found
client = await findClient (api, phone);
if (! client) {
client = await createClient (api, phone);
isExistingClient = false;
}
// We are looking for an open or new ticket, if not found, create
if (isExistingClient) {
ticket = await findOpenTicket (api, client);
}
if (! ticket) {
ticket = await createTicket (api, client, phone);
}
// Return an object with client and ticket identifiers,
// and the existing_client flag - the client was found or created
// This information is useful in other functions
return {
client_id: client.id,
ticket_id: ticket.id,
existing_client: isExistingClient,
};
};

5. After adding the code, use a test run. Wait in the "Saved" log for the result of the function.



6. After completing the steps, click "Publish."




Internal call ended

1. Go to the "Settings" - "Integrations" section and click the node.


2. Select Usedesk as CRM.


3. Click "Create function" - "Incoming call ended."

4. Before writing any code, clear the page. Add this code:
const SipuniUsedeskApi = require ('@ sipuni / usedesk');
const moment = require ('moment');
// Returns the duration of the conversation in the format 00:01:34
function getCallDuration (callArgs) {
// timestamp and call_answer_timestamp come as strings, so we convert to a number
const conversationStarted = parseInt (callArgs.call_answer_timestamp, 10);
const conversationEnded = parseInt (callArgs.timestamp, 10);
const seconds = conversationEnded - conversationStarted;
return moment.utc (seconds * 1000) .format ('HH: mm: ss');
}
<< $ 1> $ 1> function createComment (api, ticketId, callArgs) {
const duration = getCallDuration (callArgs);
const message = ` Recording a conversation $ {duration}`;
const comment = await api.tickets.createComment ({
ticket_id: ticketId,
message,
});
comment.id = comment.comment_id;
return comment;
}
module.exports = << $ 1> $ 1> (args) => {
let commentId = null;
const ticketId = args.context.ticket_id; // get the id of the ticket from the call context
if (ticketId) {
const token = args.settings.api_key;
const api = new SipuniUsedeskApi ({token});
const comment = await createComment (api, ticketId, args.call_args);
commentId = comment.id;
}
return {
comment_id: commentId,
};

};

5. After adding the code, use a test run. Wait in the "Saved" log for the result of the function.
6. After completing the steps, click "Publish."




Missed incoming call

1. Go to the "Settings" - "Integrations" section and click the node.


2. Select Usedesk as CRM.

3. Click "Create function" - "Missed incoming."



4. Before writing any code, clear the page. Add this code:

const SipuniUsedeskApi = require ('@ sipuni / usedesk');
const moment = require ('moment');
<$ 1 data-verified = "redactor"> function createComment (api, ticketId, callArgs) {
const message = `Incoming call missed`;
const comment = await api.tickets.createComment ({
ticket_id: ticketId,
message,
});
comment.id = comment.comment_id;
return comment;
}
module.exports = <$ 1 data-verified = "redactor"> (args) => {
let commentId = null;
const ticketId = args.context.ticket_id; // get the id of the ticket from the call context
if (ticketId) {
const token = args.settings.api_key;
const api = new SipuniUsedeskApi ({token});
const comment = await createComment (api, ticketId, args.call_args);
commentId = comment.id;
}
return {
comment_id: commentId,
};
};

5. After adding the code, use a test run. Wait in the "Saved" log for the result of the function.


6. After completing the steps, click "Publish."




Outgoing call

1. Go to the "Settings" - "Integrations" section and click the node.
2. Select Usedesk as CRM.

3. Click "Create function" - "Outgoing call."


4. Before writing any code, clear the page. Add this code:

const SipuniUsedeskApi = require ('@ sipuni / usedesk');
function findClient (api, phone) {
const clients = await api.clients.list ({
offset: 0,
query: phone, // search by subscriber number
search_type: 'full_match',
});
if (clients.length> 0) {
return clients [0];
}
return null;
}
function createClient (api, phone) {
const client = await api.clients.create ({
name: phone,
phone: phone,
});
client.id = client.client_id; // add the id field, like the client returned from findClient
return client;
}
function findOpenTicket (api, client) {
const found = await api.tickets.list ({
client_id: client.id,
fstatus: '1,8', // Tickets with statuses Open and New
});
if (! found.length) {
return null;
} else {
return found [0]; // Take the first ticket
}
}
function createTicket (api, client, phone) {
const ticket = await api.tickets.create ({
subject: `Outgoing call to $ {phone}`,
message: 'Outgoing request',
client_id: client.id,
});
ticket.id = ticket.ticket_id;
return ticket;
}
module.exports = (args) => {
const phone = args.call_args.dst_num;
const token = args.settings.api_key;
let client = null;
let isExistingClient = true;
let ticket = null;
const api = new SipuniUsedeskApi ({token});
// Looking for a client, create if not found
client = await findClient (api, phone);
if (! client) {
client = await createClient (api, phone);
isExistingClient = false;
}
// We are looking for an open or new ticket, if not found, create
if (isExistingClient) {
ticket = await findOpenTicket (api, client);
}
if (! ticket) {
ticket = await createTicket (api, client, phone);
}
// Return an object with client and ticket identifiers,
// and the existing_client flag - the client was found or created
// This information is useful in other functions
return {
client_id: client.id,
ticket_id: ticket.id,
existing_client: isExistingClient,
};
};
5. After adding the code, use a test run. Wait in the "Saved" log for the result of the function.



6. After completing the steps, click "Publish."




Outgoing call ended

1. Go to the "Settings" - "Integrations" section and click the node.
2. Select Usedesk as CRM.

3. Click "Create function" - "Outgoing conversation ended."
4. Before writing any code, clear the page. Add below code:

const SipuniUsedeskApi = require ('@ sipuni / usedesk');
const moment = require ('moment');
// Returns the duration of the conversation in the format 00:01:34
function getCallDuration (callArgs) {
// timestamp and call_answer_timestamp come as strings, so we convert to a number
const conversationStarted = parseInt (callArgs.call_answer_timestamp, 10);
const conversationEnded = parseInt (callArgs.timestamp, 10);
const seconds = conversationEnded - conversationStarted;
return moment.utc (seconds * 1000) .format ('HH: mm: ss');
}
function createComment (api, ticketId, callArgs) {
const duration = getCallDuration (callArgs);
const message = `Conversation recording $ {duration}`;
const comment = await api.tickets.createComment ({
ticket_id: ticketId,
message,
});
comment.id = comment.comment_id;
return comment;
}
module.exports = (args) => {
let commentId = null;
const ticketId = args.context.ticket_id; // get the id of the ticket from the call context
if (ticketId) {
const token = args.settings.api_key;
const api = new SipuniUsedeskApi ({token});
const comment = await createComment (api, ticketId, args.call_args);
commentId = comment.id;
}
return {
comment_id: commentId,
};
};
5. After adding the code, use a test run. Wait in the "Saved" log for the result of the function.



6. After completing the steps, click "Publish."




Missed call

1. Go to the "Settings" - "Integrations" section and click the node.
2. Select Usedesk as CRM.

3. Click "New Function" - "Outgoing Not Answered."


4. Before writing any code, clear the page. Add this code:

const SipuniUsedeskApi = require ('@ sipuni / usedesk');
const moment = require ('moment');
function createComment (api, ticketId, callArgs) {
const message = `Couldn't get through`;
const comment = await api.tickets.createComment ({
ticket_id: ticketId,
message,
});
comment.id = comment.comment_id;
return comment;
}
module.exports = (args) => {
let commentId = null;

const ticketId = args.context.ticket_id; // get the id of the ticket and call context


if (ticketId) {
const token = args.settings.api_key;
const api = new SipuniUsedeskApi ({token});
const comment = await createComment (api, ticketId, args.call_args);
commentId = comment.id;
}
return {
comment_id: commentId,
};
};
5. After adding the code, use a test run. Wait in the "Saved" log for the result of the function.



6. After completing the steps, click "Publish".


How the configured script looks in Usedesk:

  • Client verification by phone number (if there is no phone, a client is created).
  • Checking a ticket for a client (if there is no open ticket for a client, create a new one).
  • Adding a call to a ticket with a comment and a link to the post.

In the customer card, the new customer's name will be filled in with a phone number; you can rename it if necessary.


- The subject in the ticket card will correspond to the call: incoming/outgoing call.

- The ticket card will display the time and signature of the ticket creation:

  • Outgoing request - for outgoing calls;
  • Incoming request - for incoming calls


- A record of missed incoming calls will be included in the ticket card.
- The ticket card will contain a recording of the conversation, which can be listened to.
If you do not get through to the client, there will be no conversation recording in the request card, only the outgoing call.

Was the article helpful?

Yes No