Howto:Dynamic MOH: Difference between revisions

From innovaphone wiki
Jump to navigation Jump to search
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<!-- Keywords: dynamic moh, moh per user, moh per group -->
<!-- Keywords: dynamic moh, moh per user -->
==Applies To==
==Applies To==
This information applies to
This information applies to


V12r2 and later
* V9 and later
==More Information==
==More Information==
===Problem Details===
===Problem Details===
Sometimes it is desired to be able to play a different MOH per user, group or special selection.
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''.  


We can store a custom logic, and then redirect to the MOH to use with an HTTP redirect.
This article describes how to implement more complex custom logic schemes to select the MOH based on this mechanism.


;Often you also able to solve your problem with the native methods in the PBX [[Reference13r1:PBX/Config/General]]
=== 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===
===System Requirements===
A Linux Application Platform or a Webserver with PHP or something similar.
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.


===Installation===
===Example===
Use the following URL as ''Music On Hold URL'' in your PBX.
Let us assume your logic is implemented in the moh.php module which resides in the path
https://tld.com/dynamic_moh/moh.php?codec=$coder&coder=g722,g711a,g711u,g729,g723&user=%h


Create a PHP script on your LinuxAP with the following content
:<code>/var/www/innovaphone/dynamic_moh/moh.php</code>


<code php>
on your web server
<?php
 
:<code>tld.com</code>
 
directly in the innovaphone application platform (not in the webdav partition!!). 
Please also configure a public [[Reference10:Concept_Linux_Application_Platform#Change_web_server_properties_and_public_access_to_the_web.2Fwebdav|Web Path]] to your new folder or use HTTP Authorisation on the PBX.
 
You would configure the following URL as ''Music On Hold URL'' in your PBX:
 
<code>https://tld.com/dynamic_moh/moh.php?codec=$coder&coder=g722,g711a,g711u,g729,g723&user=%h</code>
 
The interesting part is <code>&user=%h</code>.  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 <code>opus-wb</code>) so we end up with


// $_GET['codec'] contains the selected codec
<code>https://tld.com/dynamic_moh/moh.php?codec=opus-wb&coder=g722,g711a,g711u,g729,g723&user=alice</code>.  
// $_GET['user'] contains the H.323 name of the user who initiated the consultation


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).


// create a SOAP lookup to the PBX (group membership, pbx selection, etc.)
Finally, the GET request is redirected to the URL of the real sound file (this is what the <code>Location:</code> header does in the sample code below).
// create a CURL lookup to a different system
// create whatever you need to make a decision


// use your own criteria from above
<syntaxhighlight lang="php">
<?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') {
if ($_GET['user'] == 'alice') {
     header("Location: https://tld.com/webdav/announcements/special_moh_for_alice.".$_GET['codec']);
     header("Location: https://tld.com/webdav/announcements/special_moh_for_alice.".$_GET['codec']);
Line 40: Line 53:
     header("Location: https://tld.com/webdav/announcements/default_moh.".$_GET['codec']);
     header("Location: https://tld.com/webdav/announcements/default_moh.".$_GET['codec']);
}
}
?>
?>
</syntaxhighlight>


</code>
== Related Articles ==
 
* [[Reference13r1:PBX/Config/General]]
===Known Problems===
* [[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
 
* [http://www.innovaphone.com/en/services/support/convert.html innovaphone Audio Converter]  for how to convert your own wave files in to sound files suitable for the PBX
<!-- == Related Articles == -->


[[Category:Howto|{{PAGENAME}}]]
[[Category:Howto|{{PAGENAME}}]]

Latest revision as of 13:04, 10 May 2023

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!!). Please also configure a public Web Path to your new folder or use HTTP Authorisation on the PBX.

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