Skip to main content
Question

Call Handling C# Issue

  • September 12, 2022
  • 4 replies
  • 331 views

Forum|alt.badge.img

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 ServerNameScriptsAppNameRCTermUser.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)

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • September 12, 2022

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

Forum|alt.badge.img

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;

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • September 12, 2022

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

Forum|alt.badge.img

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:Usersxxxsource
eposTestConsoleAppTestConsoleAppProgram.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);

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings