Example Usage
Below is a simple example demonstrating the SDK usage.
// Ensure the widget is ready before accessing its methods.
window.LlaProSdk("getWidget");
window.addEventListener("llapro_phonewidget_on_ready", (event) => {
// Open the widget.
window.LlaProSdk("getWidget").maximize();
console.log(window.LlaProSdk("getWidget").isOpen);
// => true
// Minimize the widget.
window.LlaProSdk("getWidget").minimize();
console.log(window.LlaProSdk("getWidget").isOpen);
// => false
// Check if phone number editing is enabled.
console.log(window.LlaProSdk("getWidget").isPhoneNumberEditable);
// => true or false depending on the current state
// Listen to call start and end events.
window.addEventListener("llapro_phonewidget_on_call_start", (event) => {
const callData = event.detail;
console.log("Call started:", callData);
});
window.addEventListener("llapro_phonewidget_on_call_end", (event) => {
const callData = event.detail;
console.log("Call ended:", callData);
});
// Prepare a call without starting it.
const callTo = "+56900000000";
const optionalData = {
contactExternalId: "contact-id-in-external-system",
opportunityExternalId: "opportunity-id-in-external-system",
analysisConfigId: "analysis-config-to-use-in-llamadapro",
};
window.LlaProSdk("getWidget").prepareCall({
callTo,
optionalData,
});
// Disable phone number editing to prevent users from changing the number.
window.LlaProSdk("getWidget").enablePhoneNumberEditing(false);
// Start the call using the prepared data.
window.LlaProSdk("getWidget").startCall();
// Clear the prepared call data by calling prepareCall empty.
window.LlaProSdk("getWidget").prepareCall();
// Re-enable phone number editing if necessary.
window.LlaProSdk("getWidget").enablePhoneNumberEditing(true);
// Alternatively, start a call directly
window.LlaProSdk("getWidget").startCall({
callTo: "+56912345678",
optionalData: {
contactExternalId: "another-contact-id",
},
});
});
Important: Make sure the SDK is initialized before using it.