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

Offline blanco

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Receiving CometD events on .NET
« on: November 23, 2018, 01: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: 9
  • Karma: 0
Re: Receiving CometD events on .NET
« Reply #1 on: November 26, 2018, 01: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: 2752
  • Karma: 44
Re: Receiving CometD events on .NET
« Reply #2 on: November 26, 2018, 03:33:08 PM »
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[/quote]

Offline blanco

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Receiving CometD events on .NET
« Reply #3 on: November 26, 2018, 07:19:51 PM »
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.


[quote author=Kubig link=topic=11192.msg50988#msg50988 date=1543246388]
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[/quote]
[/quote]

Offline nauman.khalid

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: Receiving CometD events on .NET
« Reply #4 on: November 10, 2020, 09:23:21 PM »
Hi Blanco, seems like this is an old post. I hope you were able to resolve your issue. I am stuck in a similar situation and needed some help. I haven't been able to get the handshake set up and needed help with how I can do that. I am using JavaScript for my client. Any inputs would be appreciated. Thanks!

Offline ryusuf

  • Full Member
  • ***
  • Posts: 108
  • Karma: 0
Re: Receiving CometD events on .NET
« Reply #5 on: September 04, 2022, 06:59:21 AM »
Hi Blanco,

We are facing similar issue with cometD handshake when trying to develop WDE connector for a web application. The cometD handshake throws 403 handshake denied error. We are developing the client in .NET.

If you could share your insights on whether you were able to solve the issue you had and how you established successful handshake would be helpful.

I know its an old thread, hope someone could share their thoughts.

Best Regards,
Rashid Yusuf