Question

Call Forwarding .NET SDK Unexpected behavior

  • 18 December 2019
  • 4 replies
  • 2110 views

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 replies

Userlevel 1

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)

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}
");
                                    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}
");
                                    }
                                    catch (RestException ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                        //throw new Exception($"Attempt to forward invalid or inactive call; the call may have been disconnected. 
{ex.Message}");
                                    }
                                }
                            }
                        }
                    }
                });


@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}
");
                                    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}
");
                                    }
                                    catch (RestException ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                        //throw new Exception($"Attempt to forward invalid or inactive call; the call may have been disconnected. 
{ex.Message}");
                                    }
                                }
                            }
                        }
                    }
                });


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.


Reply