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
Call Forwarding .NET SDK Unexpected behavior
Tags: sdk
Dec 18, 2019 at 6:47am   •   5 replies  •  0 likes
Jeff Craig

I've set up an application that subscribes to the account telephony webhook, looks up information in our database about the caller, and then attempts to route the call to the person the caller is trying to reach by forwarding the call to that Ring Central user's direct phone number. I am using the .NET SDK. Below is the method that runs the call forwarding action. This all works as expected in the sandbox environment, however when I promote it to production I am getting some very unexpected behavior and was hoping for some help to figure out why.

1) On the sandbox environment, when the call is forwarded to a direct line, a new call with a different telephonySessionId is created and the account telephony webhook is pinged multiple times with this new call and the forwarded call rings the soft phone associated with the the direct line

2) On production, when the call is forwarded to a direct line of a Ring Central extension, the phone just rings and rings and no new phone call is pinging the account telephony webhook. The soft phone associated with the direct line of the forwarded call does not ring. After several minutes, a recording says this call could not be connected and hangs up. I can confirm that a properly formatted non null phone number is being used and there are no exceptions being generated in the code.

3) On production, if instead of forwarding the call to the direct line of a Ring Central extension, I instead forward it to an external number, for instance, my cell phone. It works as expected. That is to say the behavior on production matches the behavior on sandbox and my cell phone rings.

Really the only difference between our production and sandbox environments is that we leverage call queues and ring groups in production and we don't in sandbox. Could this be the issue?

Thanks!


 public async Task<bool> ForwardPhoneCall(string phoneNumber, string userName, string firmId, string telephonySessionId, string partyId, string toNumber, ForwardedCall forwardedCall)
        {
            try
            {
                if (phoneNumber != null)
                {
                    RingCentralCredentials creds = await GetRingCentralCredentials(firmId);
                    ForwardTarget forwardTarget = new ForwardTarget() { phoneNumber = phoneNumber.FormatPhoneNoSpaces() };

                    var rc = new RestClient(creds.clientID, creds.clientSecret, creds.serverURL);
                    rc.token = await Authorize(creds, rc, firmId);

                    await rc.Restapi().Account().Telephony().Sessions(telephonySessionId).Parties(partyId).Forward().Post(forwardTarget);

                    return true;
                }

                return false;
            }
            catch(Exception ex)
            {
                throw;
            }
        }


4 Answers
answered on Sep 3, 2020 at 6:33am  

I'm seeing similiar behavior, where on production, if I try to forward a call to a Ring Central extension (using the e164 formatted number), the API says it succeeded, but the actual call gets an error recording. (And yes, the extension can otherwise recieve calls normally.)

Forwaring to a non-Ring Central extension, like my cell phone, works just fine.



 0
answered on Jan 21, 2020 at 1:49pm  

@Jeff Craig It looks like your application use case is very similar to ours. In our case, the API responds with a TAS-106 error when the incoming call is from an internal RingCentral number; in other words, you cannot forward from one internal RC line to another internal RC line; try calling from your cell phone into direct number/soft phone in production; not sure if this helps with what you are seeing.

