Howto:Dynamic MOH
Applies To
This information applies to
- V9 and later
More Information
Problem Details
Sometimes it is desired to play a different music on hold (MOH) based on the user, node or PBX of the calling or called user. The PBX has a mechanism to implement this known as %-URL parameters. They are described in Reference13r1:PBX/Config/General#Common, Music On Hold URL.
This article describes how to implement more complex custom logic schemes to select the MOH based on this mechanism.
Solution
The trick to "insert" your own custom logic is based on the fact that the PBX will always retrieve the MOH as a sound file from an URL using HTTP GET. This is done on a call-by-call basis, that is, the sound file is retrieved for each call individually. This URL is part of the PBX configuration and allows for the expansion of some call related parameters (see the reference article linked to above). The URL we use does not refer to a sound file directly. Instead, it refers to a web site that implements our custom logic and then redirects the GET requests to the real sound file. The PBX would then follow this redirect and retrieves the sound file.
System Requirements
To implement the custom logic, you need a web server with support for a web programming language (such as e.g. PHP). This might be a Linux Application Platform or a Webserver with PHP or something similar.
Example
Let us assume your logic is implemented in the moh.php module which resides in the path /var/www/innovaphone/dynamic_moh/moh.php
on your web server tld.com
directly in the innovaphone application platform (not in the webdav partition!!).
You would configure the following URL as Music On Hold URL in your PBX:
https://tld.com/dynamic_moh/moh.php?codec=$coder&coder=g722,g711a,g711u,g729,g723&user=%h
The interesting part is &user=%h
. When retrieving the MOH, the PBX will replace it with the Name of the calling user (lets say alice). Also, as usual, the $coder variable will be substituted (say with opus-wb
) so we end up with
https://tld.com/dynamic_moh/moh.php?codec=opus-wb&coder=g722,g711a,g711u,g729,g723&user=alice
.
In your PHP code in moh.php, you now have access to the parameters codec and user and can select the right sound file based on this information (or any other information you have at hand, as e.g. the time of day or a database lookup).
Finally, the GET request is redirected to the URL of the real sound file (this is what the Location:
header does in the sample code below).
<?php
// $_GET['codec'] contains the selected codec
// $_GET['user'] contains the H.323 name of the user who initiated the consultation
// select the sound file
if ($_GET['user'] == 'alice') {
header("Location: https://tld.com/webdav/announcements/special_moh_for_alice.".$_GET['codec']);
} elseif ($_GET['user'] == 'cooper') {
header("Location: https://tld.com/webdav/announcements/special_moh_for_cooper.".$_GET['codec']);
} else {
header("Location: https://tld.com/webdav/announcements/default_moh.".$_GET['codec']);
}
?>
Related Articles
- Reference13r1:PBX/Config/General
- Howto:Can I download the innovaphone built-in music on hold as a wave file? for how to get at the default music on hold as a sound file
- innovaphone Audio Converter for how to convert your own wave files in to sound files suitable for the PBX