Upgrade 3CX to v18 and get it hosted free!

Realtime voicemail tricks

Author image

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(
voicemail.mailbox%TYPE
)RETURNS varchar(50) AS ‘
DECLARE
_extension alias for $1;
_context varchar(50);
BEGIN
_context := none;
SELECT INTO _context context from voicemail where mailbox=_extension;
RETURN _context;
END;
‘ 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.
Note
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

[GET_VOICEMAIL_CONTEXT]
dsn=asterisk
escapecommas=no
read=select get_context_for_voicemail(‘${ARG1}’)

The macro to be called:

[macro-voicemail-main]
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,Set(VM_CONTEXT=${ODBC_GET_VOICEMAIL_CONTEXT(${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.

Note

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


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.
Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.