Skip to main content

Send Urgent Voicemails to Email

Posted by k3leland on Wed, 08/25/2010

I am trying to configure the following:

When someone is leaving a voicemail message they are given the option to mark it as urgent. If they mark it as urgent an email is sent, otherwise no email is sent.

So far my best option is to have two distinct voicemail boxes preceded by an ivr which allows the user to choose whether they want to leave a voicemail in the "urgent voicemail box" or the "regular voicemail box." This has the disadvantage that the customer has to maintain 2 separate boxes.

Any suggestions would be appreciated.


Submitted by k3leland on Wed, 08/25/2010 Permalink

Forgot to mention this is a MTE installation.

Here is a second solution:
Use externnotify and write a script that sends emails conditionally if all of the following are true:
1) context = default-tenantname
2) extension = voicemail box I am interested in
3) most recent message in /var/spool/asterisk/voicemail/tenant/ is in the urgent folder

This has the disadvantage that this script has to be run much more often than it really needs to be.
Specifically it will be run every time a voicemail box is left for any tenant, and anytime anyone checks a voicemail box. This isn't really what this hook is meant for.

Submitted by k3leland on Thu, 08/26/2010 Permalink

We ended up creating a new script in the library called 'mtt-goto-voicemail-urgent-and-email' that takes all of the same arguments of 'tl-goto-voicemail' plus one additional argument: email address. We create the voicemail box normally and all messages that are left in that voicemail box through tl-goto-voicemail will not generate an email alert. In an IVR we conditionally send a user to that voicemail box through our new 'mtt-goto-voicemail-urgent-and-email' script which causes an email to be sent and the message to be marked as urgent.

You would think this is something that eventually will be integrated into asterisk's voicemail system; sending emails conditionally on the urgent flag. We are using this to satisfy feature requests coming from doctors offices.

Anyway here is the code.

mtt-goto-voicemail-urgent-and-email


exten => s,1,Set(MAILBOX=${ARG1})
exten => s,n,Set(OPTIONS=${ARG2})
exten => s,n,Set(OP_EXTEN=${ARG3})
exten => s,n,Set(EMAIL=${ARG4}
exten => s,n,Goto(voicemail-urgent-and-email,s,1)

which goes to a context that we created in extensions.conf:


[voicemail-urgent-and-email]

exten => s,1,VoiceMail(${MAILBOX},U${OPTIONS})

exten => o,1,GotoIf($["${OP_EXTEN}" = ""]?check)
exten => o,n,Set(OPERATOR=${OP_EXTEN})
exten => o,n(check),GotoIf($["${OPERATOR}" != ""]?dial)
exten => o,n,Set(OPERATOR=0)
exten => o,n(dial),Dial(Local/${OPERATOR}@from-inside${TL_DASH}${tenant})

exten => a,1,VoiceMailMain(${ARG1})
exten => a,n,Hangup

exten => h,1,Execif($[ "${VMSTATUS}" = "SUCCESS" ]?System(/usr/local/bin/notifyurgent.rb ${MAILBOX} ${EMAIL}))
exten => h,n,Hangup

which calls the script notifyurgent.rb:


#!/bin/env ruby

require 'net/smtp'

# This script takes 2 parameters
#

message = <
To: Ken Leland III
Subject: Urgent VoiceMail Message

This is a test e-mail message.
MESSAGE_END

Net::SMTP.start('smtp.serverofyourchoice.com') do |smtp|
smtp.send_message message, 'donotreply@testing.com',
'test@testing.com'
end

Submitted by thirdlane on Thu, 08/26/2010 Permalink

Very nice! This is exactly how PBX Manager is supposed to be extended. FYI, you should put voicemail-urgent-and-email (or any custom code) into user_extensions.include which is untouched during product updates