Asterisk on Debian as a stand alone voicemail box…

… connected to an ALCATEL PBX

 

apt-get update
apt-get -y dist-upgrade
apt-get -y install rdate rsync mc glances nloadm locate ncdu mailutils
apt-get -y install asterisk
systemctl enable asterisk

Add routes to your main PBX

dpkg-reconfigure exim4-config

Do some config stuff:

Your extensions.conf:

[general]

[incoming]
exten => 500,1,VoiceMailMain()
exten => 500,2,HangUp()
exten => 500,3,PlayBack(vm-goodbye)
exten => 500,4,HangUp()
;
exten => 640,1,Log(NOTICE, Incoming call from ${CALLERID(all)})
exten => 640,2,Dial(SIP/640,5)
exten => 640,3,VoiceMail(640,s)
;
exten => 641,1,Log(NOTICE, Incoming call from ${CALLERID(all)})
exten => 641,2,Dial(SIP/641,5)
exten => 641,3,VoiceMail(641,s)
;
exten => 642,1,Log(NOTICE, Incoming call from ${CALLERID(all)})
exten => 642,2,Dial(SIP/642,5)
exten => 642,3,VoiceMail(642,s)
;
exten => 643,1,Log(NOTICE, Incoming call from ${CALLERID(all)})
exten => 643,2,Dial(SIP/643,5)
exten => 643,3,VoiceMail(643,s)
;
; EXTENSION 100 + VOICEMAIL (FOR TEST ONLY)
;
exten => 100,1,Dial(SIP/100,5)
exten => 100,2,VoiceMail(100,s)
;
; EXTENSION 200 (FOR TEST ONLY)
;
exten => 200,1,Dial(SIP/200,5)
exten => 200,2,VoiceMail(200,s)
;
;END

Your sip.conf:

[general]

allowguest=no
srvlookup=no
udpbindaddr=0.0.0.0
tcpenable=no
canreinvite=no
dtmfmode=auto

;

; Trunk to your main PBX
[alcatel]
type=friend
host=172.16.100.12
disallow=all
allow=ulaw
allow=alaw
;allow=gsm
allow=g729
insecure=port,invite
context=incoming

; Your testing area
[local-voip](!)
type=friend
context=incoming
host=dynamic
insecure=port,invite
disallow=all
allow=ulaw
allow=alaw
allow=g729
;
[100](local-voip)
secret=pass100
callerid="Test 100" 
;
[200](local-voip)
secret=pass200
callerid="Test 200" 
;

Your voicemail.conf:

[general]

format=wav
maxmsg=1000
maxsecs=60
minsecs=3
skipms=3000
maxsilence=10
silencethreshold=128
maxlogins=3
externnotify="/usr/local/homegrown/asterisk/externnotify.sh"
emaildateformat=%A, dem %d. %B %Y um %H:%M:%S
emailsubject=AB | Neue Nachricht: ${VM_NAME}
emailbody=Liebe ${VM_NAME}:\n\n\tam ${VM_DATE} wurde eine Nachricht mit der Laenge ${VM_DUR} durch 0${VM_CALLERID} fuer Dich hinterlassen.\n\nDu findest sie in S:\\ANRUFBEANTWORTER\\${VM_NAME}\\AUFNAHMEN.\n\n\n\n\t\t\t\tDein Anrufbeantworter
attach=no
serveremail=voicemail@mydomain.mytld
fromstring=Anrufbeantworter


[default]
100 => 777,Test 100,email100@mydomain.mytld
200 => 777,Test 200,email200@mydomain.mytld
640 => 777,Test 640,email640@mydomain.mytld
641 => 777,Test 641,email641@mydomain.mytld
642 => 777,Test 642,email642@mydomain.mytld
643 => 777,Test 643,email643@mydomain.mytld

You have to numbers to test with softphones (i.e. zoiper): 100 and 200.
the 64x extensions are targets that should be connected/rerouted from existing extensions on your main PBX.

All answers should be like RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
All audio stuff related to your extensions is located in /var/spool/asterisk/voicemail/default. Temporary answers per extension: i.e. 640/temp.wav.

To move incoming messages to any other host use externnotify:

externnotify.sh

#!/bin/bash
HOME="/usr/local/homegrown/asterisk"
test -d "$HOME" || exit 1
cd "$HOME"

# BASICS
SPOOLDIR=/var/spool/asterisk/voicemail/$1/$2/
MSGINBOX=${SPOOLDIR}INBOX
ANSWERPLACE=$SPOOLDIR
REMOTEBASEDIR="root@yourserver:/data/ANRUFBEANTWORTER/extension-"
SSHOPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i $HOME/id_rsa"
case $2 in
   640)
        # BBR EMPFANG
        REMOTEEXTENSION="470"
      ;;
   641)
        # TDY EMPFANG
        REMOTEEXTENSION="471"
      ;;
   642)
        # BBR HOTLINE
        REMOTEEXTENSION="472"
      ;;
   643)
        # 222
        REMOTEEXTENSION="473"
      ;;
   *)
    echo "UNKNOWN EXTENSION"
    exit 4
     ;;
esac

# UPDATE ANSWER
/usr/bin/rsync -q -e "ssh $SSHOPTS" ${REMOTEBASEDIR}${REMOTEEXTENSION}/ANSAGE/ansage.wav ${SPOOLDIR} 2>/dev/null && \
    cd ${SPOOLDIR} && \
    chown asterisk:asterisk ansage.wav && \
    /usr/bin/sox -c 1 ansage.wav -b 16 -r 8000 -c 1 temp.wav && \
    chown asterisk:asterisk temp.wav
cd $HOME

# PROCESS MESSAGES
for MSGINFO in $MSGINBOX/*.txt; do
    test -r $MSGINFO || exit 2
    MSGAUDIO=${MSGINFO%txt}wav
    test -r $MSGAUDIO || exit 2

    eval $(cat "$MSGINFO" | grep callerid)
    eval $(cat "$MSGINFO" | grep origtime)
    test "x$callerid" == "x" && callerid="unknown"
    MSGTARFILE="${REMOTEBASEDIR}${REMOTEEXTENSION}/AUFNAHMEN/$(/usr/bin/date -d @$origtime "+%Y-%m-%d_%H%M%S")_$callerid.wav"
    /usr/bin/scp $SSHOPTS -q $MSGAUDIO $MSGTARFILE && ( rm -f $MSGAUDIO && rm -f $MSGINFO )
done
exit $?
# END

Chown this script to asterisk:asterisk, add asterisk to sudoers and test it.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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