question

Nate Breeden avatar image
Nate Breeden asked Phong Vu commented

Call Handling C# Issue

Hey everyone,


Having an issue with the below snippet, the error I'm getting is below as well. Have verified that fwdQueueExt.extensionNumber actually contains the extension it should go to, but still receive the below error. Also receiving the same error if I add the queue's extensionID/uri into fwdQueueExt.id/fwdQueueExt.uri, but don't think that matters because parameters.transfer doesn't take an ID/uri



Error:

System.NullReferenceException: Object reference not set to an instance of an object.
   at MyAppName.Name.<RCAPICalls>d__4.MoveNext() in \\ServerName\Scripts\AppName\RCTermUser.cs:line 430

Line 430 is:

parameters.transfer.extension = fwdQueueExt;



Code (removed personal info with x)

CallHandlingExtensionInfo fwdQueueExt = new CallHandlingExtensionInfo { };

if (callQueues.records.Count() > 0) { fwdQueueExt.extensionNumber = callQueues.records[0].extensionNumber.ToString(); }
else if (RINGCENTRAL_USERNAME == "+1xxxxxxxxx") { fwdQueueExt.extensionNumber = "xxxx"; }
else { fwdQueueExt.extensionNumber = "xxxx"; };

var parameters = new CreateAnsweringRuleRequest();
parameters.enabled = true;
parameters.type = "Custom";
parameters.name = "Forwarding Calls";
var schedule = new ScheduleInfo();
var weeklyRanges = new WeeklyScheduleInfo();
TimeInterval meetingTime = new TimeInterval();
meetingTime.from = "00:00";
meetingTime.to = "00:00";
weeklyRanges.monday = new TimeInterval[] { meetingTime };
weeklyRanges.tuesday = new TimeInterval[] { meetingTime };
weeklyRanges.wednesday = new TimeInterval[] { meetingTime };
weeklyRanges.thursday = new TimeInterval[] { meetingTime };
weeklyRanges.friday = new TimeInterval[] { meetingTime };
weeklyRanges.saturday = new TimeInterval[] { meetingTime };
weeklyRanges.sunday = new TimeInterval[] { meetingTime };

schedule.weeklyRanges = weeklyRanges;
parameters.schedule = schedule;
parameters.callHandlingAction = "TransferToExtension";
parameters.transfer.extension = fwdQueueExt;

var custRuleVar = await rc.Restapi("v1.0").Account("~").Extension(newDevID.extension.id.ToString()).AnsweringRule().Post(parameters);


Already have a script that re-assigns a terminated users extension to a temp user, but trying to make a custom rule to forward that temp users extension to the former users call queue.


Also tried going through some code samples, but no avail (that's where I got most of the above)

rest apicall handling
1 |3000

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 answered Nate Breeden commented

Can you just leave the account id and extension id blank to make sure that you are creating a custom answering rule for the extension that authenticated the app.

rc.Restapi().Account().Extension().AnsweringRule().Post(parameters);
3 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.

Nate Breeden avatar image Nate Breeden commented ·

Hey Phong,


Same issue when leaving those blank, it seems like it is not even getting to the API call and is stopping on the below line.

parameters.transfer.extension = fwdQueueExt;


Also tried adding the following this morning to make sure I have everything it could possibly want, but still receive an error on that same as above (just with the new variable). I'm sure I'm just doing something wrong lol, just not sure what

var transferInfo = new CallHandlingExtensionInfo ();
transferInfo.extensionNumber = callQueues.records[0].extensionNumber.ToString();
transferInfo.id = callQueues.records[0].id.ToString();
transferInfo.uri = callQueues.records[0].uri;

parameters.callHandlingAction = "TransferToExtension";
parameters.transfer.extension = transferInfo;
0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Nate Breeden commented ·

I think it's because of the extension object you passed to the transfer parameter. The documentation is vague and there are redundant params. Can you try to assign the call queue extension id to the extension.id, instead of using the extension number?

0 Likes 0 ·
Nate Breeden avatar image Nate Breeden Phong Vu ♦♦ commented ·

Same error when passing the call queue's ID to the extension.id (snippet below just to make sure we're on the same page)

transferInfo.id = callQueues.records[0].id.ToString();

parameters.callHandlingAction = "TransferToExtension";
parameters.transfer.extension.id = transferInfo.id;


I'm pretty stumped, the documentation says 'If "TransferToExtension" is specified for callHandlingAction, the transfer parameter object is required.'

https://developers.ringcentral.com/guide/voice/call-routing/manual/user-answering-rules

The only thing in the transfer parameter is the id?

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered Phong Vu commented

This code works for me. It's not the same action but can you try it first, then change the action and set the transfer to see which part potentially causes the problem.

var parameters = new CreateAnsweringRuleRequest();
parameters.enabled = true;
parameters.type = "Custom";
parameters.name = "My weekly meetings";
var schedule = new ScheduleInfo();
var weeklyRanges = new WeeklyScheduleInfo();
TimeInterval day = new TimeInterval();
day.from = "09:00";
day.to = "10:00";
weeklyRanges.monday = new TimeInterval[] { day };

day = new TimeInterval();
day.from = "10:00";
day.to = "15:00";
weeklyRanges.friday = new TimeInterval[] { day };

schedule.weeklyRanges = weeklyRanges;
parameters.schedule = schedule;
parameters.callHandlingAction = "TakeMessagesOnly";

var response = await rc.Restapi().Account().Extension().AnsweringRule().Post(parameters);
4 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.

Nate Breeden avatar image Nate Breeden commented ·

The code you sent worked fine, after that I changed "TakeMessagesOnly" to "TransferToExtension" and added this line below the "TakeMessagesOnly" line, then received the same error as before (x's are the queue's id). This time I hard coded the queue's id as well, just to make sure it's not breaking when passing


parameters.transfer.extension.id = "xxxxxxx";


Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Program.<Main>$(String[] args) in C:\Users\xxx\source\repos\TestConsoleApp\TestConsoleApp\Program.cs:line 44
   at Program.<Main>(String[] args)


var parameters = new CreateAnsweringRuleRequest();
parameters.enabled = true;
parameters.type = "Custom";
parameters.name = "My weekly meetings";
var schedule = new ScheduleInfo();
var weeklyRanges = new WeeklyScheduleInfo();
TimeInterval day = new TimeInterval();
day.from = "09:00";
day.to = "10:00";
weeklyRanges.monday = new TimeInterval[] { day };

day = new TimeInterval();
day.from = "10:00";
day.to = "15:00";
weeklyRanges.friday = new TimeInterval[] { day };

schedule.weeklyRanges = weeklyRanges;
parameters.schedule = schedule;
parameters.callHandlingAction = "TransferToExtension";
parameters.transfer.extension.id = "xxxxxxxxx";

var response = await rc.Restapi().Account().Extension().AnsweringRule().Post(parameters);
0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Nate Breeden commented ·

Great. That helps us narrow down the suspecting area. And here is the working code

parameters.callHandlingAction = "TransferToExtension"; 
var transferObj = new TransferredExtensionInfo();
var callQueueInfo = new CallHandlingExtensionInfo();
callQueueInfo.id = "xxxxxxxxx";

transferObj.extension = t;
parameters.transfer = transferObj;
0 Likes 0 ·
Nate Breeden avatar image Nate Breeden Phong Vu ♦♦ commented ·

As always, you're a beast.


For future and so I understand better, how were you able to narrow it down to it wanting the CallHandlingExtensionInfo type inside the TransferredExtensionInfo variable?

0 Likes 0 ·
Show more comments

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