[SalesForce] OpenCTI enableClickToDial does not invoke any callback in Salesforce Classic Console

I have a Lightning instance which contains a Salesforce Classic Console App using Contacts, Leads and Accounts tabs. Inside of it I have an OpenCTI Phone which is made of Lightning components. During the initialization of one of the components I invoke a function which should enable a click-to-dial feature. Here's a simple code:

enableClickToDial : function(cmp) {
    const clickToDialListener = function(response) {
            console.log("Click-to-dial listener");
    }

    var callback = function (response) {
       console.log("Callback invoked");
       if (response.result) {
          alert('Click to dial was enabled.');
       } else {
          alert('Click to dial was not enabled.');
       }
    };

    sforce.interaction.cti.enableClickToDial(callback);

    console.log("Enabling finished");
}

However, the callback is not invoked. I don't know what's happening since an "Enabling finished" message is printed out to the console – that means there was no error in enableClickToDial function and interpreter got to the next statement.

Also, a phone icon is grayed out:

enter image description here

Does anyone know the reason why is it not working properly?

Best Answer

For anyone struggling with an issue of OpenCTI API methods not getting invoked without any visible cause - in our case this turned out to be the issue with Call Center configuration: the CTI Adapter URL was configured like so: apex/<softPhonePageName>, without the leading slash.

This was not an issue in terms of the SoftPhone page being displayed, but when trying to call the OpenCTI API, there is a check there, that compares the call origin with the configured CTI Adapter URL and without the leading slash it considered the domains to be different.

Changing the CTI Adapter URL to /apex/<softPhonePageName> resolved the issue.

The annoying part was that I had to debug the unminified source of the InteractionFramework to find it out - the error about the origin mismatch does not seem to surface anywhere in the JS console or the page.

Related Topic