Having Issue When Using C# SDK and using Presence API

  • 2
  • Question
  • Updated 2 years ago
Hi everyone,

I am having an issue with C# sdk and Pubnub Presence api. I can subscribe to Presence but no data is being received when ring central phone changes its state. I have created an equivalent javascript application which subscribes with same sub key and channel and it gets the notifications whenever ring central phone changes its state (whenever agent goes in a call or a call ends or agent changes its state manually) but this is not happening for Asp.net C# application. Right now I am using sample application from github provided by Pubnub but it doesn't work

Note: all the communication is encrypted and I have specified the cipher key as well 

Thanks
Photo of Mutahir Mehmood

Mutahir Mehmood

  • 100 Points 100 badge 2x thumb

Posted 2 years ago

  • 2
Photo of Benjamin Dean

Benjamin Dean

  • 8,602 Points 5k badge 2x thumb
We are aware of these blocking issues which have been reported in the Github repository for the RingCentral C# SDK, and we are working on prioritizing this work to get our developers unblocked.

In the meantime, the RingCentral C# SDK is open source, and we welcome contributions from our community. Please see the Github Issue tracker for reported issues and follow the contribution documentation to become an active contributor this open source project. https://github.com/ringcentral/ringcentral-csharp/issues

This issue has more activity on this thread, please consider this post deprecated and use the original post for any content or new relating issues: https://devcommunity.ringcentral.com/ringcentraldev/topics/long-running-subscription-issues-c-sdk
Photo of John Wang

John Wang, Official Rep

  • 4,798 Points 4k badge 2x thumb
There are some open issues on the C# SDK but those only come into effect in a long-running subscription. The code provided below will subscribe to and receive decrypted events using the C# SDK.
Photo of VB

VB, Official Rep

  • 1,310 Points 1k badge 2x thumb
Please have a look at this code. I have subscription and presence working in C#. This should help :

https://github.com/vyshakhbabji/ringcentral-csharp-demo/blob/master/ConsoleApplication1/Program.cs
Photo of Mutahir Mehmood

Mutahir Mehmood

  • 100 Points 100 badge 2x thumb
Hi Thanks for your help but, I am little confused when I was looking at your code. dont we have to use pubnub.Presence<string>()  method when we are looking to get notified on Presence? but instead you just used pubnub.Subscribe<string>(). Can you please clarify this? I am a newbie to pubnub
Photo of VB

VB, Official Rep

  • 1,310 Points 1k badge 2x thumb
You are subscribing to presence event through subscription API. Please read the document here for subscription API . https://developer.ringcentral.com/api-docs/latest/index.html

The subscription api will help you subscribe to presence api so that you dont have to poll for presence api. 
Photo of John Wang

John Wang, Official Rep

  • 4,840 Points 4k badge 2x thumb
Using the C# SDK, the following example code should get you started. I just verified it working and receiving decrypted events. Since the C# SDK will automatically decrypt the PubNub payload, you should not need to specify any cipher keys yourself.

The following app is a console app that will listen to presence events and print out state changes. I've also added this example code here.

http://ringcentral-sdk-csharp-simple.readthedocs.org/en/latest/notifications/Subscription/

using System;

using RingCentral.SDK;
using RingCentral.Subscription;

namespace console.subscribe
{
    class MainClass
    {
        static void ActionOnNotification(object message) {
            var receivedMessage = message.ToString();
            Console.WriteLine(receivedMessage);
        }

        static void ActionOnConnect(object message){
            var receivedMessage = message.ToString();
            Console.WriteLine(receivedMessage);
        }

        static void ActionOnError(object error) {
            var receivedMessage = error.ToString();
            Console.WriteLine(receivedMessage);
        }

        public static void Main (string[] args)
        {
            var url = "https://platform.devtest.ringcentral.com";
            var sdk = new RingCentral.SDK.SDK("myAppKey", "myAppSecret", url, "appName", "appVersion");
            sdk.GetPlatform().Authorize("myUsername", "myExtension", "myPassword", true);

            var sub = new SubscriptionServiceImplementation(){ _platform = sdk.GetPlatform()};
            sub.AddEvent("/restapi/v1.0/account/~/extension/~/presence");

            sub.Subscribe(ActionOnNotification, ActionOnConnect, ActionOnError);

            Console.ReadLine();
            Console.WriteLine("Hello World!");
        }
    }
}
(Edited)