Author Topic: Receiving CometD events on .NET  (Read 170 times)

Offline blanco

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Receiving CometD events on .NET
« on: November 23, 2018, 10:31:58 PM »
Hi everyone,
I am trying to develop AgentDesktop application on Windows Forms using Genesys Web Edition. Agent Login is OK, I am able to get/post requests to Genesys Web server but I couldn't receive any events from CometD. I didn't get any error while
handshaking with CometD. For example, when I sent this request 
POST api/v2/me/channels/voice
{
"operationName": "NotReady"
}
I can see that Agent's status is set to 'NotReady' successfully. However, there is no 'DeviceStateChangeMessage' event is coming from CometD to my application. Any suggestions? My code is below:


public void getCometDAuthenticationRequest(HttpWebRequest request)
    {
        request = (HttpWebRequest)WebRequest.Create("http://XXXX:8090/api/v2/notifications");
        request.ContentType = "application/json; charset=utf-8";
        request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(userName + ":" + password));
        request.PreAuthenticate = true;
        request.Method = "POST";
    }

    private void connectToCometD()
    {
        try
        {
            IClientSessionChannel channel;
            BayeuxClient client;

            Action<HttpWebRequest> customizeRequest = new Action<HttpWebRequest>(getCometDAuthenticationRequest);
            LongPollingTransport transport = new LongPollingTransport(null, customizeRequest);

            // Handshake
            string url = "http://XXXX:8090/api/v2/notifications";
            client = new BayeuxClient(url, new List<ClientTransport>() { transport });

            client.handshake();
            client.waitFor(1000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });

            // Subscription to channels
            channel = client.getChannel("/v2/me/*");
            channel.subscribe(new Listener());               

        }
        catch (Exception e)
        {
            MessageBox.Show("EXCEPTION ON connectToCometD(): " + e.Message);
            return;
        }           
    }

class Listener : IMessageListener
{
    public void onMessage(IClientSessionChannel channel, IMessage message)
    {                         
            MessageBox.Show("New Message received.. Message:" + message.ToString());             
    }       
}

Offline blanco

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Receiving CometD events on .NET
« Reply #1 on: November 26, 2018, 10:19:01 PM »
Any idea why I can't receive notifications from CometD? I also tried this on JavaScript and everything works fine but I couldn't do this on .NET

Offline Kubig

  • Hero Member
  • *****
  • Posts: 2508
  • Karma: 41
Re: Receiving CometD events on .NET
« Reply #2 on: November 27, 2018, 12:33:08 AM »
Are you sure about the used URI (api/v2/notification)? As I can see within documentation, following notifications are allowed:

Quote
Topics
Once your client application establishes a CometD session, you must create a subscription to one or more of the CometD topics used by the Web Services API. Your subscriptions should be based on the functionality available in your client application.

Topic   Description   MessageTypes
/v2/me/devices   Messages related to devices. Examples include changes to agent state, do-not-disturb, call forwarding, and supervisor monitoring.   
DeviceStateChangeMessage
ErrorMessage
/v2/me/calls   Messages related to calls. Examples include changes to call state, updates to call participant information, and updates to call data.   
CallStateChangeMessage
ErrorMessage
/notifications/services   Messages relating to the state of different services. If the connection to T-Server is lost, or T-Server's connection to the CTI link is broken, a message is delivered to the client.   
ServiceStateChangeMessage
/v2/me/chats   Messages related to chats. Examples include changes to chat state, updates to chat participant information, updates to chat data, and updates to chat transcript.   
ChatStateChangeMessage
MessageLogUpdated
/v2/me/emails   Messages related to emails. Examples include changes to email state and updates to email data.   
EmailStateChangeMessage
/v2/me/facebook   Messages related to Facebook interactions. Examples include changes to Facebook interaction state and updates to Facebook interaction data.   
FacebookStateChangeMessage
/v2/me/facebooksession   Messages related to private Facebook messages. Examples include changes to private Facebook message state, updates to private Facebook message data, and updates to private Facebook message transcript.   
FacebooksessionStateChangeMessage
MessageLogUpdated
/v2/me/im-sessions   Messages related to instant messaging between agents. Examples include changes to IM session state and updates to IM session data.   
IMSessionStateChangeMessage
IMLogUpdateMessage
/v2/me/openmedia   Messages related to OpenMedia interactions. Examples include changes to OpenMedia interaction state and updates to OpenMedia interaction data.   
OpenmediaStateChangeMessage
/v2/me/twitter   Messages related to Twitter interactions. Examples include changes Twitter interaction state, updates to Twitter interaction data, and updates to Twitter account following.   
TweetStateChangeMessage
TweetOperationResponse
/v2/me/workbins   Messages related to workbins. Examples include changes to workbin state and updates to workbin contents.   
WorkbinSubscriptionStateChangeMessage
WorkbinStateChangeMessage
/v2/me/workitems   Messages related to workitems. Examples include changes to workitem state and updates to workitem data.   
WorkitemStateChangeMessage
Genesys certified professional consultant (GVP, SIP, GIR and Troubleshooting)

