Realtime voicemail tricks

This uses the func_odbc app. So you will have to figure out how to get that work ;)
I am using Postgres.

The problem

I have many unique extensions (DIDs) and I want to only have one DID number used up for the voicemail application (get your voicemail) even thought, I have lots of contexts for peoples voicemails.

The sql

Here is the function I wrote for the func_odbc:

-- Function: get_context_for_voicemail
-- Args:
-- extension --> the extension to lookup
-- Returns:
-- the context or blank if not found
-- Description:
-- This function is used to find the context of a given extension
CREATE OR REPLACE FUNCTION get_context_for_voicemail(
)RETURNS varchar(50) AS '
_extension alias for $1;
_context varchar(50);
_context := none;
SELECT INTO _context context from voicemail where mailbox=_extension;
RETURN _context;
' LANGUAGE 'plpgsql';

As you can see, this function is looking for the extension (mailbox) inside the voicemail table and returning the context that is part of the row specified.
The assumption here is that you don't have the same extensions in more than one context. This is for people that are using DID's or that are using unique extensions.

The func_odbc.conf

read=select get_context_for_voicemail('${ARG1}')

The macro to be called:

exten => s,1,NoOp("Macro voicemail-main: Macro-Exten: ${MACRO_EXTEN})
exten => s,n(start),Read(VM_EXTEN|'vm-login'|10||3|4)
exten => s,n,NoOp("User entered: ${VM_EXTEN})
exten => s,n,GotoIf($[${VM_CONTEXT}none = 'none']?error:password)

exten => s,n(password),NoOp("Request a password for ${RESULT} and ${VM_EXTEN}")
exten => s,n,VoicemailMain(${VM_EXTEN}@${VM_CONTEXT})
exten => s,n,Hangup

exten => s,n(error),Playback(vm-incorrect)
exten => s,n,Goto(s,start)

exten => i,1,NoOp("Invalid extension reached")
exten => i,n,Goto(s,error)

exten => t,1,NoOp("Timeout extension reached")
exten => t,n,Goto(s,error)

So, with this you can have one phone number act as the voicemailmain for many context. It uses the Realtime subsystem so that the valid voicemails are in the database in this case pointed to by the DSN asterisk.
I am sure there are some that will say it is a security issue that I have created by making the system this way. One of the reason for contexts is to provide segmentation. That is fine for inbound and outbound calls, etc, but if you have hundreds of users that all want/need to check voicemail, this seems like a good way to keep voicemail in seperate contexts (read disks if you like :), but still only have one number to dial for voicemail. Obviously this is for people that are offering Asterisk as a service :)
~ Cheers

Created by: blankman, Last modification: Fri 07 of Jul, 2006 (05:25 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+