Skip to content

guillaumeteillet/ivr-guillaume-teillet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting started with IVR - Interactive Voice Response

This walkthrough describes how to create an IVR (Interactive Voice Response) based on Asterisk / Nexmo / ippi.fr / AWS in few easy steps and how to run it on your EC2 (Amazon Web Service).

Prerequisites

  • An AWS account

Asterisk / Nexmo / ippi.fr / AWS

Asterisk is an open source framework for building communications applications. Asterisk turns an ordinary computer into a communications server. Asterisk powers IP PBX systems, VoIP gateways, conference servers and other custom solutions. It is used by small businesses, large businesses, call centers, carriers and government agencies, worldwide. Asterisk is free and open source.

Nexmo is the global cloud communications platform leader providing innovative communication APIs and SDKs for voice, text, chat app and phone verification. Here you can rent a number for 0.50 cts per month (French mobile number)

ippi.fr is a SIP provider where we will buy some credits to be able to transfer calls from our IVR to our mobile phone number.

Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage, content delivery and other functionality to help businesses scale and grow. We will use EC2.

1. Create an EC2 instance

First of all, you need to create an EC2 instance. On Amazon Web Service, select EC2 :

In the left menu, choose "Instances" :

On the Instance page, click on "Launch Instance" on the top menu :

"Step 1: Choose an Amazon Machine Image (AMI)" : You should select "Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-f95ef58a" :

"Step 2: Choose an Instance Type" : Verify that the instance t2.micro is selected and click on "Review and launch"

"Step 7: Review Instance Launch" : click on "Launch" (Right bottom of the page)

If you already used AWS, you already have a key pair so you can use it and for finish, click on "Launch Instance"

If you never used AWS, you should create a new key pair : Enter the name of your key pair (can be what you want) and click on "Download Key Pair" and for finish, click on "Launch Instance"

Now, you should have this page : click on "View Instances" (Right bottom of the page)

A new instance is launching :

After few minutes, when the EC2 instance is ready, you should see this :

If you click on it, you will see all the details about the EC2 Instance.

2. Connect to your EC2 Instance

On Amazon Web Service, select EC2, Instances (in the left menu), select your instance and click on "Connect" (in the top menu).

Copy the ssh command. Mine is "ssh -i "Guillaume.pem" ubuntu@ec2-54-171-135-46.eu-west-1.compute.amazonaws.com". Open a terminal, go to the folder that contains the key pair and paste the ssh command.

Now your are connected on your EC2 Instance.

3. Get the code

Run this on your EC2 instance :

sudo su
apt-get update
apt-get install -y git
cd /home/ubuntu/
git clone https://github.com/guillaumeteillet/ivr-guillaume-teillet
cd ivr-guillaume-teillet

4. Install Asterisk and Sendmail

Run this on your EC2 instance :

apt-get install asterisk

When the system is asking you "Do you want to continue? [Y/n]" Press Y and Enter.

Run this on your EC2 instance :

apt-get install sendmail

When the system is asking you "Do you want to continue? [Y/n]" Press Y and Enter.

5. Configuration Sendmail

Run this on your EC2 instance :

cd /home/ubuntu/ivr-guillaume-teillet
nano wavmail.sh

Update "your-email-address@domain.tld" with your email address. Don't remove the "<>", they are important ! So if your email is tony@myprovider.com, you should have something like this :

#!/usr/bin/env bash

(printf "%s\n" \
"Subject: New message on your Voicemail from $2 !" \
"To: Voicemail <tony@myprovider.com>" \
"Content-Type: application/wav" \
"Content-Disposition: attachment; filename=$(basename $1)" \
"Content-Transfer-Encoding: base64" \
""; base64 $1) | /usr/sbin/sendmail -t

Save your file Ctrl + X + S, then press y and enter

Then, run this on your EC2 Instance :

cd /home/ubuntu/ivr-guillaume-teillet
chmod 777 wavmail.sh

6. Create an ippi.fr account to activate redirection call on your mobile phone.

One of the functionality of this IVR is to redirect urgent call to your mobile phone.

For this functionality, we need a SIP account. I choose to use a ippi.fr account but you can use another provider if you want. You can sign up here : https://www.ippi.com/index.php?page=sp-offer&lang=44&referrer=guillaumeteilletpro

OPTIONAL :

When your free ippi account is ready, you need to add some credits or apply for a package to be able to use the redirection feature (it's not free of charge).

7. Add an elastic ip to your EC2 Instance

We will add an elastic ip to your EC2 Instance. On the left menu, in the "Network & Security" section, select "Elastic IPs".

On the Elastic IP page, click on the blue button "Allocate new address".

A popup appears, click on "Yes, allocate"

AWS will allocate an new elastic ip to your account. Click on "Close"

Then, click on "Actions" in the menu and select "Associate Address"

A popup appears, select your instance in the first field and then click on "Associate"

Now, on the left menu, click on Instances.

On the Instances page, select your EC2 Instances to get all the details of your instance :

We will need the private IP and the public IP in the next step !

Now, your public address has changed. You need to ssh again on your EC2 Instance (See step 2 - Connect to your EC2 Instance)

8. Configuration Asterisk

Run this on your EC2 instance :

cd /home/ubuntu/ivr-guillaume-teillet
nano sip.conf

After "externip=" replace YOUR_PUBLIC_IP_AWS by your elastic IP (public IP address). After "localnet=" replace YOUR_PRIVATE_IP_AWS by your private IP address.

If you want to activate the redirection feature, replace all "YOUR_USERNAME_IPPI" by your ippi.fr username and all "YOUR_PASSWORD_IPPI" by your ippi.fr password.

If you want to activate the redirection feature, your sip.conf file should look like this :

[general]

bindaddr = 0.0.0.0
context = ivr_menu
host=dynamic
type=friend
encryption=yes
externip=52.209.221.205
localnet=172.31.34.144/255.255.255.0
nat=yes
register=guillaumeteilletpro:mypwd33lol@ippi.fr


[ippi]

type=peer
host=ippi.fr
username=guillaumeteilletpro
secret=mypwd33lol
fromuser=guillaumeteilletpro
fromdomain=ippi.fr
nat=yes
canreinvite=no

If you DO NOT want to activate the redirection feature, your sip.conf file should look like this :

[general]

bindaddr = 0.0.0.0
context = ivr_menu
host=dynamic
type=friend
encryption=yes
externip=52.209.221.205
localnet=172.31.34.144/255.255.255.0
nat=yes

Save your file Ctrl + X + S, then press y and enter

A) If you want to activate the redirection feature

Run this on your EC2 instance :

cd /home/ubuntu/ivr-guillaume-teillet
rm extensions_without_redirection.conf
nano extensions.conf

This file is divided in 2 part. First part (l1 -l113) is for the french version of the IVR. Second part (l122 - l225) is for the english version.

We have to update a parameter in the Dial command in [fr_option_3_1] and [en_option_3_1]

[fr_option_3_1]
exten => 35,1,Background(/home/ubuntu/ivr-guillaume-teillet/sounds/fr/fr7)
exten => 35,2,Dial(SIP/ippi/YOUR_PHONE_NUMBER);
[en_option_3_1]
exten => 45,1,Background(/home/ubuntu/ivr-guillaume-teillet/sounds/en/en7)
exten => 45,2,Dial(SIP/ippi/YOUR_PHONE_NUMBER);

Here, replace YOUR_PHONE_NUMBER by your own phone number with the International code (for example france is 33, USA is 1). So you should have something like (for a french number) :

[fr_option_3_1]
exten => 35,1,Background(/home/ubuntu/ivr-guillaume-teillet/sounds/fr/fr7)
exten => 35,2,Dial(SIP/ippi/33612345678);
[en_option_3_1]
exten => 45,1,Background(/home/ubuntu/ivr-guillaume-teillet/sounds/en/en7)
exten => 45,2,Dial(SIP/ippi/33612345678);

Save your file Ctrl + X + S, then press y and enter.

I will explain later the commands (Section "Customize your IVR").

B) If you DO NOT want to activate the redirection feature

Run this on your EC2 instance :

cd /home/ubuntu/ivr-guillaume-teillet
rm extensions.conf
cp extensions_without_redirection.conf extensions.conf
nano extensions.conf

This file is divided in 2 part. First part (l1 -l88) is for the french version of the IVR. Second part (l96 - l174) is for the english version.

I will explain later the commands (Section "Customize your IVR").

9. Configuration of the voicemail folder

Run this on your EC2 instance :

cd /home/ubuntu/ivr-guillaume-teillet
mkdir voicemail
chmod 777 voicemail
cp extensions.conf /etc/asterisk/extensions.conf
cp sip.conf /etc/asterisk/sip.conf

10. Open a port on your EC2 Instance

Now we will open the UDP port 5060 in the security group of our EC2 instance.

Go to the instance page :

Select your instance, and click on the security group.

Then, select the Inbound Tab, and click on "Edit"

A popup appears, click on "Add rule", select "Custom UDP rule" in the type field, set the "Port range" at 5060 and set "Source" at "Anywhere". Click on "Save"

11. Create a Nexmo account and buy your first number

Open a free account and get 2 euros welcome credit : https://dashboard.nexmo.com/sign-up

Then, select Numbers in the top menu.

On the Numbers page, select Buy number in the left menu.

On the Buy Numbers page, select a country, a feature (VOICE OR VOICE + SMS), and a type, then click on "Search"

Choose your number on the list and click on "Buy"

A popup appears, click on yes to confirm you want to buy this number.

Then, click to "Your numbers" in the left menu.

On the "Your numbers" page, select "Edit" for you number.

A popup appears, in the "Voice" section, select "Forward to SIP", and set "Number, URL or String" to "30@YOUR_PUBLIC_IP_AWS" (for French version) or to "40@YOUR_PUBLIC_IP_AWS" (for English version)

