News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
How to phone number track with c# SDK?
Tags: internet explorer
Jun 22, 2022 at 11:51am   •   3 replies  •  0 likes
Juneeight gull

I need to develop an application to Track live call numbers when the RingCentral phone app is ringing. How can I do that with C# SDK?




#User story#


We have developed a c#, .net windows-based application for the Pizza shop. They need to integrate their RingCentral app with this new application to track customer call numbers. When ringing the RingCentral phone app, We need to get the customer's phone number and check whether that number is already registered with our DB. Could please help in order to get this done? I am looking for a sample code.

3 Answers
answered on Jun 24, 2022 at 11:07am  

Also, your sample is for Send SMS, Not to Get caller number. It would be great if you can share a sample code that I can use to get the call number when ringing the phone.




 0
on Jun 24, 2022 at 11:10am   •  0 likes

Code is almost the same. You just replace the event filter. And parse the response for the number.

on Jun 24, 2022 at 1:06pm   •  0 likes

I m not clear with this? How/Where can I do this?

And parse the response for the number.

on Jun 24, 2022 at 1:37pm   •  0 likes

I see you are already doing the right thing in your code.

on Jun 25, 2022 at 10:01am   •  0 likes

Then what should be the issue that it is not subscribing when receiving a call?

answered on Jun 24, 2022 at 11:05am  

Hi Tyler,


I checked your sample. But I received the below error. Could you please advise how can I get this off?

1656093750257.png


Also, I have given all the permissions.


1656093813917.png


Here is my code snippet


1656093896741.png


 0
on Jun 24, 2022 at 11:11am   •  0 likes

it means you authorize your app using extension 1, and try to subscribe to events for extensions 2. But extension 1 and extension 2 don't belong to the same company.

on Jun 24, 2022 at 12:02pm   •  0 likes

I tried with the below event URL. Could you please let me know, what are the correct values for the accountId & extensionId parameters? I just use my sandbox user name and extension. If those are wrong where can I find the correct details?

"/restapi/v1.0/account/{accountId}/extension/{extensionId}/telephony/sessions"


1656097276678.png


Also, I used the same credentials, clientId & secret for the RestClient constructor & Authorize.

on Jun 24, 2022 at 12:04pm   •  1 likes

Make an API call to /restapi/v1.0/account/~/extension

to get all the extensions, where you can find the extension Ids. If you only need the ID for the current extension, use "~" as ID.

on Jun 24, 2022 at 12:29pm   •  0 likes

I execute this API and found the accountID. But still not found a way to get the extentionId?

var extInfo = await rc.Restapi().Account("~").Extension("~").Get();
var accId = extInfo.account.id;
 var extention = extInfo.extensionNumber;


Also, there is no error receiving when I execute the below code, but it does not subscribe when I answer a call even with the 301 extension?



 var extInfo = await rc.Restapi().Account("~").Extension("~").Get();
var accId = extInfo.account.id;
var pubNubExtension = new PubNubExtension();

await rc.InstallExtension(pubNubExtension);

 var eventFilters = new[]{
  $"/restapi/v1.0/account/{accId}/extension/~/telephony/sessions"
 };

var messages = new List<string>();
var messageStoreMessageCount = 0;
var subscription = await pubNubExtension.Subscribe(eventFilters, message => {
       messages.Add(message);
       dynamic jObject = JObject.Parse(message);
       var eventString = (string)jObject.@event;
       if (new Regex("/account/\\d+/extension/\\d+/message-store").Match(eventString).Success)
                        {
                            messageStoreMessageCount += 1;
                            var messageEvent = JsonConvert.DeserializeObject<MessageEvent>(message);
 var uuid = (messageEvent.uuid);
 var body = (messageEvent.body);
                        }
 });


var subscriptionInfo = subscription.SubscriptionInfo;
//await SendSms(rc); feature does not enable for Send SMS
await Task.Delay(20000);

subscriptionInfo = await subscription.Refresh();
 await subscription.Revoke();
on Jun 24, 2022 at 1:38pm   •  0 likes

extensionid = extInfo.id

on Jun 25, 2022 at 10:00am   •  0 likes

I got it. And no error when I execute the code. But it's never subscribing when a call is received. Could you please check the above code snippet and advice me why this is not working as expected?

on Jun 26, 2022 at 10:35pm   •  0 likes

I am on vacation this week. Please create a ticket https://developers.ringcentral.com/support/create-case if the issue persists.

Do not just copy the code. You need to print the message.

  1. var subscription = await pubNubExtension.Subscribe(eventFilters, message => { Console.WriteLine(message)
  2. }

And do not Refresh or Revoke

It is the unit test. You don't need those logic because you are not writting an unit test.

And subscription happens once and only once. When there is incoming call, your code will NOT subscribe (because it already did that). Instead, the code in the callback function will be executed. That's why I let you print the message. Otherwise even the messages come you don't know.

I will try to write a sample project after my vacation. Thanks.

answered on Jun 22, 2022 at 12:03pm  

I tried with the below code and got the error.

// https://developers.ringcentral.com/my-account.html#/applications // Find your credentials at the above url, set them as environment variables, or enter them below


RestClient rc = new RestClient( Environment.GetEnvironmentVariable("clientId"), Environment.GetEnvironmentVariable("clientSecret"), false );

await rc.Authorize( Environment.GetEnvironmentVariable("username"), Environment.GetEnvironmentVariable("extension"), Environment.GetEnvironmentVariable("password") );

var r = await rc.Restapi().ClientInfo().SipProvision().Post(); // PROCESS RESPONSE


-----------------------------------------------------


{ "errorCode": "SPR-112", "message": "Client edition is not compatible with current Brand", "errors": [ { "errorCode": "SPR-112", "message": "Client edition is not compatible with current Brand" } ] }


 0
on Jun 22, 2022 at 1:59pm   •  0 likes

Why did you invoke await rc.Restapi().ClientInfo().SipProvision().Post()?

It's for low level SIP and it's probably not what you need.


To get customer phone number, when they call you, you need to create a subscription: https://github.com/ringcentral/RingCentral.Net/blob/master/RingCentral.Tests/SubscriptionTest.cs

And here is the event: https://developers.ringcentral.com/api-reference/Extension-Telephony-Sessions-Event




A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us