Upgrade 3CX to v18 and get it hosted free!

Asterisk tips callback

Author image

How to create callback voicemail

by Jpiterak

Here are a couple of scripts I use to do callback voicemail to my users. This was a request from a customer who was looking at a similar feature on an Avaya system.

How it works:

    • Instead of calling Voicemail() directly, I set up a macro ‘macro-leave_voicemail’ that makes the Voicemail() call, then checks to see if you want to send a call to the user.
    • If callback is set, the macro calls a bash script that creates the call file. This script:
      • Checks the voicemail.conf file for a specially formatted comment line after the mailbox definition with the telephone numbers to call for this user.
      • Creates a call file for each of these phone numbers. Note that the call file:
        • Puts the callee into a context in extensions.conf that tells them that they have a call waiting, and allows them to press 1 to go directly to voicemail.
        • Sets a variable ‘${mailbox}’, which is used to enter the correct voicemailbox if the user chooses to listen to the voicemail.

/var/lib/asterisk/scripts:

Usage:
voicemail_callback.sh <voicemailbox>

Requires that you add a line after each entry in Asterisk config voicemail.conf where you want the mailbox to get a callback, in the format
315 => 4513,Jim Doh,[email protected],[email protected]
callme = 5555555555,6666666666

TODO:

  1. Allow for different contexts, as the config file does.
  2. Right now, anyone with the same mailbox # will get called 🙂

get_phone_numbers()
{
if [ “x$1” != “x” ];then voicemailbox=”$1″; else return 1; fi
cfg_line=$(grep -A 1 “^$voicemailbox” “$VOICEMAIL_CFG”)
if ( echo “$cfg_line”|grep -E ‘callme\W*=\W*[[:digit:]]+’>/dev/null);then
phnum_list=$(echo “$cfg_line”|grep -E ‘callme = ‘|cut -d’=’ -f 2|sed -e ‘s/,/ /g’)
echo “$phnum_list”
else
return 1
fi
}

make_callfile()
{
if [ “x$1” != “x” ];then mailbox=”$1″; else return 1; fi
if [ “x$2” != “x” ];then phone_number=”$2″; else return 1; fi

  1. note use of ‘-‘ in ‘-EOF1’ – Escapes tab at beginning of lines

CALLFILE=$(cat <<-EOF1
Channel: Zap/g1/$phone_number
MaxRetries: 2

  1. Retry in 5 min

RetryTime: 300
WaitTime: 45

Context: feature-voicemail_callback
Extension: s
Priority: 1
SetVar: mailbox=$mailbox

EOF1)

echo “$CALLFILE” >> “$CALL_SPOOL_DIR”/$(date +%Y%m%d-%I%M%S)-$phone_number

}

  1. CONSTANTS

ASTERISK_CFG=”/etc/asterisk”
VOICEMAIL_CFG=”$ASTERISK_CFG/voicemail.conf”
CALL_SPOOL_DIR=”/var/spool/asterisk/outgoing”

  1. CALL_SPOOL_DIR=tst/
  2. VOICEMAIL_CFG=”./asterisk/voicemail.conf”
  1. *********MAIN*******************************************************

if [ “x$1” != “x” ];then voicemailbox=”$1″; else exit 1; fi

if ph_numbers=$(get_phone_numbers $voicemailbox) ;then
for ph_num in $ph_numbers; do
make_callfile “$voicemailbox” “$ph_num”
done
fi

In extensions.conf:

  • A macro that is used to call app_voicemail, and which calls the bash script to initiate the call out.

 


  [macro-leave_voicemail]
  ; Leave a voicemail message, then do post-processing.
  ;   o Call configured phones, with an announcement that a message
  ;      is waiting, and the option to listen to the voicemail(s)
  ;        ${ARG1} = u or b for 'unavailable' or 'busy' message
  ;        ${ARG2} = mailbox
  ;	 ${ARG3} = Call user flag
  ; USAGE:
  ;	exten => s,15,Macro(leave_voicemail,u,310,1)

  exten => s,1,ResponseTimeout(30)
  exten => s,2,Voicemail2(${ARG1}${ARG2})
  exten => s,3,GoToIf($[${ARG3} = 0]?s|5)
  exten => s,4,system(${SCRIPTS_DIR}/voicemail_callback.sh ${ARG2})
  exten => s,5,NoOp

  exten => h,1,GoToIf($[${ARG3} = 0]?h|3)
  exten => h,2,system(${SCRIPTS_DIR}/voicemail_callback.sh ${ARG2})
  exten => h,3,NoOp
  exten => t,1,GoToIf($[${ARG3} = 0]?t|3)
  exten => t,2,system(${SCRIPTS_DIR}/voicemail_callback.sh ${ARG2})
  exten => t,3,NoOp

 

  • Note that the h and t extensions may not be necessary… I used them for troubleshooting problems with call progress detection on FXO cards (More on that later… Down in ‘Please Note!’)

and…

  • The context that is connected to by the call file:

[feature-voicemail_callback]
exten => s,1,ResponseTimeout(2)
exten => s,2,Background(vm_callback-announcement)
exten => s,3,Background(vm_callback-options)
exten => t,1,Goto(s|2)

exten => 1,1,VoicemailMain2(s${mailbox})

  • Finally, the sound file contents:
vm_callback-announcement: “You have new voicemail”
vm_callback-options: “To listen to this voicemail, press 1”

 


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.