Changing the state of the system

So I’m posting this for the new folks; it may seem like an obvious thing for some, but maybe it will help someone.

Our situation here is the boss wants the phone answered by a human whenever possible; so we have IVR set up for hours when we are closed, OR if the operator can’t get to a ringing line in so many seconds.

But there are other things as well; such as holidays, bad weather, and so forth.

Here’s how I set things up.

I have a time group called “Normal Hours” that are the business hours. That one is a no-brainer. When we’re closed, send it to IVR, when we’re open, send it to the operator group.

So, a combination of a Time Condition and a Time Group makes that happen.

However, there are other reasons that the system may go to IVR. Holidays, closed due to weather, and so forth.

To make all this work, my time conditions are “Cascaded”. I have a time condition called “Bad Weather”. It has no time GROUP associated with it, so it never activates itself. I have one called Christmas, one called Thanksgiving, and one called Holidays (for the other holidays).

Each time condition has a feature code assigned to it (more on this later)

So, a call comes in and hits the first time condition… bad weather. If it’s on, send it to an IVR called “Bad Weather”, which plays a bad weather message, then takes a voicemail message.

If the “Bad Weather” isn’t active, it goes to the next time condition. “Thanksgiving”. If that one isn’t active, it goes to “Christmas”, then to “Holidays”, then LAST it goes to “Normal Hours”.

So, an incoming call looks like this:
Call starts
Is it “Bad Weather”?
Is it “Thanksgiving”?
Is it “Christmas?”
Is it “Holidays?”
Are we open? (normal hours)
Ring the operator.

Now here is where things get cool. First of all, since all of these have a feature code, I set up a separate DISA number (with a strong password) so that the boss can say “Oh, we’re buried in snow…” and they can dial in and turn on the “Bad Weather”. Since that’s the first in the cascade, the system immediately switches over to the bad weather/voicemail setting.

Here’s the next cool thing… by programming those feature codes on BLF’s on the operator station, the modes can also be changed with a push of a button! Why would I want this? Well, one day (before a holiday) the boss let us all go home an hour early on Friday. No problem… touch the “Normal Hours” button on the operator station, and the system goes into the IVR mode, instead of ringing the front desk.

In this way, modes can be quickly and easily changed either with the push of a button at the operator station, OR by DISA. Bonus is that you can see what mode the system is in… so when we’re open, the “Normal Hours” BLF is green… when we’re closed, it’s red. If we’re getting sent home because of a blizzard, just touch the “Bad Weather” button on your way out, and the system is changed appropriately.

Anyway, I hope this helps someone. Took me a while to figure out the best way to handle it, but this way works well.

(Note: Whatever is “higher” on the list will have priority… in other words, if the “Bad Weather” mode is set, “Christmas” won’t ever get played)

Oh… just a follow up to this… I’m working on an automated script to set “floating” dates (like easter and thanksgiving) that can’t easily be programmed into a time group.

Most businesses are closed on Sundays, so setting up a special condition for Easter is usually not required. If your business is open on Sundays, except for Easter you might need to handle it special.

I’ve set up “closed” conditions like this before, and I always combine all of the “standard” holidays so you don’t need to “cascade” them. Finally, for Thanksgiving, you can use a compound condition where the holiday is “Thursday” and the date falls between the 22nd and the 28th of November. Check the dates of course, but I think that’s about right.

The Calendar module in FreePBX 14 is quite useful for this.

Anyone can add an appointment to a Google Calendar, FreePBX reads this and if something exists, activates the condition.

1 Like

We’re closed Good Friday. :slight_smile: That’s why the “Easter” holiday.

Good Friday is a tricky one… working on the script for that.

Easter sunday is the first sunday after the first full moon after the vernal equinox.

Most people wouldn’t be able to figure that out, unless it was marked on a calendar. BUT, there is a formula for it… problem is, BASH (because I was going to write a bash script to set the database… ) doesn’t do floating point, so I’m having to work around that.

Could probably do it as a PHP or PERL script though, and just set it as a cron job.

