question

rick-smith2386 avatar image
rick-smith2386 asked Phong Vu answered

Recieve SMS using C#

How can I receive SMS using C#


So I can send SMS using the api. But can't seem to find a way to receive them. Is it even possible? At this point I think I need something like ngrok? But Im not sure where to start.


Thanks In Advance

rest apisms and text messaging
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered
If you want to receive sms in real time, check this:  https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral.Test/SubscripotionT... It is powered by PubNub, so you don't need ngrok.

Alternatively, you can check WebHook which does require a public address:  https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral.Test/WebHookTest.cs

Or if you don't need real time sms notification, you can retrieve sms via HTTP GET /restapi/v1.0/account/~/extension/~/message-store

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

rick-smith2386 avatar image
rick-smith2386 answered
Tyler

Thanks again! I will try these.
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

rick-smith2386 avatar image
rick-smith2386 answered Tyler Liu commented
Tyler

Hmm I just plugged it in and tried the PubNub variant, It has an error can't quite figure out.

 await subscription.Register(); //Throws Object Reference not set to instance of object...



10 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image Tyler Liu ♦ commented ·
Throws Object Reference not set to instance of object
Which object did it mean?

Maybe you can provide more information, preferably the full code snippet.
0 Likes 0 ·
rick-smith2386 avatar image rick-smith2386 commented ·
Thanks. It appears to be Subscription is the problem, here is the code

ublic async void MessageNotifications()
        {
            RestClient rc = new RestClient("XXXNNNN", "XXXNNN123");           
            var subscription = rc.Restapi().Subscription().New();
            subscription.EventFilters.Add("/restapi/v1.0/account/~/extension/~/message-store");
            var presenceCount = 0;
            subscription.PresenceEvent += (sender, args) => {
                presenceCount += 1;
                Console.WriteLine(args.Message);
            };
            var messageCount = 0;
            var messageNotificationCount = 0;
            subscription.NotificationEvent += (sender, args) => {
                messageCount += 1;
                var message = args.message;
                Console.WriteLine(message);
                dynamic jObject = JObject.Parse(message);
                var eventString = (string)jObject.@event;
                if (new Regex("/account/\\d+/extension/\\d+/message-store").Match(eventString).Success)
                {
                    messageNotificationCount += 1;
                    var bodyString = JsonConvert.SerializeObject(jObject.body);
                    var messageEvent = JsonConvert.DeserializeObject<MessageEvent>(bodyString);
                //For now just show it...  
               txtIncomingSMS.text =  bodyString;
                   
                }
            };
            var statusCount = 0;
            subscription.StatusEvent += (sender, args) => {
                statusCount += 1;
                Console.WriteLine(args.Message);
            };
            await subscription.Register(); //Throws Object Reference not set to instance of object
}


0 Likes 0 ·
rick-smith2386 avatar image rick-smith2386 commented ·
At this point, and based on  almost non-existent documentation I am making wild guesses here;
I think what is missing from this is - PubNubMessaging.Core;  . Am I in the ball park? Where is this thing located I tried PubNub.com but could not really find any reference to Pubnubmessaging.core.

Thanks again?


0 Likes 0 ·
Tyler Liu avatar image Tyler Liu ♦ commented ·
You code seems pretty fine to me because it is just the code from the test cases.

At the moment I have no idea why it doesn't work. Let me write a program to reproduce the issue.
0 Likes 0 ·
Tyler Liu avatar image Tyler Liu ♦ commented ·
I have written a sample project and it runs pretty smooth without the "Object Reference not set to instance of object" error.  https://github.com/tylerlong/RingCentralPasswordFlow/tree/PubNub

Could you please have a try? Pay attention it is the PubNub branch instead of master branch.

The code is pretty simple:  https://github.com/tylerlong/RingCentralPasswordFlow/blob/PubNub/RingCentralPasswordFlow/Program.cs#...
0 Likes 0 ·
Show more comments
Phong Vu avatar image
Phong Vu answered
Hi Rick,

Alternatively, check out this quick start for what you want to achieve.

https://developers.ringcentral.com/guide/notifications/quick-start/pubnub/c-sharp
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys