question

Jeff Craig avatar image
Jeff Craig asked Ivie Ogufere commented

Call Forwarding .NET SDK Unexpected behavior

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;
            }
        }


call routingc#.net sdk
3 comments
1 |1000

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

Phong Vu avatar image Phong Vu ♦♦ commented ·

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.

=> Can you do a quick test by making a direct call to the number/extension you suppose to forward the call to and see if it ring can receive the call successfully?

0 Likes 0 ·
Jeff Craig avatar image Jeff Craig Phong Vu ♦♦ commented ·

Yes, directly calling the number rings as expected.

0 Likes 0 ·
Jeff Craig avatar image Jeff Craig Phong Vu ♦♦ commented ·

So the issue with this appears to be that there is a difference between a soft phone number and a direct number. We've noticed that the call forwards correctly to users that have a direct number and does not forward correctly to users who only have soft phone numbers.


This works as expected when call is forwarded:


This user does not have any direct numbers on the Numbers tab and only has a number connected to their soft phone and this does not forward correctly:


Is this expected behavior? And if so, is there any downside to converting all of the soft phone numbers to direct numbers?


Also, the api documenation seems pretty clear that you have to use an e164 formatted phone number as the forwardTarger but I wanted to double check that there is no way to forward to an extension using the extensionId of the user or their extension number.


Thanks!

0 Likes 0 ·
1576774586301.png (156.5 KiB)
1576774635069.png (33.2 KiB)
1576774840407.png (35.6 KiB)
Phong Vu avatar image
Phong Vu answered

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)

1 |1000

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

Ivie Ogufere avatar image
Ivie Ogufere answered Ivie Ogufere edited

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}");
                                    }
                                }
                            }
                        }
                    }
                });


1 |1000

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

Ivie Ogufere avatar image
Ivie Ogufere answered Ivie Ogufere commented

@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}");
                                    }
                                }
                            }
                        }
                    }
                });


2 comments
1 |1000

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

Jeff Craig avatar image Jeff Craig commented ·

Hey Ivie,

I haven't had that particular issue, but i am now receiving the below error quite frequently whenever I attempt to forward the call, Not sure if you've seen this at all on your end but it basically tries to make the connection for several seconds before failing to forward the call.

An Error OccurredSystem.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond



0 Likes 0 ·
Ivie Ogufere avatar image Ivie Ogufere Jeff Craig commented ·

@Jeff Craig I have not run into this issue. I wonder if the error is referring to a connection other than RingCentral API; are you using an API service to connect to your back end routing logic?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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