ncal -e

Yeah… my installation doesn’t have ncal installed.
Yum says no package ncal available.

That’s why I was going down the route of writing my own script. :slight_smile:

its usually in bsdmainutils

I’m using this calendar integration and it works great! If you use exchange based calendars, you can use the category function to set specific categories and it allows you to use a single calendar to control the “office”.

I filed an enhancement to also allow use of regex matches on the calendar event titles, that would expand the use to more calendar systems. In the mean time, I’ve put in a hack to pre-process the ics files and add the category. Currently work in progress…

Well, I’ve got a php script now that correctly calculates easter, good friday, and thanksgiving. I’m adding code in for labor day and memorial day.

I’m looking at the timegroups_groups and timegroups_details tables, and working out how to best update the dates. This way, a cron job could run (once a year for that matter) and “plug in” all of the time conditions. OR, if you wanted to have one “Closed for the holidays” message, the cron job could run once a day, and update based on if today is a holiday or not.

Just poking around and playing with things… I don’t know if there’s even an interest in this script… I’m just playing right now. :slight_smile: Proof of concept.

thanksgiving is easy, there is an example here

This is exactly what most users need.

Additionally, I’d rather set up a Call Flow Control for bad weathers or unexpected emergencies, like this the state of “closed” won’t get overridden by the next schedule in the time condition.
Meaning, have a CFC on top of your time conditions.
Also, holidays don’t show up unexpected, there’s enough time for admins to send emails to management and setup accordingly.
Iv’e seen users trying to set holiday schedules by overriding Time Conditions running into trouble…

Well, it sounds like there’s not much interest in having a script to do this.

I guess I’ll move along to other interests.

What we’ve been saying, that essentially there’s better ways of doing it, or an opinion how their way would work better.

This community is about an open source project that has thousands of custom built integrations, some of which were built by FreePBX/Sangoma and some by users like you and me.

So… Your scrip will very likely be what someone in the future will be looking for, for their integrations.

Refraining from posting because of some people said their toys is cooler than yours is wrong IMO.

If there are already ways to do it, there’s no point in re-inventing the wheel. If newer version than what I have already have calendar integration, that’s great. I wasn’t saying I wouldn’t post, I was just saying that I won’t put a whole lot of effort into writing a script if the issue has already been addressed in later versions.

Sometimes, I like to write scripts just as an exercise in making me think about it.

I remember one time writing a calculator in VisualStudio. Simple, 4 function calculator. It would even make the numbers “scroll” left to right as you entered new numbers, etc. etc.

Think of the original windows calculator. I re-wrote it.

My (now ex) wife told me it was a waste of time, why not just use Windows calculator? She never did get the concept of “I wanted to see if I could do it myself.”

That being said, for those who DO want the calculation (I didn’t write this, I found it…) here is a php function that gets the date of Easter for any given year.


   function easterdate ($Year) {

   G is the Golden Number-1
   H is 23-Epact (modulo 30)
   I is the number of days from 21 March to the Paschal full moon
   J is the weekday for the Paschal full moon (0=Sunday,
     1=Monday, etc.)
   L is the number of days from 21 March to the Sunday on or before
     the Paschal full moon (a number between -6 and 28)

     $G = $Year % 19;
     $C = (int)($Year / 100);
     $H = (int)($C - (int)($C / 4) - (int)((8*$C+13) / 25) + 19*$G + 15) % 30;
     $I = (int)$H - (int)($H / 28)*(1 - (int)($H / 28)*(int)(29 / ($H + 1))*((int)(21 - $G) / 11));
     $J = ($Year + (int)($Year/4) + $I + 2 - $C + (int)($C/4)) % 7;
     $L = $I - $J;
     $m = 3 + (int)(($L + 40) / 44);
     $d = $L + 28 - 31 * ((int)($m / 4));
     $y = $Year;
     $E = mktime(0,0,0, $m, $d, $y);

     return date("m-d-Y",$E);

Absolutely, you gotta keep on practicing!