Redial: Interactive Telephony : Week 3

Soft Phones and the Dialplan Continued: Core Concepts, Advanced Commands

Soft Phones

Since we are using VoIP and Asterisk, we have the option of using Soft Phones. Soft Phones are VoIP phone implementations in software and they run on a desktop or laptop (other devices too but we will get to that later).

Normally someone would use a soft phone like Skype or Gizmo to contact a service provider (a TSP) on the internet and the calls would be routed through that network. Since we are using Asterisk, we can setup our softphones to connect directly to our Asterisk server, in effect creating our own network.

As we discussed, Asterisk can work with a variety of different protocols and the next version even supports Skype so we can be pretty flexible with the choice of soft phones. To make things a bit easier, our Asterisk server is setup to deal with both SIP and IAX (pronounced eecks) protocols. We have discussed SIP quite a bit in the past so we won't go into detail here.

IAX stands for Inter-Asterisk Exchange and was developed primarily for use with Asterisk. The benefits of using IAX over SIP is that it can easily route through home firewalls and NAT routers while SIP has problems with such. Unfortunately, by using IAX we are diverging from established standards.

Some Softphones

iaxComm

iaxComm is an open source softphone that uses IAX to communicate with other softphones or PBX's. It is a bit buggy but is cross platform with versions for Windows, Mac and Linux. You can download is here: http://iaxclient.sourceforge.net/iaxcomm/. For the Mac version you have to scroll down the page a bit looking for "iaxcomm-mac-1.0rc1.zip".

To setup iaxComm to work with our Asterisk server we need to use the iax.conf file. Just like the other conf files that we are editing, I setup a way to dynamically include our individual conf files into the main conf file. Use the following naming convention to create your own iax.conf file in the asterisk_conf directory:

net-id_iax.conf

Mine is called sve204_iax.conf and contains the following:

[redial_iax]
type=friend
host=dynamic
username=redial_iax
secret=redial_iax
auth=md5
context=redial_iax
		
While this shouldn't be required, it seems that the top line (the IAX context) should match the username. The "type" "friend" means that this softphone can both make and receive calls. We will primarily be using this to make calls. "secret" is the password, "auth" is the type of encryption that is used when transferring the password over the network, "context" is the context in the dialplan that is first used when this softphone dials our server.

The context that I am using, redial_iax is defined as follows:

[redial_iax]
exten => Answer();
exten => _X,1,Goto(2127960961,s,1)
		
It is defined in "redial_iax_extensions.conf. The first line tells Asterisk to answer the line when a call comes in. The second line is a regular expression that matches a dialed extension. In this case a single digit. It jumps to the "2127980961" context which is the main context that is being used when we dial in from any normal phone. In a sense this context sets the softphone to behave as it is any normal phone coming in to our Asterisk setup by dialing 2127960961. (Don't forget to "reload" which will activate your iax.conf file using our reload URL: http://social.itp.tsoa.nyu.edu/asterisk/asterisk_reload.php

I would suggest that if you want to use a softphone to make it easier to create and work with your applications on Asterisk that you use this same context in your IAX configuration.

In iaxComm's account settings, (under Options), you put an Account Name, I usually match this with the username but I don't think it is important. You put the host, which should be "social.itp.tsoa.nyu.edu", the username which you defined in the iax.conf file (which should be something like netid_iax) and the password which you defined in the iax.conf file.

