Page 240 - Asterisk™: The Future of Telephony
P. 240
You will notice that the second argument is passed by putting in a set of double quotes,
escaped by backslashes. Without the double quotes to indicate the second argument,
this command does not work correctly.
You must pass all required arguments to the AGI commands. If you want
to skip a required argument, you must send empty quotes (properly
escaped in your particular programming language), as shown above. If
you don’t pass the required number of arguments, your AGI script will
not work.
You should also make sure you pass a line feed (the \n on the end of the
print statement) at the end of the command.
After sending the STREAM FILE command, this test reads the result from STDIN and calls
the checkresult subroutine to determine if Asterisk was able to play the file. The STREAM
FILE command takes three arguments, two of which are required:
• The name of the sound file to play back
• The digits that may interrupt the playback
• The position at which to start playing the sound, specified in number of samples
(optional)
In short, this test told Asterisk to play back the file named beep.gsm, and then it checked
the result to make sure the command was successfully executed by Asterisk.
print STDERR "2. Testing 'sendtext'...";
print "SEND TEXT \"hello world\"\n";
my $result = <STDIN>;
&checkresult($result);
This test shows us how to call the SEND TEXT command, the
SendText() application. This command will send the specified text to the caller, if the
caller’s channel type supports the sending of text.
The SEND TEXT command takes one argument: the text to send to the channel. If the
text contains spaces (as in the previous code block), the argument should be encapsu-
lated with quotes, so that Asterisk will know that the entire text string is a single
argument to the command. Again, notice that the quotation marks are escaped, as they
must be sent to Asterisk, not used to terminate the string in Perl.
print STDERR "3. Testing 'sendimage'...";
print "SEND IMAGE asterisk-image\n";
my $result = <STDIN>;
&checkresult($result);
This test calls the SEND IMAGE command, which is similar to the SendImage() application.
Its single argument is the name of an image file to send to the caller. As with the SEND
TEXT command, this command works only if the calling channel supports the receiving
images.
212 | Chapter 9: The Asterisk Gateway Interface (AGI)