Sunday, November 17, 2013

Asterisk 11.4.0 Call File

Call File are like shell script for Asterisk. A user or application writes a call file into /var/spool/asterisk/outgoing/ where Asterisk processes it immediately.

NOTE: 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 .call files. With cp (copy), the file is copied line by line, which could lead to Asterisk processing an incomplete file.

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:
  • Asterisk polls the /var/spool/asterisk/outgoing/ for new call files and processes any it finds. 
  • Asterisk opens a connection to device SIP/2000. If the device is in use or not answered, Asterisk tries two more times (see MaxRetries). 
  • If someone answers SIP/2000, Asterisk begins processing extension 10 in the context [call-file-test]. In this case, Asterisk plays hello-world to the answering party.

Parameters

These parameters may be used in call files:
Channel: <channel>
The channel upon which to initiate the call. Uses the same syntax as the Dial() command (see Section B.27, “Dial()”).
Callerid: <callerid>
The caller ID to be used for the call.
WaitTime: <number>
Number of seconds the system waits for the call to be answered. If not specified, defaults to 45 seconds.
MaxRetries: <number>
Maximum number of dial retries (if an attempt fails because the device is busy or not reachable). If not specified, defaults to 0 (only one attempt is made).
RetryTime: <number>
Number of seconds to wait until the next dial attempt. If not specified, defaults to 300 seconds.
Account: <account>
The account code for the CDR.
Context: <context>
The destination context.
Extension: <exten>
The destination extension, in which dialplan execution begins if the device is answered.
Priority: <priority>
The destination priority. If not specified, defaults to 1.
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>