Offline blanco

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Receiving CometD events on .NET
« Reply #3 on: November 27, 2018, 04:19:51 AM »
Hi kubig,
yes I am definitely sure about the URI. I also tried this example on Javascript with the same URI and same channel. On .NET , customizeRequest object  might be the problem and I also tried without sending customizeRequest object:
client = new BayeuxClient(url, new List<ClientTransport>() { new LongPollingTransport(null)});

nothing has changed  :( I don't know what I should try...
I am not getting any error and I can see that handshake is succeeded but still there is no event coming from CometD.


Are you sure about the used URI (api/v2/notification)? As I can see within documentation, following notifications are allowed:

Quote
Topics
Once your client application establishes a CometD session, you must create a subscription to one or more of the CometD topics used by the Web Services API. Your subscriptions should be based on the functionality available in your client application.

Topic   Description   MessageTypes
/v2/me/devices   Messages related to devices. Examples include changes to agent state, do-not-disturb, call forwarding, and supervisor monitoring.   
DeviceStateChangeMessage
ErrorMessage
/v2/me/calls   Messages related to calls. Examples include changes to call state, updates to call participant information, and updates to call data.   
CallStateChangeMessage
ErrorMessage
/notifications/services   Messages relating to the state of different services. If the connection to T-Server is lost, or T-Server's connection to the CTI link is broken, a message is delivered to the client.   
ServiceStateChangeMessage
/v2/me/chats   Messages related to chats. Examples include changes to chat state, updates to chat participant information, updates to chat data, and updates to chat transcript.   
ChatStateChangeMessage
MessageLogUpdated
/v2/me/emails   Messages related to emails. Examples include changes to email state and updates to email data.   
EmailStateChangeMessage
/v2/me/facebook   Messages related to Facebook interactions. Examples include changes to Facebook interaction state and updates to Facebook interaction data.   
FacebookStateChangeMessage
/v2/me/facebooksession   Messages related to private Facebook messages. Examples include changes to private Facebook message state, updates to private Facebook message data, and updates to private Facebook message transcript.   
FacebooksessionStateChangeMessage
MessageLogUpdated
/v2/me/im-sessions   Messages related to instant messaging between agents. Examples include changes to IM session state and updates to IM session data.   
IMSessionStateChangeMessage
IMLogUpdateMessage
/v2/me/openmedia   Messages related to OpenMedia interactions. Examples include changes to OpenMedia interaction state and updates to OpenMedia interaction data.   
OpenmediaStateChangeMessage
/v2/me/twitter   Messages related to Twitter interactions. Examples include changes Twitter interaction state, updates to Twitter interaction data, and updates to Twitter account following.   
TweetStateChangeMessage
TweetOperationResponse
/v2/me/workbins   Messages related to workbins. Examples include changes to workbin state and updates to workbin contents.   
WorkbinSubscriptionStateChangeMessage
WorkbinStateChangeMessage
/v2/me/workitems   Messages related to workitems. Examples include changes to workitem state and updates to workitem data.   
WorkitemStateChangeMessage