Toggle an extension's DND with calendar

We are using Freepbx 14. I have a customer asking if his extension’s DND can be automatically toggled with a google calendar based on if they are busy (have an event) or not. I can load the calendar into the calendar module. I’m not sure if this is possible or not, pretty new feature. Any ideas?

I’ve not had the opportunity to use the calendar module, so I’m not sure of all of the features, but you may be able to make this work by using the calendar flow-control the same way you would any other holiday schedule. It would be experimental but basically, you could do it the same way you would a “secretary” phone, where the boss’ extension is on the assistant’s phone and his phone’s actual extension is a hidden “special” extension that only the dial-plan actually knows.

Followme can be calendar controlled. You could control external calls through a time condition with true going to an extension and false going to voicemail.

You could also script up something that accomplishes the task as well…

$freepbx = FreePBX::Create();
$busy = $freepbx->matchCalendar($calendarID);
   $freepbx->Donotdisturb->setStatusByExtension('1001', 'BUSY');
   $freepbx->Donotdisturb->setStatusByExtension('1001', '');
1 Like
$freepbx = FreePBX::Create();
$busy = $freepbx->matchCalendar($calendarID);
   $freepbx->Donotdisturb->setStatusByExtension('1001', 'BUSY');
} else {
   $freepbx->Donotdisturb->setStatusByExtension('1001', '');

I know it’s a pedantic thing, but this gets rid of one of the comparisons and makes it so that the code runs one or the other (without the possibility of both, which arguably couldn’t happen).

@jfinstrom Would you run this as a Cron job, or is there a way to add arbitrary code to the Calendar module?

Code is for humans… The computer will read any code that compiles it doesn’t care. When you write code you must assume a serial killer in your basement is going to maintain it. So code should be written to be read. Much like there are many ways to communicate you should communicate in a way that anyone can understand. The case above is probably fine for an if/else. What if I need to do more tests and checks. I add another check. Someone else adds one etc. It quickly becomes a bloody train wreck.

in the example you see:
if it is busy he intends this.
if it is NOT busy he intends this.
future code…
if the state is alreasy busy he wants it to return
etc etc…

You have experienced perl the write only language. You never patch, simply refactor :slight_smile:

tl;dr code should be written in a manor that someone who doesn’t write code can still understand what is happening.

So a better example would have really been

if($busy === true){....
if($busy === false){....

This would tell the reader he is absolutely expecting true or false rather than assuming that is what was returned.

also… yes it would likely be a cron job lol

Yeah - all of that.

I could probably invoke that “whipper-snapper” thing at this point. In September, I “celebrated” the 45th anniversary of my first computer program. Keep in mind, though, that I come from a time when we worked hard to get rid of unneeded comparisons. I know it’s hard for some of our readers to believe, but there was once a time when if you wanted to do anything on a computer, you had to do it yourself and as efficiently as possible.

I’ve written in far more write-only languages than PHP or PERL. I’ve written in FORTH. I currently write in IBM Series-1 Assembler. What I wouldn’t give for a PHP interpreter that could produce overlays in 128K I-spaces with 256K D-spaces.

Like I said, it was a little pedantic, but it’s where I’m from. :slight_smile:

I’ll have to find out if we want to do something this custom or not. In case we do decide to do it and for future people searching this where would I put that code at? Do I need to include/require something or does it autoload classes?

I made a feature request here:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.