Hi,
A quick and dirty (aka Rapid Application Developement) AGI script
implement using bash shell. No need to invoke a 10MB perl engine to
process simple asterisk agi scripts.
I found it to be very useful in learning the AGI interface. For example,
I learn that AGI won't execute the next command until you read the
results from STDIN.
Enjoy,
Sunny Woo
Solution Consultant
Avantnix
=========================== agi-test-bash.agi ======================
#!/bin/bash
declare -a array
while read -e ARG && [ "$ARG" ] ; do
array=(` echo $ARG | sed -e 's/://'`)
export ${array[0]}=${array[1]}
done
# following variables are available from asterisk
echo $agi_request >&2
echo $agi_channel >&2
echo $agi_language >&2
echo $agi_type >&2
echo $agi_uniqueid >&2
echo $agi_callerid >&2
echo $agi_dnid >&2
echo $agi_rdnis >&2
echo $agi_context >&2
echo $agi_extension >&2
echo $agi_priority >&2
echo $agi_enhanced >&2
checkresults() {
while read line
do
case ${line:0:4} in
"200 " ) echo $line >&2
return;;
"510 " ) echo $line >&2
return;;
"520 " ) echo $line >&2
return;;
* ) echo $line >&2;; #keep on reading those Invlid command
#command syntax until "520 End ..."
esac
done
}
echo "1. Testing 'sendfile' ..." >&2
echo "STREAM FILE beep \"\""
checkresults
echo "2. Testing 'sendtext' ..." >&2
echo "SEND TEXT \"hello world\""
checkresults
echo "3. Testing 'sendmage' ..." >&2
echo "SEND IMAGE asterisk-image"
checkresults
echo "4. Testing 'saynumber' ..." >&2
echo "SAY NUMBER 192837465 \"\""
checkresults
echo "5. Testing 'waitdtmf' ..." >&2
echo "WAIT FOR DIGIT 1000"
checkresults
echo "6. Testing 'record' ..." >&2
echo "RECORD FILE testagi gsm 1234 3000"
checkresults
echo "6a. Testing 'record' playback" >&2
echo "STREAM FILE testagi \"\" "
checkresults
echo "=================== Complete ====================" >&2
=========================== agi-test-bash.agi ======================
--
Sunny Woo <[EMAIL PROTECTED]>
#!/bin/bash
declare -a array
while read -e ARG && [ "$ARG" ] ; do
array=(` echo $ARG | sed -e 's/://'`)
export ${array[0]}=${array[1]}
done
# following variables are available from asterisk
echo $agi_request >&2
echo $agi_channel >&2
echo $agi_language >&2
echo $agi_type >&2
echo $agi_uniqueid >&2
echo $agi_callerid >&2
echo $agi_dnid >&2
echo $agi_rdnis >&2
echo $agi_context >&2
echo $agi_extension >&2
echo $agi_priority >&2
echo $agi_enhanced >&2
checkresults() {
while read line
do
case ${line:0:4} in
"200 " ) echo $line >&2
return;;
"510 " ) echo $line >&2
return;;
"520 " ) echo $line >&2
return;;
* ) echo $line >&2;; #keep on reading those Invlid command
#command syntax until "520 End ..."
esac
done
}
echo "1. Testing 'sendfile' ..." >&2
echo "STREAM FILE beep \"\""
checkresults
echo "2. Testing 'sendtext' ..." >&2
echo "SEND TEXT \"hello world\""
checkresults
echo "3. Testing 'sendmage' ..." >&2
echo "SEND IMAGE asterisk-image"
checkresults
echo "4. Testing 'saynumber' ..." >&2
echo "SAY NUMBER 192837465 \"\""
checkresults
echo "5. Testing 'waitdtmf' ..." >&2
echo "WAIT FOR DIGIT 1000"
checkresults
echo "6. Testing 'record' ..." >&2
echo "RECORD FILE testagi gsm 1234 3000"
checkresults
echo "6a. Testing 'record' playback" >&2
echo "STREAM FILE testagi \"\" "
checkresults
echo "=================== Complete ====================" >&2