In this document you can find the step-by-step explanation of how you can load a embedded version of UCP from your website.
The most easily way to load UCP from your site is by using an iframe HTML tag. Lets go to the explanation of how to use this powerful HTML tag in your site to load the application.
Lets use the following vocabulary to talk about your website and UCP
In the HTML document of your website (webParent) or inside your component if you are working with React you should insert the following:
<iframe title='ucp' src='{webUCP}' allow='notifications; microphone' />
Lets talk about the attributes of the iframe
Important: Always use the URL of UCP with the /login path at the end, otherwise the content of UCP will not be loaded successfully
Incorrect usage: https://qvoice.ca/ucp
Correct usage: https://qvoice.ca/ucp/login
Important: If you do not want to grant these two permissions to UCP you should take into account that incoming and outgoing calls are not going to work
Finally you should see UCP embedded inside your website, for sure you can customise the styles of the iframe.
Important: We strongly suggest to use a minimum size of 300 pixels x 300 pixels in order to give the UI enough space to normally display the elements
Enjoy Embedded UCP in your website!
Embedded UCP sends call events to the parent window so you can subscribe to these events by opening a listener in the parent window.
Below you can find the examples of the events:
{
"type": "UCP_INCOMING_CALL",
"payload": {
'call_id': "8a9e7f1e-af22-4257-84d2-043e56dc0d1e",
"caller_id_name": "John Doe",
"caller_id_number": "1234567890",
"queue_id": "1234567890",
"queue_name": "Test Queue",
"campaign_name": "Test Campaign",
"lead_id": "1234567890",
"user_id": "1234567890",
"user_ext": "1000"
}
},
{
"type": "UCP_ANSWERED_CALL",
"payload": {
'call_id': "8a9e7f1e-af22-4257-84d2-043e56dc0d1e",
"caller_id_name": "John Doe",
"caller_id_number": "1234567890",
"queue_id": "1234567890",
"queue_name": "Test Queue",
"campaign_name": "Test Campaign",
"lead_id": "1234567890",
"user_id": "1234567890",
"user_ext": "1000"
}
},
{
"type": "UCP_HANGUP_CALL",
"payload": {
'call_id': "8a9e7f1e-af22-4257-84d2-043e56dc0d1e",
"user_id": "1234567890",
"user_ext": "1000"
}
},
{
"type": "UCP_OUTGOING_CALL",
"payload": {
'call_id': "8a9e7f1e-af22-4257-84d2-043e56dc0d1e",
'callee_id_number': "1237",
"user_id": "1234567890",
"user_ext": "1000"
}
}
window.addEventListener('message', function(event) {
if (event.data.type === "UCP_INCOMING_CALL") {
console.log('INCOMING CALL FROM UCP: ', event.data)
} else if (event.data.type === "UCP_ANSWERED_CALL") {
console.log('ANSWERED CALL FROM UCP: ', event.data)
} else if (event.data.type === "UCP_HANGUP_CALL") {
console.log('HUNGUP CALL FROM UCP: ', event.data)
} else if (event.data.type === "UCP_OUTGOING_CALL") {
console.log('OUTGOING CALL FROM UCP: ', event.data)
}
}, false)
The parent window can also send messages to the embedded UCP to trigger specific actions. This allows you to control UCP functionality directly from your website.
You can initiate calls from the parent window by sending a message to the embedded UCP iframe. Here's how to do it:
document.getElementById('ucp-iframe').contentWindow.postMessage({
type: 'MAKE_CALL',
payload: {
destination: '1234'
}
}, '*')
Important considerations:
iframe ID: Make sure your iframe has an id
attribute so you can reference it. For example:
<iframe id="ucp-iframe" title='ucp' src='{webUCP}' allow='notifications; microphone' />
Message structure: The message must follow the specific format with type
and payload
properties.
Destination: The destination
field should contain the phone number you want to call.
Origin parameter: The '*'
parameter allows the message to be sent to any origin. For security reasons, you might want to specify the exact UCP domain instead.
Currently, the following message types are supported:
Note: More message types will be added in future versions to support additional UCP functionality.
Here's a complete example showing how to add a button that makes a call from the parent window:
<iframe id="ucp-iframe" title='ucp' src='https://qvoice.ca/ucp/login' allow='notifications; microphone' />
<button onclick="makeCall('1234567890')">Call 123-456-7890</button>
<script>
function makeCall(destination) {
const iframe = document.getElementById('ucp-iframe');
iframe.contentWindow.postMessage({
type: 'MAKE_CALL',
payload: {
destination: destination
}
}, '*');
}
</script>
Now you can control UCP functionality directly from your parent website!