login | register
Fri 29 of Aug, 2008 [00:42 UTC]

voip-info.org

Discuss [8] History

Asterisk tips callback

Created by: oej,Last modification on Sat 10 of Mar, 2007 [21:04 UTC] by gramels
!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"




Comments

Comments Filter
222

333To: ip_works

by bdrake, Thursday 05 of July, 2007 [18:11:23 UTC]
Make sure you have set your script as "executable":
chmod +x /var/lib/scripts/voicemail_callback.sh

--Barry
222

333

by ip_works, Sunday 17 of June, 2007 [23:13:16 UTC]
Hi,
I have set this up and am getting error
:Unable to execute '/voicemail_callback.sh 3001"

I have the script in /var/lib/asterisk/scripts
Asterisk 1.4.4
Centos 4.5

any thoughts are appreciated.

Thank you

Jimmy
222

333

by ip_works, Sunday 17 of June, 2007 [23:12:59 UTC]
Hi,
I have set this up and am getting error
:Unable to execute '/voicemail_callback.sh 3001"

I have the script in /var/lib/asterisk/scripts
Asterisk 1.4.4
Centos 4.5

any thoughts are appreciated.

Thank you

Jimmy
222

333

by ip_works, Sunday 17 of June, 2007 [23:11:41 UTC]
Hi,
I have set this up and am getting error
:Unable to execute '/voicemail_callback.sh 3001"

I have the script in /var/lib/asterisk/scripts
Asterisk 1.4.4
Centos 4.5

any thoughts are appreciated.

Thank you

Jimmy
222

333Re: no send on hangup

by geekfly, Wednesday 17 of August, 2005 [16:06:20 UTC]
Use DEADAGI on a dead channel....
http://www.voip-info.org/tiki-index.php?page=Asterisk%20cmd%20AGI
222

333no send on hangup

by , Thursday 13 of January, 2005 [23:19:41 UTC]
Has anyone figured out the Hangup issue? Same as the first comment; When a user hangs up the script is not run. I have tried with the h extension to no avail so would love a pointer or two.
222

333what's wrong?

by goolem, Thursday 07 of October, 2004 [11:35:30 UTC]
When the Caller press # at the end of message it's all ok.
But when the caller hangs up then the script dont run.

what is wrong?
222

333wish for this awesome app'

by sjobeck, Tuesday 20 of July, 2004 [06:42:33 UTC]
I wonder how hard it would be to add some more complexity to this for the users to customize some variables before the out-call is made? (by the way, AltiGen offers this feature also, just FYI). What I had in mind was something like:
_ make out-call if voicemail is urgent
_ make out-call is voicemail from certain callerid
_ make out-call if between certain hours
_ make out-call if not listened to voicemail in the last hour

but these are way above my head at this time.

Thanks for the great tip, though, will be deploying it soon.