Email notifications for missed calls in Asterisk

May 5th, 2007

A feature I have wanted for a long time is to get emails about missed calls. I have a Blackberry and knowing that people are calling and hanging up before leaving a vm is very useful when I am out in the field. I wrote a small shell script to add this functionality to Asterisk.

I place the script in the h extension of the stdexten marco. The h extension triggers once a call is hung up from that context. The first and only priority for the h extension is a System() call. It calls this shell script and passes many parameters to it. The first parameter is the email address to send the email to. To make this work for the marco, I adjust the macro to have a third parameter which is email address. I would like to pull the email address from that extensions vm but that function does not exist and I could not figure out how to add that function in the C source code. If anyone knows a better way, please let me know. The script requires you have the mailx package installed.

  • Download the script
  • Rename the file processCallEmail.sh.
    mv processCallEmail.txt processCallEmail.sh
  • Put it in the /var/lib/asterisk/agi-bin directory.
    mv processCallEmail.sh /var/lib/asterisk/agi-bin/"
  • Make sure the asterisk user has execute permissions on the script.
    chmod 755 /var/lib/asterisk/agi-bin/
    processCallEmail.sh
  • Add one line of documentation to macro-stdexten context on the line after ${ARG2}. ; ${ARG3} - email address to send emails about missed calls to
  • Add the h extension line to the macro-stdexten context. exten => h,1,System(processCallEmail.sh "${ARG3}" "${CALLERID(num)}" "${CALLERID(name) }" "${DIALSTATUS}" "${VMSTATUS}")
  • Alter the line that calls the macro to include an email address. exten => 500,1,Macro(stdexten,500,SIP/${EXTEN},abc@test.com)

Here is an example of an updated stdexten macro.
[macro-stdexten];
;
; Standard extension macro:
; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
; ${ARG2} - Device(s) to ring
; ${ARG3} - email address to send emails about missed calls to
;
exten => s,1,AGI(ldaplookupphone2.agi)
exten => s,n,Dial(${ARG2},20) ; Ring the interface, 20 seconds maximum
exten => s,n,Goto(s-${DIALSTATUS},1) ; Jump based on status NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)

exten => s-NOANSWER,1,Voicemail(${ARG1},u) ; If unavailable, send to voicemail w/ unavail announce

exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start

exten => s-BUSY,1,Voicemail(${ARG1},b) ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start

exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer

exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain

exten => h,1,System(
processCallEmail.sh "${ARG3}" "${CALLERID(num)}" "${CALLERID(name) }" "${DIALSTATUS}" "${VMSTATUS}")

Answering machine detection

May 2nd, 2007

Today I worked with the Asterisk function amd. Amd stand for answering machine detection and after my initial testing it seems to work very well. The documentation on the function is written very cryptically. I decided to just use the defaults and it worked amazingly well. For any auto dialing applications I highly recommend trying this function.

To help me get started I grabbed an example from the wiki and used an example from it. Here is the example from the wiki modified for Asterisk 1.4. I updated the wiki with the relevant 1.4 information.

[outbound]
exten => s,1,NoCDR
exten => s,n,AMD
exten => s,n,GotoIf($[${AMDSTATUS}=HUMAN]?humn:mach)
exten => s,n(mach),WaitForSilence(2500)
exten => s,n,Playback(message-when-machine)
exten => s,n,Hangup
exten => s,n(humn),WaitForSilence(500)
exten => s,n,Playback(message-when-human)
exten => s,n,Hangup

Recover documents from a corrupt Lotus Notes database

April 12th, 2007

Today when I was reading an IBM RSS feed about Lotus Domino, I stumbled upon an interesting technote on how to recover documents from a corrupted Lotus Notes database. The technote first recommends you attempt the standard fixup, updall and compact. However if those don’t work, this is something else to try.

The process recommended is to write an agent that will attempt to copy each document in the database to a new database. The technote has sample code that you could easily copy and paste with only a couple of tweaks to the filenames. I have never had a database that needed this but being prepared could come in handy in an emergency.

Asterisk caller id lookup via LDAP to a Domino Directory

April 12th, 2007

I got an idea last night to have Asterisk do a LDAP lookup to a Lotus Domino Directory for caller id names. This provides caller id names for any company phone number listed in the directory including people’s cell phone numbers. Today I spent a few of hours writing a shell script to be called via the Asterisk Gateway Interface(AGI). The AGI is very powerful with interfaces to many programming languages like PHP, Perl, Python, Ruby and shell. There are many examples on the voip-info.org wiki.

The shell script is called via the Asterisk dialplan on incoming calls. The shell script get passed all the standard AGI variables which includes the caller id number of the caller. The script requires OpenLDAP to be installed on the Asterisk server because it uses the ldapsearch function. The script builds a LDAP search filter and queries the LDAP server for any users with a matching phone number. It then sends a “set callerid” command via the AGI to add the name to the call.

Domino’s LDAP server seems to respond very fast and the script takes around 1/4 of a second to process. I don’t consider script to be done and still needs more error checking added. I figured I would post what I have so others can build off of what I have started. Here are some instructions if you want to use what I created. The Asterisk server I was using is running 1.4.2 . I think it will work fine with prior versions of 1.2.x, however I have not tested it on that.

  • Download Asterisk AGI script.
  • Rename the file ldaplookupphone.agi.
    mv ldaplookupphone.txt ldaplookupphone.agi
  • Put it in the /var/lib/asterisk/agi-bin directory.
    mv ldaplookupphone.agi /var/lib/asterisk/agi-bin/”
  • Make sure the asterisk user has execute permissions on the script.
    chmod 755 /var/lib/asterisk/agi-bin/ldaplookupphone.agi
  • Update 3 variables at the top of the script for the hostname, username and password for the LDAP server.
  • Follow the example below to alter your extensions.conf to run the script before calling the Dial application. After you make changes in extensions.com remember to run dialplan reload at the Asterisk console.

Here is an example dialplan.
exten => 1234,1,Dial(SIP/1000)

It should be changed to look like this.
exten => 1234,1,AGI(ldaplookupphone.agi)
exten => 1234,n,Dial(SIP/1000)

In the future I hope to post other ways to do lookups to Lotus Notes databases from Asterisk AGI scripts.