Restrict incoming calls based on time of day

Hello all,

I’d like to be able to restrict incoming calls based on the time of day. During the day when there are classes being taught in some of the rooms, I would like to have the phones in those rooms go straight to voicemail if someone from outside the building calls in to that extension. Calls to those rooms from inside the building should be allowed to go through.

I know about the include statements to base includes on time of day, but I’m not sure how to use them for incoming calls without replicating my dial plan for daytime and nighttime.

The only thing I could come up with so far is:

In extensions.conf:

[incoming]
include => daytime|8:00-17:00|mon-fri||
include => nighttime|17:01-7:59|mon-fri||

[daytime]
exten => 3331,1,Voicemail(u3351)
exten => 3332,1,Voicemail(u3332)
…and so on

[nighttime]
exten => 3331,1,Dial(SIP/3331,20,rt)
exten => 3331,2,Voicemail(u3331)
exten => 3332,1,Dial(SIP/3332,20,rt)
exten => 3332,2,Voicemail(u3332)
…and so on

While I think this will work, it will be tedious to make and maintain the dialplan because it will be so huge and there’s lots of duplication.

Is there any easier and more efficient way of doing this that I’m overlooking?

TIA,

Jeremy

One thing that comes to my mind right now:
[incoming]
exten => 3331,1,[url=http://www.voip-info.org/wiki/view/Asterisk+config+extensions.conf]macro/url
exten => 3332,2,macro(CheckTime,${EXTEN})

[macro-CheckTime]
exten => s,1,gotoiftime(17:01-7:59|mon-fri||?2,3) ; i think that should work, if ‘time’ in 17:01-7:59 then dial else voicemail
exten => s,2,dial(SIP/${ARG1},20,rt)
exten => s,3,voicemail(u${ARG1})
exten => s,4,hangup

Thanks for the reply. That almost worked. I actually changed the gotoiftime statement to:
exten => s,1,gotoiftime(8:00-17:00|mon-fri||?s,3)
exten => s,2,dial(SIP/${ARG1},20,rt)
exten => s,3,voicemail(u${ARG1})
exten => s,4,hangup

Which sends them to voicemail (priority 3) if time is between 8 and 17 and goes to priority 2 which dials normally if it’s not.

I guess it pays to know how to use the dial plan correctly. I was going to suggest that you used [color=orange]Asterisk Realtime[/color] on extensions.conf and change the dialplan using a crontab and SQL statements… Oh well, at least there is more than one way!

Alejandro