Here’s a simple working example. There’s enough there to get you started, just fill in some of the blanks. Let me know if you’ve got any questions.
Edit /etc/asterisk/extensions_custom.conf.
Add the following where appropriate:
[from-internal-custom]
include => custom-alert
include => custom-alert-answer
[custom-alert]
exten => ctat,1,NoOp(Beginning alert IVR for ${CALLERID(num)})
; list of users to call. FIRST number is where we dumb the alerted user into, SECOND is the caller ID, and all comma-separated entries after that are people getting alerted.
; To be clear, you should change:
; 5000 to be your conference room or extension you want called
; 1000 to be the caller ID number users see on their phones
; 3456,4567 to be a comma-separated list of as many numbers as you want called
; same => n,Set(anothergroup=5000,1000,3456,4567)
same => n,Set(alertees=5560,${CALLERID(num),5067)
; check that the caller is something local. dont rely on this.
same => n,GosubIf(${LEN(${CALLERID(num)})}=4?ok:notok)
same => n(ok),NoOp("Length checked out, continuing")
same => n,GoSub(alertivr,1)
same => n(notok),NoOp(Bad extension length (${LEN(${CALLERID(num)})}), hanging up..)
same => n,Playback(goodbye)
same => n,Hangup()
; prompt for caller to enter password; you could have different alerts based on password entered if you wanted.
exten => alertivr,1,NoOp(Entering alert IVR)
same => n,Background(enter-password)
same => n,WaitExten(4)
same => n,Hangup()
; an example 'password'
exten => 1234,1,NoOp(${CALLERID(num)} entered the right password)
; execute the call file script, passing in the variable with our alertees - this is what youd change with different 'passwords'
same => n,System(/home/asterisk/alertfolks.sh ${alertees})
same => n,Wait(1)
same => n,Playback(goodbye)
same => n,Hangup()
; where the caller ends up; you could prompt them to accept the conference or whatever.
[custom-alert-answer]
exten => atan,1,NoOp(Alerting someone and dumping them in a conference)
same => n,Playback(minneapolis&minnesota)
same => n,Dial(Local/5560@from-internal)
same => n,Hangup()
Create /home/asterisk/alertfolks.sh
, include the following:
#!/bin/bash
# template call file location
here="/home/asterisk"
callfile="alert.call"
# what the alerted extension will be subbed for
alertext="%EXTEN%"
# what the alerted destination will be (extension/conference/etc)
dest="%DEST%"
# get arguments and put them in the ${extarr[@]} array
IFS=, read -ra extarr <<< "$@"
# set the first element as the destination, second as CID, then discard them
destext=${extarr[0]}
fromext=${extarr[1]}
alertees=${extarr[@]:2}
# loop through the alertees and build/move the call file
for i in $alertees; do
cp $here/$callfile $here/$i-$callfile
sed -i -e "s/$alertext/$i/g" $here/$i-$callfile
sed -i -e "s/$dest/$destext/g" $here/$i-$callfile
sed -i -e "s/$cid/$fromext/g" $here/$i-$callfile
mv $here/$i-$callfile /var/spool/asterisk/outgoing
done
Create /home/asterisk/alert.call
, include the following:
Channel: Local/%EXTEN%@from-internal
WaitTime: 8
MaxRetries: 2
RetryTime: 12
Callerid: %CID%
Context: custom-alert-answer
Extension: %DEST%
You can modify waittime/retrytime/maxretries as needed, obviously.
Set permissions on stuff, reload asterisk
chown asterisk. /home/asterisk/alert*
chmod +x /home/asterisk/alertfolks.sh
asterisk -rx 'dialplan reload'
Configure FreePBX:
Admin > Custom Destinations
Target: custom-alert,ctat,1
Description: CustomAlertDest
Applications > Misc Application
Description: CustomAlert
Feature Code: <some extension>
Destination: Custom Destination/CustomAlertDest
At this point you should have a basic, working alert system. You can dial the Feature Code
you just entered to test. From here you can probably figure out how to schedule it, if you wanted to. All you need to do is change the list in extensions_custom.conf and you’re set; the rest shouldn’t need much/any touching (although you can do lots with just what i’ve given you).
If you have problems, please do the following from linux shell:
asterisk -rvvvvvvvvv
<reproduce issue>
exit
Copy resulting scrollback to pastebin.com, copy that link, paste it here.