When you launch iaxComm it should automatically connect to our Asterisk server. To make a call into the context as I have suggested, you just need to dial one digit and push "Dial". If you are having problems, log into the asterisk manager interface and issue the command: iax2 debug. This will give you debugging output. To turn off debugging (which I would do quickly to be nice to everyone else using the interface, issue the command "iax2 no debug".

Gizmo

Gizmo is a free SIP based soft phone that is cross platform (unfortunately, I don't think it is open source). It was developed to be used with the SIPPhone network (which is cool and you should check it out) but has the means to be used with a different network by setting up a "secondary" connection. You can download it here: http://www.gizmoproject.com/

To use Gizmo (or any other SIP softphone) you need to create an entry in sip.conf. Just like all of our other configuration files, you can create a file in the asterisk_conf directory using the naming convention "netid_sip.conf" and it will be automatically included in the main configuration when you "reload".

Here are the contents of sve204_sip.conf:
[sve204_gizmo]
type=friend
username=sve204_gizmo
secret=sve204_gizmo
host=dynamic
dtmfmode=rfc2833
allowguest=yes
insecure=very
promiscredir=yes
context=redial_sip
		
Almost all of the options are the same as with the iax.conf file. As with using an IAX softphone, a context from the dialplan is specified. In this case, I am using redial_sip which is defined in redial_sip_extensions.conf.

Here are the contexts of redial_sip_extensions.conf:
[redial_sip]
exten => Answer();
exten => _X,1,Goto(2127960961,s,1)
		
It does the exact same thing as redial_iax, drops the caller into the 2127960961 context so that everything behaves as if it was a normal incoming call.

Unfortunately, in order to use Gizmo you first have to register an account on the SIPPhone network. Gizmo will prompt you to do that when you first launch it. After you have done this you can specify a "secondary account". This is where you will put the corresponding information from your sip.conf file.

When you launch Gizmo from now on it should automatically connect to our Asterisk server. Before you call, you should choose your secondary account for your "Outgoing Call Account" under "Account" and only dial 1 digit.

There are a bunch more SIP and IAX based softphones. Please feel free to try another one if you like. Here is a good list: http://en.wikipedia.org/wiki/Comparison_of_VoIP_software

More Information:

  • IAX - voip-info.org
  • IAX vs SIP
  • A search for IAX or SIP on Voip-Info.org will yield a ton of results. Have a look.


  • Parse Mail Script Take 2

    Here is another version of the parse mail script that we took a look at briefly last week: http://itp.nyu.edu/~sve204/redial/parseVMailMailScript.txt

    This version is specific to receiving and posting to a blog voicemail attachments that are sent to email with the configuration we have setup on our server.

    To use this script as is you need to edit the top portion of the script:

    ###
    # User Configurable Variables
    ###
    my $username = "xxxxx"; ## This is your email username, it might be in the form of your entire address: something@something.com in which case you need to escape the @ with a \.  Like so: something\@something.com
    my $password = "xxxxx";  ## This is your email password
    my $mailserver = "mail.xxxx.com"; ## This is your mail server
    my $temp_folder = "/home/sve204/redial_popper/temp/"; ## This is a directory you should setup on the same server as this script is running to save any temporary or working files.
    my $attachment_output_folder = "/home/sve204/public_html/redial_vmail/"; ## This is the directory on the server that this script is running that will house the saved email attachments.  This should be in your public_html directory.
    my $attachment_output_folder_relative = "http://itp.nyu.edu/~sve204/redial_vmail/"; ## This should be the http:// verision of the same directory.  Like what you would put in the location bar of a web browser to access that directory.
    my $blog_xmlrpc_url = "http://www.mobvcasting.com/wp/xmlrpc.php"; ##  This is the URL to your XML-RPC application on your blog.  WordPress and MT work well, I have not tested with other blogging software.
    my $blog_id = 0; ## This is the ID number of your blog.  This is only relevant to Moveable Type.
    my $blog_username = "xxxx"; ## This is the username for posting to your blog.
    my $blog_password = "xxxx"; ## This is the password for posting to your blog.  Careful on MT this is not the same as your password for logging onto your blog.  This is a separate option in the user configuration portion of the blog admin interface.
    
    my $use_wp_plugin = 1; ## If you are using this with WordPress and 
    ## you are using my Word Press Plugin: 
    ## http://www.walking-productions.com/QuickTimePostWPP/
    ## Wordpress strips out non-standard tags, like those used to embed audio files on a page.  This plugin fixes that issue.
    		
    Later in the script you will see a line like this:
    $body = "New Message from $vm_callerid at $vm_date.  It is message number $vm_messagenum and is $vm_duration long.  The name is $vm_name and the mailbox is $vm_mailbox\n";		
    		
    To change the body of the posting you would edit this line. The above variables should all be available.

    There is a something similar for the subject/title of the post. Right now it is set to post the subject of the email as the title.

    To make this script work you should download it, change the configuration options, save it as a .pl file and upload it to a webserver. You can run it by typing: perl parseVMailMailScript.pl

    To make it run automatically you will need to use a unix utility called cron. Here is some information about that: http://itp.nyu.edu/~sve204/ppmblog/?p=98

    Dialplan Dialplan Dialplan Dialplan

    Last week we went over several commands/applications that can be used in the Asterisk Dialplan. This week I want to go over some of the more difficult or advanced features.

    Predefined Channel Variables:
    Under the heading "Predefined Channel Variables" this page lists all of the variables that are predefined for you. You can use these variables in your dialplan logic.

    A good way to get started is to use them with the NoOp command. This will output them on the Asterisk console so you can see their values:
    exten => s,n,NoOp(${CALLERIDNAME});
    exten => s,n,NoOp(${SIPUSERAGENT});
    exten => s,n,NoOp(${CALLERIDNUM});
    exten => s,n,NoOp(${EXTEN});
    		
    Pattern Matching:
    When you define an extension in Asterisk you can either choose to put the exact digits or use a pattern to match the extension.

    The "_" indicates that we are using a pattern.
    The "X" matches any digit
    The "." matches anything one or more times.
    Brackets "[" enclose ranges. "[13-5]" matches 1, 3, 4, and 5.

    Using patterns allows you to capture user input. The exact input will always be in the EXTEN variable so you can use that in your logic.

    There is a very good write-up regarding pattern matching in the Asterisk book. Check Chapter 5 around page 92.

    Database Interaction:
    Last week we discussed variables and so on. The problem with variables is that they go away once a call is completed. To save data you can use the AstDB.

    To put a value in the AstDB you use the Set command (just like variables) but also use the DB command inside the Set command, like so:

    exten => s,1,Set(DB(sve204/lastcalltime)=${DATETIME})

    This sets a value in the "sve204" family called "lastcalltime". The value of the variable is the current date and time (a predefined variable).

    I can get the value of this out of the database by using the following command:

    exten => s,n,Set(LASTCALLTIME=${DB(sve204/lastcalltime)});

    This would set the value in a variable called LASTCALLTIME which tell me the last time someone called and the above code got executed.

    Say I wanted to keep a log of how many times anyone did something on the system. I could do the following:

    exten => s,n,Set(SOMETHING=${DB(sve204/something)})
    exten => s,n,SetVar(SOMETHING=$[${SOMETHING} + 1])
    exten => s,n,Set(DB(sve204/something)=${DB(sve204/something)}
    		


    Outbound Dialing:
    Asterisk can make outbound calls as well as receive incoming calls. To make an outbound call from your dialplan you use the Dial application.

    exten => s,1,Dial(SIP/itp_jnctn/17188096659,30,r);

    The above command will always dial my cell phone. The command is Dial, the first argument the connection type which for our purposes will be SIP. The second is the SIP context (the channel) to use for dialing. For our purposes it will always be "itp_jnctn". This is followed by the number or extension to dial. The 30 means wait 30 seconds and the "r" means indicate ringing to us.

    Asterisk cmd Dial - Voip-Info.org

    Recording Audio:
    Records what a user says for a specified period of time.

    exten => s,1,Record(sve204_menu.gsm|5|30);

    The first argument is the name of the file with the format, after the slash it is the amount of silence detection (in seconds I beleive) and the next argument is the amount of time to record.

    Asterisk cmd Record

    Playback with Controls:
    Plays an audio file with controls.

    exten => s,n,ControlPlayback(shawn_test,1000,#,*,0,1,2);

    The first argument is the name of the file to play, the second the number of milliseconds to move per button push. The last arguments are the buttons for rewind, fast forward, stop, play and pause.

    Asterisk cmd ControlPlayback

    Monitoring/Recording a Channel:
    Asterisk can record the audio of a call. By default it saves the audio in two separate files, one for each side of the "conversation".

    exten => s,1,Monitor(wav,shawn_monitor);

    This command will create two files, both in /var/spool/asterisk/monitor. One will be named shawn_monitor-in.wav, the other shawn_monitor-out.wav.

    Asterisk cmd Monitor
    Also checkout MixMonitor which mixes the two channels at: Asterisk cmd MixMonitory

    Executing a System Command:
    Asterisk can work with other applications running on the same machine. For instance the following command will use a program called LAME (lame ain't an mp3 encoder) to convert a recorded audio file to an MP3 file (which might be useful for those working posting these files online).

    exten => s,1,Record(/home/sve204/converter.wav|5|30); exten => s,n,TrySystem(lame /home/sve204/converter.wav /home/sve204/converter.mp3);

    Asterisk cmd System

    Automated Outbound Calling

    Asterisk can make outbound calls without having someone call in the first place (as with the Dial command shown above). The means to do this is in the creation of a "call file", simply a text file such as follows:

    Channel: SIP/itp_broadvoice/17188096659
    MaxRetries: 1
    RetryTime: 60
    WaitTime: 30
    Context: itp_broadvoice_hello_out
    Extension: 1
    Priority: 1
    		
    This "call file" is simply a text file. The first line specifies the channel to use, in this case SIP/itp_broadvoice and the extension, in this case, my phone number. The next line is the number of times that asterisk should try calling, the amount of times in between retries (in seconds) and the initial wait time to make the call. Next it specifies which dialplan context to put the call in along with what extension and priority to use in that context.

    There are other options available such as setting the caller id of the outbound call: CallerID: Some Name <7188096659>

    In order to tell asterisk to read and use this call file it needs to be placed into the /var/spool/asterisk/outgoing/ directory. You need to "mv" this file there instead of creating it there in the first place. Also Asterisk needs to have permission enough to delete the file when it is done with it. Here are the steps that I use on the command line after creating the call file:

    chmod 777 callfile.call
    mv callfile.call /var/spool/asterisk/outgoing/.
    
    Note above that the call file enters the call into a context, extension and priority. Here is the context that the above example is using:

    [itp_broadvoice_hello_out]
    exten => 1,1,Monitor(wav,shawn_test,m)
    exten => 1,2,Playback(vm-goodbye)
    exten => 1,3,Hangup()
    
    Nothing special about it except that since we are going to extension 1 in the call file we need to have extension 1 defined in the context.

    More information
  • Asterisk auto-dial out