[SalesForce] How to USE sendCTIMessage in a visualforce page

Well I am trying to call a number using CTI adapter. But somehow I am unable to make it work. I used the code from Salesforce Doc(http://www.salesforce.com/us/developer/docs/api_console/index.htm)

<apex:page>
    <apex:includeScript value="/support/console/24.0/integration.js"/>
     <script type="text/javascript">

           var callback = function (result) {
              if (result.success) {
                 alert('CTI message was sent successfully!');
             } else {
                 alert('CTI message was not sent successfully.');
               }
           };

          //Note that we are using the CTI submodule here
           sforce.console.cti.sendCTIMessage('/ANSWER?LINE_NUMBER=1', callback);
     </script>
</apex:page>

But I am getting cross domain error

Uncaught SecurityError: Blocked a frame with origin
"https://cs10.salesforce.com" from accessing a frame with origin
"https://c.cs10.visual.force.com". Protocols, domains, and ports must
match.

Any Idea what I am doing wrong here ?

Best Answer

Well I guess I found a way out. Instead of using integration.js I used interaction.js which is generally used to communicate with CTI and directly called the method by just "sendCTIMessage"

<apex:page>
    <script src="/support/api/26.0/interaction.js" type="text/javascript"></script>
     <script type="text/javascript">

           var callback = function (result) {
              if (result.success) {
                 alert('CTI message was sent successfully!');
             } else {
                 alert('CTI message was not sent successfully.');
               }
           };

          //Note that we are using the CTI submodule here
           sendCTIMessage('/ANSWER?LINE_NUMBER=1', callback);
     </script>
</apex:page>

This code seems to work perfectly.

Few observations

  • To make this work the user must have Call center associated.
  • Once Call center is associated "sendCTIMessage" method gets available."sendCTIMessage" this method doesnt seem to be documented but it does works(please note it doesnt have a namespace like sforce.cti.XXX)