Search:

Asterisk tips callback

!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 voicemail.conf where you want the mailbox to get a callback, in the format
  315 => 4513,Jim Doh,doh@megacorp.com,5555555555@messaging.nextel.com
  callme = 5555555555,6666666666




  TODO:
 #  Allow for different contexts, as the config file does.
 #   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

      #note use of '-' in '-EOF1' - Escapes tab at beginning of lines
      CALLFILE=$(cat <<-EOF1
       Channel: Zap/g1/$phone_number
       MaxRetries: 2
       # 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%mNaVI%M%S)-$phone_number

 }

 #CONSTANTS
 ASTERISK_CFG="/etc/asterisk"
 VOICEMAIL_CFG="$ASTERISK_CFG/voicemail.conf"
 CALL_SPOOL_DIR="/var/spool/asterisk/outgoing"

 #CALL_SPOOL_DIR=tst/
 #VOICEMAIL_CFG="./asterisk/voicemail.conf"


 #*********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"



Created by: oej,Last modification on Sat 10 of Mar, 2007 [21:04 UTC] by gramels


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

 
Sponsored by:




Search: