Sunday, March 13, 2016

Free IVR and voicemail system for MS Lync/SFB Part 3

Welcome Back. In Part 1 and Part 2 we finished installing asterisk and configured IVR in this part we will confiugre voicemail and SFB/Lync side.

Install postfix on linux

  • First you need to remove sendmail and install postfix to make it default mail client on the voicemail server.
  • To remove snedmail run "yum remove sendmail".
  • To install postfix run "yum -y install postfix mailx cyrus-sasl-plain" .
  • You need to create a new file with name "/etc/postfix/sasl_passwd" with your mail account smtp server and credentials in the following format:
smtpserver.yourdomain.com    emailaddress@yourdomain.com:emailpassword
  • Then you need to hash your password file by run "postmap hash:/etc/postfix/sasl_passwd"
  • Open the /etc/postfix/main.cf and add following lines.
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
# Secure channel TLS with exact nexthop name match.
smtp_tls_security_level = secure
smtp_tls_mandatory_protocols = TLSv1
smtp_tls_mandatory_ciphers = high
smtp_tls_secure_cert_match = nexthop
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
relayhost = smtpserver.yourdomain.com
  • You could change tls confiugration according to your SMTP server.
  • Some times you will need to change the from email address in the header of sent mail so you need to create two additional files "/etc/postfix/header_checks,canonical" check this URI for more details http://tech.gate.io/postfix-sender-address-rewriting-changing-mails-from-field-in-header-on-relay-server/
  • Then restart the postfix service by "service postfix restart".
  • Test sending mail by run "echo 'Test mail from voicemail system' | mail -s 'test mail' -r 'voicemail system <emailaddress@yourdomain.com>' testemail@hotmail.com".
  • To troubleshoot you could find the logs in "/var/log/maillog"
  • Once you send the mail check your email to see if you received the email and then you can go ahead and remove the text password file by run "rm /etc/postfix/sasl_passwd".

Configure asterisk voicemail

  • first copy the voicemail sample file from sample to asterisk directory by run "cp /usr/src/asterisk*/configs/vociemail.conf.sample /etc/asterisk/voicemail.conf"
  • If you need more details on how to configure the voicemail file just read the sample file comments, but I'll go through basic needs.
  • To change from name check "fromstring="
  • To change the subject check "emailsubject="
  • To change the body check "emailbody="
  • Now we will configure the voicemail boxes by write the following under "[default]" section
user 3 digit extension=> 1234,user display name,user email address
  • repeat this line for every user you need to send him voicemail.

Configure missed call notification

  • Now let's configure the missed call notification open "/etc/asterisk/extensions.conf".
  • write following line at end of "[IVR_EN]" and "[IVR_EN]" sections.
exten => h,1,GotoIf($["${DIALSTATUS}" = "ANSWER"]?:Missed,${extens},1)
  • Write "[Missed]" in the end of the file.
  • Under "[Missed]" section write.
exten => user 3 digit extension,1,System(echo 'You have Missed Incoming Call From: ${CALLERID(num)} <${CALLERID(num)}>  Received at : ${STRFTIME(${EPOCH},,%d-%m-%Y-%H:%M:%S)}' | mail -s 'New Missed Call' -r 'voicemail system <emailaddress@yourdomain.com>'  user email address)
  • Repeat this line for every user you need to send him voicemail.
  • Restart asterisk service.

Configure SIP trunks @ SFB/Lync and @ voice gateway

  • From Lync/SFB side it is similar to create SIP trunk with any gateway it was written a lot in other blog so no need to duplicate it here but to summarize you need to do the following.
    • Create SIP trunk with IVR using port 5060 at both sides.
    • Create SIP trunk with Voice gateway.
    • Route external calls to Voice gateway.
  • About voice gateway it depend upon your gateway, but you need to do the following:
    • Create sip trunk with IVR server using port 5060 for each side using TCP as transport.
    • Create sip trunk with Lync/SFB.
    • Route 299 calls to IVR system.
    • Route DID to Lync/SFB direct.
  • I'll provide in next blogs examples on how to configure most gateways which integrate with Lync/SFB.

Sunday, March 6, 2016

Free IVR and voicemail system for MS Lync/SFB Part 2

Welcome Back. In Part 1 we finished installing asterisk so let start configuring everything.

Asterisk Basic files

  • first you need to configure some basic configuration, you have two options to do so:
    • simple one by just run "make samples" but this will enable a lot of features you may don't need to use them
    • just create two essential files called (asterisk.conf, and modules.conf) and put them in "/etc/asterisk" folder (press on file names to see sample of confiugration).
  • run "service asterisk restart" to reset the asterisk service to update configuration.

Asterisk SIP Trunks configuration

  • The sip configurations are located in file called "sip.conf" at "/etc/asterisk" so create the file and open it.
  • first you need to enable SIP/TCP as a transport as Lync/SFB work only with TCP and asterisk by default support UDP, you could do it by write below configuration, 
[general]
tcpenable=yes
tcpbindaddr=0.0.0.0
transport=tcp,udp
  • We will need to have two sip trunks one with Lync/SFB and one with the gateway on same file add below lines
[Lync]
disallow=all
host=<hostname of Lync/SFB FE server>
type=peer
insecure=port,invite
transport=tcp
port=<TCP Port of Lync/SFB mediation>
context=Lync-Trunk
dtmfmode=RFC2833
allow=alaw
allow=ulaw

[Gateway]
disallow=all
host=<hostname of gateway>
type=peer
insecure=port,invite
transport=tcp "you could use UDP of gateway if it doesn't support TCP"
port=<port of Gateway>
context=Gateway-Trunk
dtmfmode=RFC2833
allow=alaw
allow=ulaw
  • run "service asterisk restart" to reset the asterisk service to update configuration.

Asterisk IVR sound files

  • First you need to import sound files to asterisk these file should be in .WAV format.
  • According to my workflow from part1 we will need these files "Welcome, Main_Ar, Transfer_Ar, Wrong_Ar, Main_En, Transfer_En, Wrong_En)".
  • Sure you could have you own files and also IVR workflow this is just a sample.
  • The files should have below characteristics to work with
    • If you record in a studio, use 8kHz 16 bits, not 8 bits, and phone line is 12 to 13 bits compressed down to 8 in a pseudo-logarithmic way
    • then down-sample your audio to 8000hz and save in Windows PCM wav (16 bit) format
    • When recording find a really quiet place. Background noise is usually the biggest hassle when recording prompts
    • use a reasonable mic; fix it down someplace (don't hand hold it) 
  • Upload these files to "/var/lib/asterisk/sounds/en/"
  • Then we need to convert them to format that asterisk understand (gsm, or sln) so you should run below command for every file."sox /var/lib/asterisk/sounds/en/Welcome.wav -t raw -r 8000 -s -2 -c 1 /var/lib/asterisk/sounds/en/Welcome.sln"

Asterisk IVR configuration

  • you need to create one of the most important files in asterisk which called "extensions.conf" it is also exist in "/etc/asterisk"
  • first you need to define a number that the Gateway will send all incoming call to it in my configuration below it is "299"
  • According to my workflow from part1 i have written below in the file, sure you need to change it if your workflow is different.
; trunk assign to call received from gateway
 [Gateway-Trunk]
; answer the received call on 299 number
exten => 299,1,answer()
; play welcome and wait maximum 3 digit
  same => n,Read(extens,Welcome,3,,,5)
; if the caller didn't give any digits go to arabic IVR_AR
  same => n,gotoIf($[${LEN(${extens})} == 0]?IVR_AR,299,Start) 
; if the caller enter 2 then go to english IVR_EN
  same => n,gotoIf($[${extens} == 2]?IVR_EN,299,Start)
; if the user out 3 digit go to direct to call internal extension
  same => n,gotoIf($[$[${LEN(${extens})} = 3]]?IVR_AR,299,Transfer)
; if non of the above run the message again
  same => 299,6,goto(,299,1)

;arabic IVR section
[IVR_AR] 

; play main and wait for 3 digits

exten => 299,1(Start),Read(extens,Main_Ar,3,,,2)
;if the user out 3 digit go to direct to call internal extension
  same => n,GotoIf($[$[${LEN(${extens})} = 3]]?:IVR_AR,299,Start)
; this is the section of direct call of internal ext 
; play transfer msg before dial
  same => n(Transfer),Playback(Transfer_Ar) 
; dial internal ext at lync
  same => n,Dial(SIP/${extens}@Lync) 
; if call answered go to end 
  same => n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?stop) 
 ; if user doesn't exist go to wrong ext
  same => n,GotoIF($["${DIALSTATUS}" = "CHANUNAVAIL"]?wrong) 

; if non of above it mean missed call go to voicemail of this extension
  same => n,VoiceMail(${extens}@default) 

; end call
  same => n,Hangup() 
; this is wrong extension section
; play wrong ext msg
  same => n(wrong),Playback(Wrong_Ar)
; return back to start of arabic IVR_AR
  same => n,Goto(,299,Start) 
; end call
  same => n(stop),Hangup() 

;enlgish IVR same like arabic but with english msgs
[IVR_EN]
exten => 299,1(Start),Read(extens,Main_En,3,,,2)
  same => n,GotoIf($[$[${LEN(${extens})} = 3]|$[${extens} == 0]]?:IVR_EN,299,Start)
  same => n(Transfer),Playback(Transfer_En)
  same => n,Dial(SIP/${extens}@Lync_Out)
  same => n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?stop)
  same => n,GotoIF($["${DIALSTATUS}" = "CHANUNAVAIL"]?wrong)
  same => n,VoiceMail(${extens}@default)
  same => n,Hangup()
  same => n(wrong),Playback(Wrong_En)
  same => n,Goto(,299,Start)
  same => n(stop),Hangup

check  Part 1 and Part 3
See you in part 3 

Wednesday, March 2, 2016

Free IVR and voicemail system for MS Lync/SFB Part 1

The problem

I faced a problem a lot when implementing Lync/SFB as IP PBX, it is IVR and attendant systems.
I heard requests from customer like:
  • Why I need MS exchange if I'll only install Lync/SFB.
  • I need to change the language of all prompts not only greeting and so on.
  • I need more options and flexibility in the IVR option (example, inform caller of transferring the call while calling the internal extension)
  • I have google cloud and need to have missed calls and voice mails to be sent to users email
also I faced a lot customers have Exchange online and when we integrate it with Lync/SFB we experience delay till the call answer by exchange auto attendant and I think it is due to the fact that exchange is on internet , we opened  a lot of tickets with MS and apply all possible QoS methods with slightly enhanced but it still noticed by the caller.

We was about to loss or lost a lot of hot opportunities cause of things like this.

The Solution

so what is the solution ??!!.

It is 3rd party IVR and voicemail system which I developed by myself using Asterisk PBX and Postfix on a Linux machine.

The Design

  • As blow image I insert the IVR system in middle of incoming calls between Voice gateway and Lync/SFB system while leaving the outbound call path as it is.
  • All incoming calls pass through IVR first then it answer the call and run the prompts as needed workflow, and waiting to get the caller digits.
  • Then the IVR system transfer the call of Lync/SFB with monitoring the status of the call if didn't answered the IVR contact the mail server and send voicemail and/or missed call notification mail to the called person.

  • I already have basic IVR workflow as below image which I will represent it in this blog

Installation of IVR

First I won't go though Linux installation also you could choose any distribuation of Linux but to use the same commands for asterisk installation, use Centos 6.x.

for Asterisk installation do below:
  • Update Centos
yum update -y
  • Disable firewall
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
iptables -X
/etc/init.d/iptables save

    • Install prerequisites
    yum install -y make wget openssl-devel ncurses-devel newt-devel libxml2-devel kernel-devel gcc gcc-c++ sqlite-devel
    • Download Asterisk Source
    cd /usr/src/
    wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
    • Extract and Install Asterisk
    tar zxvf asterisk*
    cd /usr/src/asterisk*
    for 32 bit:
    ./configure && make menuselect && make && make install
    for 64 bit:
    ./configure --libdir=/usr/lib64 && make menuselect && make && make install
    • Start asterisk
    service asterisk start
    asterisk -rvvv

    check  Part 2 and Part 3