Save the modification.

12. Try it with your phone !

Run this on your EC2 instance :

asterisk -rvvvvvvvv
core restart now

Now, you can use your phone to call the number you just bought on Nexmo. You should be able to hear the IVR.

If you want to see the incoming call on your number, run this on your EC2 instance :

asterisk -rvvvvvvvv

Now, the asterisk CLI is launched. After updating extensions.conf or sip.conf, you should always run this on your EC2 instance :

asterisk -rvvvvvvvv
core restart now

Customize your IVR

Convert Audio file

If you want to convert your own WAV file for customize your EC2 server, you can run this command on your EC2 :

sox myinitialfile.wav -r 8000 -c 1 -e signed-integer mynewfile.wav -q

Then change the path of the audio file in extensions.conf.

Asterisk CMD

Answer([delay])

If the channel is ringing, answer it, otherwise do nothing. If a delay is specified, Asterisk will wait this number of milliseconds AFTER answering the call. If you want to add a delay prior answering, use Wait.

Goto([[context|]extension|]priority)

Set the priority to the specified value, optionally setting the extension and optionally the context as well. The extension BYEXTENSION is special in that it uses the current extension, thus permitting you to go to a different context, without specifying a specific extension. Please note that the LEADING arguments to Goto() are optional, not the trailing arguments.

Playback(filename1[&filename2...][,options])

Plays the specified sound or video file(s) (you need to omit the filename extension). Sound files are stored in the /var/lib/asterisk/sounds directory by default (the directory path can be changed in asterisk.conf).

Playback is Multi-Language-compliant. It will look in a subdirectory corresponding with the current language code (as set by the SetLanguage command, or the channel's default language code. Failing that, it will play the non-language-specific edition.

Playback will play the whole sound file(s), and when complete, return control. Compare with the Background command, which plays a sound file but returns control immediately, allowing Asterisk to perform other commands on this channel while the sound file is playing.

Background(filename1[&filename2...][|options[|langoverride][|context]])

This application will play the given list of files while waiting for an extension to be dialed by the calling channel. To continue waiting for digits after this application has finished playing files, the WaitExten application should be used. The 'langoverride' option explicity specifies which language to attempt to use for the requested sound files. If a 'context' is specified, this is the dialplan context that this application will use when exiting to a dialed extension. If one of the requested sound files does not exist, call processing will be terminated.

WaitExten(seconds) or WaitExten([seconds][|options])

Waits for the user to enter a new extension for the specified number of seconds, then returns 0. Seconds can be passed with fractions of a second. (eg: 1.5 = 1.5 seconds).

Set(variablename=value[|variable2=value2][|options]) (up to and including Asterisk 1.2)

This application can be used to set the value of channel variables or dialplan functions. It will accept up to 24 name/value pairs upto Asterisk 1.2, but only one name/value pair in Asterisk 1.4 or later. When setting variables, if the variable name is prefixed with _ the variable will be inherited into channels created from the current channel. If the variable name is prefixed with __ the variable will be inherited into channels created from the current channel and all children channels. Next to the Set() command there is also the SET function available.

Record(filename.format[|silence][|maxduration][|option])

Records from the current channel to a sound file saved with the given filename. The format parameter specifies the sound format and the extension of the file. If you don't specify a full path, the file will be stored in the /var/lib/asterisk/sounds directory. If a file with the same name and extension already exists, it will be overwritten. In the case of combined audio & video recording the 'format' refers only to the audio portion, while the video portion of the recording is automatically set to the active video codec (Asterisk 1.2/1.4/1.6 cannot transcode video, at least not without out-of-tree patches). You will, for example, end up with two files: sample.wav (audio) and sample.h263 (video).

The optional parameters are:

  • silence: seconds of silence allowed before the recording is stopped. If missing or 0, silence detection is disabled.
  • maxduration: maximum recording duration in seconds. If missing or 0, there is no maximum.
  • option: may be 'skip' to return immediately if the line is not up, or 'noanswer' to record even if the line is not up.

Hangup(causecode)

This application hangs up the calling channel unconditionally and returns -1. If a causecode is given the channel's hangup cause is set to the given value.

System(command arg1 arg2 etc)

Execute a system (Linux shell) command

Dial(type1/identifier1[&type2/identifier2[&type3/identifier3... ] ], timeout, options, URL)

Attempts to "dial out" on all the specified channels (each specified by a type and identifier) simultaneously. The first channel that answers "wins", and all the other outgoing channels are hung up. The originating channel that triggered this Dial command is then Answered, if necessary, and the two channels are connected together ("bridged") allowing a conversation to take place between them. When the channel that triggered the Dial command hangs up, the Dial command exits.

Troubleshooting

The sound stutters

Asterisk needs bandwidth to work properly. Verify that another program does not consume too much bandwidth or start a a bigger EC2.

Need Help ?

If something doesn't work or if you need help, please open a ticket on this repository.

Useful links

About

My IVR based on Asterisk / Nexmo / ippi.fr

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages