1

I want to subscribe to PushTopic events from my Open CTI application. But I can't even connect to a cometd server. Help me find the problem with my solution. Or maybe there are other ways to subscribe to Streaming API events from the Open CTI app.

Component:

<aura:component>
  <ltng:require 
  scripts="{!$Resource.cometd}"
  afterScriptsLoaded="{!c.scriptsLoaded}" />
  <aura:handler name="init" value="{!this}" action="{!c.init}" />    
  {!v.body}
</aura:component>

Controller:

scriptsLoaded : function(component, event, helper) {        
    var param = {apexClass: 'CurrentUserProvider', methodName: 'getSessionId',methodParams : '',callback: function(response) {
        if (response.success) {
            var cometd = new org.cometd.CometD();
            cometd.websocketEnabled = false;
            cometd.configure({
                url: window.location.protocol + '//' + window.location.hostname + '/cometd/40.0',
                requestHeaders: {"Authorization": 'OAuth '+response.returnValue.runApex},
                appendMessageTypeToURL : false
            });
            cometd.handshake(function(handshakeReply) {
                console.log(handshakeReply)    
            });                                   
        } 
    }};
    sforce.opencti.runApex(param);      
},

Apex class for session id access:

global class CurrentUserProvider {
  webService static String getSessionId() {
    return UserInfo.getSessionId();
  }
}

Handshake error:

 {  
   "ext":{  
      "sfdc":{  
         "failureReason":"401::Authentication invalid"
      },
      "replay":true,
      "payload.format":true
   },
   "advice":{  
      "reconnect":"none"
   },
   "channel":"/meta/handshake",
   "id":"1",
   "error":"403::Handshake denied",
   "successful":false
}
2
  • Have you tried taking the session ID and using it in a standalone cometd client? For example, with Java on the client something along the lines of BearerTokenExample from github.com/forcedotcom/EMP-Connector
    – identigral
    Commented Jun 17, 2019 at 21:58
  • Thank you for the answer. Yes, I tried to connect via java client. But I get the same error Commented Jun 18, 2019 at 10:56

0

You must log in to answer this question.