# Asterisk Project : Calendaring Dialplan Examples

Added by mdavenport , edited by gdraque on Oct 11, 2012

### Office hours

A common business PBX scenario is would be executing dialplan logic based on when the business is open and the phones staffed. If the business is closed for holidays, it is sometimes desirable to play a message to the caller stating why the business is closed.

The standard way to do this in asterisk has been doing a series of GotoIfTime statements or time-based include statements. Either way can be tedious and requires someone with access to edit asterisk config files.

With calendaring, the adminstrator only needs to set up a calendar that contains the various holidays or even recurring events specifying the office hours. A custom greeting filename could even be contained in the description field for playback. For example:

    [incoming]
    exten => 5555551212,1,Answer
     same => n,GotoIf(${CALENDAR_BUSY(officehours)}?closed:attendant,s,1)
     same => n(closed),Set(id=${CALENDAR_QUERY(office,${EPOCH},${EPOCH})})
     same => n,Set(soundfile=${CALENDAR_QUERY_RESULT(${id},description)})
     same => n,Playback($[${ISNULL(soundfile)} ? generic-closed :: ${soundfile}])
     same => n,Hangup

### Meeting reminders

One useful application of Asterisk Calendaring is the ability to execute dialplan logic based on an event notification. Most calendaring technologies allow a user to set an alarm for an event. If these alarms are set on a calendar that Asterisk is monitoring and the calendar is set up for event notification via calendar.conf, then Asterisk will execute notify the specified channel at the time of the alarm. If an overrided notification time is set with the autoreminder setting, then the notification would happen at that time instead.

The following example demonstrates the set up for a simple event notification that plays back a generic message followed by the time of the upcoming meeting. calendar.conf.

    [calendar_joe]
    type = ical
    url = https://example.com/home/jdoe/Calendar
    user = jdoe
    secret = mysecret
    refresh = 15
    timeframe = 600
    autoreminder = 10
    channel = SIP/joe
    context = calendar_event_notify
    extension = s
    waittime = 30

extensions.conf :

    [calendar_event_notify]
    exten => s,1,Answer
     same => n,Playback(you-have-a-meeting-at)
     same => n,SayUnixTime(${CALENDAR_EVENT(start)})
     same => n,Hangup

### Writing an event

Both CalDAV and Exchange calendar servers support creating new events. The following example demonstrates writing a log of a call to a calendar.

    [incoming]
    exten => 6000,1,Set(start=${EPOCH})
    exten => 6000,n,Dial(SIP/joe)
    exten => h,1,Set(end=${EPOCH})
    exten => h,n,Set(CALENDAR_WRITE(calendar_joe,summary,start,end)=Call from ${CALLERID(all)},${start},${end})