Created
May 8, 2016 15:51
-
-
Save marcelog/c403a20efd4938fe7f72c6f393030ba3 to your computer and use it in GitHub Desktop.
Part of: http://marcelog.github.io/articles/php_asterisk_agi_protocol_tutorial.html Sending commands and receiving responses from Asterisk by using a shell script and the Asterisk Gateway Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
filedump=/tmp/dump.txt | |
function log() { | |
echo ${@} >> ${filedump} | |
} | |
function dumpvar() { | |
log "channel variable: ${1} = ${2}" | |
} | |
function send() { | |
log Sending: ${@} | |
echo ${@} | |
read line | |
log "Got: ${line}" | |
} | |
function answer() { | |
send "ANSWER" | |
} | |
function agilog() { | |
send "VERBOSE" \"${@}\" | |
} | |
function play() { | |
send STREAM FILE ${1} "#" | |
} | |
function setvariable() { | |
send SET VARIABLE ${1} ${2} | |
} | |
function hangup() { | |
setvariable AGISTATUS SUCCESS | |
send "HANGUP 16" | |
} | |
callStatus=1 | |
function callEnded() { | |
if [ "${callStatus}" -eq "0" ]; then | |
return | |
fi | |
callStatus=0 | |
agilog "Call ended abruptly" | |
hangup | |
exit 0 | |
} | |
# Asterisk will send a SIGHUP signal when the user hangups the channel. In this | |
# example you can try it by waiting for the welcome audio message to finish or | |
# hangup before it finishes playing. | |
trap callEnded SIGHUP | |
log "------------ call start ------------" | |
dumpvar "config dir" ${AST_CONFIG_DIR} | |
dumpvar "configfile" ${AST_CONFIG_FILE} | |
dumpvar "module dir" ${AST_MODULE_DIR} | |
dumpvar "spool dir" ${AST_SPOOL_DIR} | |
dumpvar "monitor dir" ${AST_MONITOR_DIR} | |
dumpvar "var dir" ${AST_VAR_DIR} | |
dumpvar "data dir" ${AST_DATA_DIR} | |
dumpvar "log dir" ${AST_LOG_DIR} | |
dumpvar "agi dir" ${AST_AGI_DIR} | |
dumpvar "key dir" ${AST_KEY_DIR} | |
dumpvar "run dir" ${AST_RUN_DIR} | |
line='init' | |
while [ "${#line}" -gt "2" ]; do | |
read line | |
log ${line} | |
done | |
answer | |
agilog Hello There | |
play welcome | |
hangup | |
log "------------ call done ------------" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment