SDK postMessage Communications
The postMessage command, which enables cross-origin communication between window objects. For example, can be opened as a pop-up spawned within a browser window and can enable call controls, agent state controls, and the ability to receive interaction data without requiring development around the SDK or the use of REST API calls to the platform.
Software Delivery Kit (SDK) supports front-end messaging between the interface and third-party applications when is launched from within the third-party application, such as with a custom customer relationship management application (CRM). The messages are communicated with aThis implementation requires assistance from your software or website development team. If you do not have a developer available, please contact your CxEngage account representative.
Launching
For postMessage
to be able to communicate with a different origin, must be opened in the parent page:
skylight = window.open(
'https://skylight.cxengage.net/?standalonePopup=true&skylightController=true',
'skylight',
'width=400,height=800'
);
Note the This is what |
Initiating Communication
When data.topic: 'skylight/loaded'
. This is the only postMessage
that performs with targetOrigin: '*'
. To set the targetOrigin
that will use for all subsequent messages, the parent page will post { skylightController: true, controllerInit: true }
to . will use the source on this message as its targetOrigin
, and respond with a message with data.topic: 'skylight/target-origin-defined'
. This confirms that the secure two-way communication path has been established.
window.addEventListener('message', event => {
// Verify Skylight's origin and syntax here
const data = event.data;
if (data.topic === 'skylight/loaded') {
// This message tells Skylight to use this event's source for subsequent messages
skylight.postMessage({
skylightController: true,
controllerInit: true
}, 'https://skylight.cxengage.net');
} else if (data.topic === 'skylight/target-origin-defined') {
console.log(
'Communication with Skylight is secure.' +
'We can now send messages back and forth.'
);
}
});
To receive all other events and messages from
, the same listener as the one above, used to initiate the communication, can be used:window.addEventListener('message', event => {
// Same as above code block here
const data = event.data;
console.log(data.topic, data.error, data.response);
if (data.topic === 'cxengage/interactions/work-accepted-received') {
interactionId = data.response.interactionId;
}
// More topic/event handling here
});
To post commands to
:skylight.postMessage({
skylightController: true,
module: 'interactions',
command: 'endWrapup',
data: {
interactionId
}
}, 'https://skylight.cxengage.net');
skylight.postMessage({
skylightController: true,
module: 'interactions',
subModule: 'voice'
command: 'dial',
data: {
phoneNumber: '+2505550199'
direction: 'agent-initiated',
interactionMetadata: {
campignName: 'Callback Campaign',
campaignId: '5738012',
listName: "Agent 007's List",
listId: '7674467',
listSource: 'Salesforce',
customer: {
name: 'John Doe',
stateCode: 'AZ',
zipCode: '85310'
country: 'US'
timezone: 'US/Arizona',
},
},
},
}, 'https://skylight.cxengage.net');
For this command script:
|
Known issue: Please note that the following commands are not currently fully supported:
|
|
If you need any of these, please contact your CxEngage account representative.
Developer Documentation
Complete developer documentation for the modules, commands, and potential error messages is available here.
Demo
Download a demo file here.