System information

Now that we have our calendar configured, we need to load it into memory, which can
be done by reloading the res_calendar.so module:
*CLI> module reload res_calendar.so
Verify that the calendar has been loaded into memory successfully with the calendar
show command:
*CLI> calendar show calendars
Calendar Type Status
-------- ---- ------
phone_call_calendar caldav free
With our calendar successfully loaded into memory, we can write some dialplan around
our Dial() command to save our call information to the calendar with the CALEN
DAR_WRITE() function:
[LocalSets]
exten => _NXXNXXXXXX,1,Verbose(2,Outbound calls)
same => n,Set(CalendarStart=${EPOCH}) ; Used by CALENDAR_WRITE()
same => n,Set(X=${EXTEN}) ; Used by CALENDAR_WRITE()
same => n,Dial(SIP/ITSP/${EXTEN},30)
same => n,NoOp(Handle standard voicemail stuff here)
same => n,Hangup()
exten => h,1,Verbose(2,Call cleanup)
; Everything that follows must be on a single line
same => n,Set(CALENDAR_WRITE(phone_call_calendar,summary,description,start,end)=
OUTBOUND: ${X},Phone call to ${X} lasted for ${CDR(billsec)} seconds.,
${CalendarStart},${EPOCH})
In our dialplan we’ve created a simple scenario where we place an outbound call
through our Internet Telephony Service Provider (ITSP), but prior to placing the call,
we save the epoch
to a channel variable (so we can use it later when we write our
calendar entry at the end of the call). After our call, we write our calendar entry to the
phone_call_calendar with the CALENDAR_WRITE() dialplan function within the built-in
h extension. There are several options we can pass to the calendar, such as the summary,
description, and start and end times. All of this information is then saved to the
calendar.
We’ve also used the CDR() dialplan function in our description to show the number of
seconds the answered portion of the call lasted for, so we can get a more accurate
assessment of whether a call was answered and, if so, how long the answered portion
lasted for. We could also be clever and only write to the calendar if ${CDR(billsec)}
was greater than 0 by wrapping the Set() application in an ExecIf(); e.g., same =>
n,ExecIf($[${CDR(billsec)} > 0]?Set(CALENDAR_WRITE...)).
‡ In Unix, the epoch is the number of seconds that have elapsed since January 1, 1970, not counting leap
seconds.
410 | Chapter 18:External Services