But I also wanted to reach out to see whether you are experiencing some other issues that we have observed with our app, .NET Core console. Every now and then, events seem to get stuck in a queue within the subscription and the callback does not get fired until "something" else (it is not clear what) happens to get the queue moving again, resulting in a flurry of calls attempting to be forwarded but error out because the actual calls associated with the events no longer exist. Does this sound familiar? Here's what the subscription code:


                var subscription = new Subscription(_tokenService.AppRestClient, eventFilters, async message =>
                {
                    dynamic jObject = JObject.Parse(message);
                    System.Console.WriteLine(jObject["body"]);
                    forwardingNumber = "";
                    string toNumberInternalId = jObject.body.extensionId.ToString();
                    //int calledExtension = GetCalledExtension(toNumberInternalId);
                    if (jObject.body.activeCalls != null)
                    {
                        string sessionId = jObject.body.activeCalls[0].telephonySessionId.ToString();
                        string fromNumber = jObject.body.activeCalls[0].from.ToString();
                        string toNumber = jObject.body.activeCalls[0].to.ToString();
                        string toName = jObject.body.activeCalls[0].toName.ToString();
                        string partyId = jObject.body.activeCalls[0].partyId.ToString();
                        string telephonyStatus = jObject.body.telephonyStatus.ToString();
                        if (telephonyStatus == "Ringing")  //cannot forward if CallConnected or NoCall
                        {
                            if (sessionId != null && partyId != null)
                            {
er);
                                    forwardingNumber = extensionE164;
                                    System.Console.WriteLine($"========>Retrieved routing; now forwarding {fromNumber} to {forwardingNumber}\n");
                                    forwardingNumber = "";
                                    if (extensionE164 != "" && extensionE164 != string.Empty)
                                    {
                                        try
                                        {
                                            var rapi = await _tokenService.AppRestClient.Restapi().Account().Telephony().Sessions(sessionId)
                                                .Parties(partyId)
                                                .Forward().Post(new ForwardTarget
                                                {
                                                    phoneNumber = extensionE164
                                                });
                                            System.Console.WriteLine($"========>Forwarded call from {fromNumber} to {extensionE164}\n");
                                    }
                                    catch (RestException ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                        //throw new Exception($"Attempt to forward invalid or inactive call; the call may have been disconnected. \n{ex.Message}");
                                    }
                                }
                            }
                        }
                    }
                });



 0
answered on Jan 21, 2020 at 11:07am  

Jeff, it looks like your application use case is very similar to ours. In our case, the API responds with a TAS-106 error when the incoming call is from an internal RingCentral number, in other words, you cannot forward from one internal RC line to another internal RC line; try calling from your cell phone into direct number/soft phone in production; not sure if this helps with what you are seeing.

But I also wanted to reach out to see whether you are experiencing some other issues that we have observed with our app, .NET Core console. Every now and then, events seem to get stuck in a queue within the subscription and the callback does not get fired until "something" else (it is not clear what) happens to get the queue moving again, resulting in a flurry of calls attempting to be forwarded but error out because the actual calls associated with the events no longer exist. Does this sound familiar? Here's what the subscription code:


                var subscription = new Subscription(_tokenService.AppRestClient, eventFilters, async message =>
                {
                    dynamic jObject = JObject.Parse(message);
                    System.Console.WriteLine(jObject["body"]);
                    forwardingNumber = "";
                    string toNumberInternalId = jObject.body.extensionId.ToString();
                    //int calledExtension = GetCalledExtension(toNumberInternalId);
                    if (jObject.body.activeCalls != null)
                    {
                        string sessionId = jObject.body.activeCalls[0].telephonySessionId.ToString();
                        string fromNumber = jObject.body.activeCalls[0].from.ToString();
                        string toNumber = jObject.body.activeCalls[0].to.ToString();
                        string toName = jObject.body.activeCalls[0].toName.ToString();
                        string partyId = jObject.body.activeCalls[0].partyId.ToString();
                        string telephonyStatus = jObject.body.telephonyStatus.ToString();
                        if (telephonyStatus == "Ringing")  //cannot forward if CallConnected or NoCall
                        {
                            if (sessionId != null && partyId != null)
                            {
er);
                                    forwardingNumber = extensionE164;
                                    System.Console.WriteLine($"========>Retrieved routing; now forwarding {fromNumber} to {forwardingNumber}\n");
                                    forwardingNumber = "";
                                    if (extensionE164 != "" && extensionE164 != string.Empty)
                                    {
                                        try
                                        {
                                            var rapi = await _tokenService.AppRestClient.Restapi().Account().Telephony().Sessions(sessionId)
                                                .Parties(partyId)
                                                .Forward().Post(new ForwardTarget
                                                {
                                                    phoneNumber = extensionE164
                                                });
                                            System.Console.WriteLine($"========>Forwarded call from {fromNumber} to {extensionE164}\n");
                                    }
                                    catch (RestException ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                        //throw new Exception($"Attempt to forward invalid or inactive call; the call may have been disconnected. \n{ex.Message}");
                                    }
                                }
                            }
                        }
                    }
                });



 0
answered on Dec 19, 2019 at 10:29am  

That's not correct. It should be able to forward to any valid number. In my test, it works with both numbers on both sandbox and production environments.

Can you double check the extension 118 can call and receive calls from a soft phone? You can also test by forward a call manually to that extension (using a RingCentral mobile app or a desktop soft-phone)


 0



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