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 Handling C# Issue
Tags: rest api, call handling
Sep 12, 2022 at 8:38am   •   2 replies  •  0 likes
Nate Breeden

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)

2 Answers
answered on Sep 12, 2022 at 10:23am  

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

 0
on Sep 12, 2022 at 10:36am   •  0 likes

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);
on Sep 12, 2022 at 11:29am   •  0 likes

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;
on Sep 12, 2022 at 12:32pm   •  0 likes

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?

on Sep 12, 2022 at 4:01pm   •  0 likes

Here is the trick. When creating a data object, place the cursor to a member and see the data member type.

screen-shot-2022-09-13-at-55857-am.png

answered on Sep 12, 2022 at 9:06am  

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

 0
on Sep 12, 2022 at 9:47am   •  0 likes

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;
on Sep 12, 2022 at 9:55am   •  0 likes

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?

on Sep 12, 2022 at 10:09am   •  0 likes

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?



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