On-Call Schedule help - Need to change on-call phone # three to four times a day

Hi,

My name is Phil and I am new to FreePBX. We are running version 2.2.3.

We have one on-Call line which needs to call one of four Doctors, depending on the time of day and day of the week.

At first, I was thinking about setting many time conditions, but since the on-call schedule changes from month to month, the maintenance of it would be too much.

I am now thinking about writing a program that would read the spreadsheet, which contains the schedule for the month. This program would be setup as a NEP on one of the other servers (Windows) and at the required time, it would update the MySQL database with the new Phone Number.

  1. Does anyone have any idea if this will work?
  2. If the Database can be updated, does anyone have information as to which file I should update.
  3. Once updated, would I need to do anything to have the system start using the update phone #?

Thank you for any help you may provide.

Phil.

I wrote this a while back to help solve that problem. In this case I assume that the on call Doc is on for a day, 3 days or a week at a time. With this hunk of code, you can set the cell phone number to be paged after hours by dialing a phone number.

;This block of code allows you to change the number that the night line uses
;Put it in the from-internal-custom.
;
;You will need to set up a Misc Destination in FreePBX for each Day/Night 
;toggle that you use.  Then point the night portion of the Day/Night switch 
;to that Misc Destination.  In my case, since the Day/Night switches are
;*280 through *289, I created Misc Destinations 280 through 289.  
;
;If you dial *280 then a 10-digit number, it will write a database key called
;"DAYNIGHT/N0 and enter the 10 digit number in it.  That is what the first block
;code does.
;
;The second block of code is processed when the night mode of a particular
;Day/Night switch is set to the appropriate Misc Destination.  If you set the
;night destination of Day/Night *280 to extension 280, the second block of code
;is executed.  If you need steering digits, set the second line, "prefixd" to 
;your prefix.  
;
;This will allow your customer to set the cell phone number that night 
;calls go to without giving them access to the Web Interface.  


exten => _*28XNXXNXXXXXX,1,noop(Sets the day night phone number)
exten => _*28XNXXNXXXXXX,n,Set(index=${EXTEN:3:1})
exten => _*28XNXXNXXXXXX,n,Set(DB(DAYNIGHT/N${index})=${EXTEN:4})
exten => _*28XNXXNXXXXXX,n,Flite(You have set night number ${index} to ) 
exten => _*28XNXXNXXXXXX,n,saydigits(${DB(DAYNIGHT/N${index})})
exten => _*28XNXXNXXXXXX,n,Flite(You should dial star 2 8 ${index} to activate the night ring.)
exten => _*28XNXXNXXXXXX,n,hangup()

exten => _28X,1,Set(index=${EXTEN:2})
exten => _28X,n,Set(prefixd=91)
exten => _28X,n,Set(dialnumb=${prefixd}${DB(DAYNIGHT/N${index}))
exten => _28X,n,goto(from-internal,${dialnumb},1)
exten => _28X,n,hangup()

;Modify line 4 above to go direct to voicemail.  Change NOMESSAGE to either BUSY or UNAVAIL if needed
exten => _28X,n,Macro(vm,${dialnumb},NOMESSAGE)

Thank you for your reply. However, I need to have the entire process automated. We cannot rely on any one to manually make the change.

The schedule changes every month and at times, it also changes during the month.

Here is an example of what the March schedule looks like:
March 1st
7am-12pm - On-call #1
12pm-2pm - On-call #2
2pm-7am - On-call #3
March 2nd
7am-12pm - On-call #4
12pm-5pm - On-call #1
5pm-7am - On-call #3
March 3rd
7am-12pm - On-call #2
12pm-5pm - On-call #3
5pm-7am - On-call #4
Etc…
There really is no patern to their on-call schedule. I was hoping to setup a file where I would upload a start and end date/time with an associated Phone # to call. Then every hour, the phone system would compare the system date and time against the dates and times within the file to determine which phone # it should now be calling when a call is received on the on-call line.

Another alternative would be for an external program, to update the on-call phone # within the Phone System’s Database, if possible. Any information on how to access the database and find which table would contain a Forwarding Phone #. Also, if I changed the # within the file, would I have to execute anything to get the phone system to recognize the updated #?

Can you help with either scenarios? I need to make the update process as streamlined as possible.

Start by installing phpMyAdmin if your system doesn’t already have it… this will allow you to see what’s in the database. You can change the number directly in the database (the method varies on how you do it, but it’s a MySQL database) but the change(s) to the database will not actually be recognized by Asterisk until you do the equivalent of an “orange bar” reload - there’s a way to do that from within a script, I just can never remember how offhand.

Another, possibly better way (but one that would require some coding skills on your part) would be to send the incoming call to an AGI script that would read your spreadsheet and pick out the number to call in real time. AGI scripts can be written in Perl or PHP, or even as a Bash script (see How to automatically reject calls from telemarketers and other “junk” callers for an example of changing a DID number based on data fetched from a web source). My point is that there is more than one way to accomplish what you want to do, and changing the number in the MySQL database may not be the best way, particularly if you don’t want to have to reload the database (a fairly CPU intensive process) every time the number changes - better, perhaps, to go out to a script that fetches the number to call.

The script could be injected into the call flow either before or after the Incoming Route part of the dialplan… to do it before you’d send the trunk to a custom context (in extensions_custom.conf) instead of from-trunk, and there you’d change the incoming DID to some pseudo-DID (as is done in the document I referenced above), then have a different incoming route for each pseudo-DID that goes to your different extensions or Misc. Destinations. Or, you could create an agi script that runs AFTER the route is selected, create a custom context that calls your AGI script, and then use the Custom Destinations module to make it selectable as a destination (from your Inbound Route, or any other place that a destination could be called). If it were me, I’d take the second approach, but that’s just me.

I suggest you spend some time looking over the HOWTOs to get some ideas about how people have tweaked FreePBX to do things not supported by the GUI. You will quickly understand that you can create what I call “shims” (little bits of custom dialplan that get wedged in between the dialplan generated by FreePBX) and then if necessary, from with the “shim” code you can do an AGI call to do just about anything you want, as long as you can program it in some script language that Asterisk supports or you can return a variable to Asterisk and then let it do what you want.

You need to figure your budget for this and place a bounty for the custom app.
You would use the asterisk API to pull it off, and that is for outside the scope of free support from a forum on PBXes.

I am sure if you budget enough cash for the project there are those here who would take it on.

with only 4 doc’s to work with it would not be hard nor would it over load the server in anyway.

sometimes the easy way is just the easy way.

Ward (nerdvittles) has “PhoneGenie” from which a decent coder can figure out how to change the DB via a third party app.

It is not hard for a PHP programmer to create a set of pages to post to the current freepbx pages and never have to learn a thing about freepbx or asterisk.

do not over think it, put in simple terms.

the reload is easy as well

$retrieve = “/var/lib/asterisk/bin/retrieve_conf”;
exec($retrieve.’&>/var/log/asterisk/freepbx-retrieve.log’);