Call files are like a shell script for Asterisk. A user or
application writes a call file into
/var/spool/asterisk/outgoing/ where Asterisk
processes it immediately.
|
|
|
A mv (move) is an atomic operation (an
operation which does not take effect until it is 100% complete) and as
such is ideally suited for |
Let's demonstrate the .call file principle with an example. Assume that we have a SIP phone registered with the number 2000 in Asterisk. In addition, we have the following extension in the dialplan:
[call-file-test] exten => 10,1,Answer() exten => 10,n,Wait(1) exten => 10,n,Playback(hello-world) exten => 10,n,Wait(1) exten => 10,n,Hangup()
We create a call file called a-test.call in
/tmp/ with the following content:
Channel: SIP/2000 MaxRetries: 2 RetryTime: 60 WaitTime: 30 Context: call-file-test Extension: 10
Now we move this file with mv /tmp/a-test.call /var/spool/asterisk/outgoing/
root@molokai:~>mv /tmp/a-test.call /var/spool/asterisk/outgoing/
The following happens:
/var/spool/asterisk/outgoing/ for new call files
and processes any it finds.SIP/2000.
If the device is in use or not answered, Asterisk tries two more times
(see MaxRetries).SIP/2000, Asterisk begins
processing extension 10 in the context
[call-file-test]. In this case, Asterisk plays
hello-world to the answering party.These parameters may be used in call files:
Channel: <channel>
Dial() command (see the section called “Dial()”).Callerid: <callerid>
WaitTime: <number>
MaxRetries: <number>
RetryTime: <number>
Account: <account>
Context: <context>
Extension: <exten>
Priority: <priority>
Setvar: <var=value>
Setvar: lets you set one or more
channel variables.Archive: <yes|no>
By default, call files are deleted immediately upon
execution. If Archive: yes is set, they
are copied into
/var/spool/asterisk/outgoing_done/ instead.
Asterisk adds a line to the call file which describes the
result:
Status: <Expired|Completed|Failed>
When executing a call file, Asterisk compares the change time with the current time. If the change time is in the future, Asterisk ignores the call file. This is an easy way to implement time-based call files.
A hotel wants to implement a simple wake-up call system. Clients must be able to set a wake-up call by dialing *77*, whereupon they hear a prompt asking for the date and time of the wake-up call.
[hotel-intern]
exten => _*77*XXXXXXXXXXXX,1,Answer()
exten => _*77*XXXXXXXXXXXX,n,Set(year=${EXTEN:4:4})
exten => _*77*XXXXXXXXXXXX,n,Set(month=${EXTEN:8:2})
exten => _*77*XXXXXXXXXXXX,n,Set(day=${EXTEN:10:2})
exten => _*77*XXXXXXXXXXXX,n,Set(hours=${EXTEN:12:2})
exten => _*77*XXXXXXXXXXXX,n,Set(minutes=${EXTEN:14:2})
exten => _*77*XXXXXXXXXXXX,n,NoOp(Wake-up call scheduled for ${CALLERID(
num)} at ${hours}:${minutes} on ${day}.${month}.${year}.)
exten => _*77*XXXXXXXXXXXX,n,System(echo -e "Channel: SIP/${CALLERID(num
)}\\nContext: wake-up\\nExtension: 23" > /tmp/${UNIQUEID}.call)
exten => _*77*XXXXXXXXXXXX,n,System(touch -t ${year}${month}${day}${hour
s}${minutes} /tmp/${UNIQUEID}.call)
exten => _*77*XXXXXXXXXXXX,n,System(mv /tmp/${UNIQUEID}.call /var/spool/
asterisk/outgoing/)
exten => _*77*XXXXXXXXXXXX,n,Playback(rqsted-wakeup-for)
exten => _*77*XXXXXXXXXXXX,n,SayNumber(${hours})
exten => _*77*XXXXXXXXXXXX,n,SayNumber(${minutes})
exten => _*77*XXXXXXXXXXXX,n,Hangup()
[wake-up]
exten => 23,1,Answer()
exten => 23,n,Wait(1)
exten => 23,n,Playback(this-is-yr-wakeup-call)
exten => 23,n,Wait(1)
exten => 23,n,Hangup()