JavaScript API
Control the Web Dialler programmatically using the global PhoenixWidget object.
Overview
Once the widget script is loaded, a PhoenixWidget object is available on the window. Use it to trigger calls, hang up, or remove the widget entirely — all from your own JavaScript code.
// Start a call
PhoenixWidget.call('+919876543210');
// Hang up the current call
PhoenixWidget.hangup();
// Remove the widget from the page
PhoenixWidget.destroy();
Methods
PhoenixWidget.call(number)
Starts an outbound call to the given number.
| Parameter | Type | Description |
|---|---|---|
number | string | Phone number to call. Use E.164 format (e.g., +919876543210) for best results. |
// Call a customer
PhoenixWidget.call('+919876543210');
If the widget panel is closed, calling this method will open it automatically and start the call.
PhoenixWidget.hangup()
Ends the currently active call. If no call is in progress, this has no effect.
PhoenixWidget.hangup();
PhoenixWidget.destroy()
Removes the widget from the page entirely — disconnects any active call, tears down the UI, and cleans up resources.
PhoenixWidget.destroy();
After calling destroy(), the widget is gone. To reinitialize it, you'll need to reload the page or re-add the script tag.
Command Queue
If you need to call widget methods before the script has finished loading, use the command queue pattern:
<script>
window.PhoenixWidget = window.PhoenixWidget || { q: [] };
// Queue a call — it'll execute after the widget initializes
PhoenixWidget.q.push(['call', '+919876543210']);
</script>
<!-- Widget script loads later -->
<script
src="https://cdn.superfone.co.in/widgets/phoenix/phoenix-widget.js"
data-api-key="USER_WEB_DIALLER_TOKEN"
></script>
Supported commands in the queue: call, hangup, destroy.
Integration Examples
Click-to-Call Button
Add a "Call" button next to customer records in your CRM:
<button onclick="PhoenixWidget.call('+919876543210')">
Call Customer
</button>
Call from a Contact List
document.querySelectorAll('[data-phone]').forEach(function (el) {
el.addEventListener('click', function () {
var phone = el.getAttribute('data-phone');
PhoenixWidget.call(phone);
});
});
Auto-Call on Page Load
Trigger a call when a specific page loads (e.g., a support ticket page):
window.PhoenixWidget = {
config: {
apiKey: 'USER_WEB_DIALLER_TOKEN',
onReady: function () {
var customerPhone = document.getElementById('customer-phone').textContent;
if (customerPhone) {
PhoenixWidget.call(customerPhone.trim());
}
},
},
};
Hang Up After a Timeout
// Auto-disconnect after 5 minutes
PhoenixWidget.call('+919876543210');
setTimeout(function () {
PhoenixWidget.hangup();
}, 5 * 60 * 1000);
Error Handling
If the widget hasn't initialized yet, methods will log a warning to the console. Use the onReady callback (see Configuration) to ensure the widget is ready before making API calls.
window.PhoenixWidget = {
config: {
apiKey: 'USER_WEB_DIALLER_TOKEN',
onReady: function () {
// Safe to call widget methods here
console.log('Widget ready — calling is available');
},
onError: function (error) {
console.error('Widget error:', error.message);
// Show a fallback UI or notify the user
},
},
};
For questions about the JavaScript API, advanced integration patterns, or custom requirements, contact Superfone customer support at hello@superfone.in.