Timing Music on Hold


Asterisk's Music On Hold (moh) is a great feature to enhance the ergonomy of an auto attendant (IVR).

Nevertheless, it lacks provision to play music for a limited given length of time.

As a result, one cannot trivially rely on basic moh features for providing the incoming call with a few seconds of music before connecting to the auto-attendant.

A solution

What if we could dial a fake number for a given length of time, say 10 seconds, and tell Dial() to play moh (option m in third argument) during this time, something like :


This idea makes the basis of our solution.

  • Step 1 : Define a moh timer.

First, define a section in the Asterisk's dialplan (file extensions.conf) to mimic a timer, something that takes one argument (the extension) to set the number of seconds the timer should run before going off :

exten => _X!,1,Wait(${EXTEN})

  • Step 2 : Call this timer by dialing it through a local channel (reentrant call to the Dialplan)

Dial(local/10@moh_timer,10,m)    ;  play 10 seconds of moh !

  • Step 3 : Use an Asterisk's macro to provide the user with a friendly interface

exten => s,1,Dial(local/${ARG1}@moh_timer,${ARG1},m)

  • Step 4 : Plug the whole thing to the general diaplan

exten => s,1,Answer()
exten => s,n,Macro(moh,5)     ; Please give the incoming call 5 seconds of music on hold! Thanks :-)
exten => s,n,Goto(ivr,s,1)


Download code

Timing Asterisk's MOH (794 bytes)


Franck PORCHER,Ph.D.


Fri 17 of Oct, 2008 (10:25 UTC)


21803 times.

Created by: fporcher, Last modification: Fri 17 of Oct, 2008 (10: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+