[mythtv-users] Little Off Topic: FreePBX -> Growl Notifications

Scott & Nicole Harris snharris99 at live.com
Mon Jan 2 17:58:44 UTC 2012


>I installed trunk on my laptop today to play around with this.  The command
>line method (mythmessage --message_text=Hello World!) seems to work fine.
>However, the url method (which I think will ultimately make sending my
>caller id freepbx almost embarrassingly simple) does not seem to work...


Well, I got it working, though I won't be implementing anything until trunk 
becomes release and there's a timeout option in MythMessage.  The timeout 
feature is a bit key, because I have frontends hooked up to both my master 
and secondary backends, so without a timeout, Caller ID messages could start 
stacking up on them before someone turned them on for use.

FWIW, for posterity, I came up with two ways of handling it.....

1) Use "Send To URL" feature of CallerIDSuperfecta already installed on my 
FreePBX box which will append the query string 
?thenumber=INCOMING_CALLER_NUMBER&CLID=INCOMING_CALLER_NAME to the url you 
specify and forward it.  I then created a simple php page in /var/www on my 
master backend and used that as the "Send To" url...

function format_phone()
{
    $phone = preg_replace("/[^0-9]/", "", 
htmlspecialchars($_GET["thenumber"]));

    if(strlen($phone) == 7)
        return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
    elseif(strlen($phone) == 10)
        return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) 
$2-$3", $phone);
    elseif(strlen($phone) == 11)
        return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) 
$2-$3", ltrim($phone, "1"));
    else
        return $phone;
}
// set the message to the caller id and name
$callerName = htmlspecialchars($_GET["CLID"]);
$callerNumber = format_phone();
$message = urlencode("Incoming Call: $callerName ~ $callerNumber");

// set an array with all hosts we want to send to
$hosts = array("frontend1", "frontend2");

// loop through the hosts and send the message
foreach ($hosts as &$value) {
    readfile("http://$value:6544/Myth/SendMessage?Message=$message");
}

I've never written any php before so if anyone has any tips on cleaning that 
up, feel free.

I also had to modify source-Send_to_URL.php in 
/var/www/html/admin/modules/superfecta/bin to urlencode the caller name 
because it was being passed with spaces so everything past the first string 
was getting dropped.

This has the benefit of being very simple to set up, works for all incoming 
calls to your pbx and you don't have to deal with any custom extensions, 
follow me's, ring groups, etc in FreePBX.  I would think most people would 
be using CallerID Superfecta already because it makes cid look ups so 
simple.

2) Involves adding custom context / extension to 
/etc/asterisk/extensions_custom.conf...

[from-internal-custom]
exten => ****101,1,Set(len=$[${LEN(${CALLERID(num)})}])
exten => ****101,n,GotoIf($[${len} < 7]?send)
exten => 
****101,n,Set(CALLERID(num)=${CALLERID(num):0:$[${len}-4]}-${CALLERID(num):$[${len}-4]:${len}})
exten => ****101,n,GotoIf($[${len} < 8]?send)
exten => 
****101,n,Set(CALLERID(num)=${CALLERID(num):0:$[${len}-7]}-${CALLERID(num):$[${len}-7]:$[${len}+1]})
exten => ****101,n,GotoIf($[${len} < 11]?send)
exten => 
****101,n,Set(CALLERID(num)=${CALLERID(num):0:$[${len}-10]}-${CALLERID(num):$[${len}-10]:$[${len}+3]})
exten => ****101,n,System(curl --data "Message=${CALLERID(name)}: 
${CALLERID(num)}" http://frontend1:6544/Myth/SendMessage)
exten => ****101,n,System(curl --data "Message=${CALLERID(name)}: 
${CALLERID(num)}" http://frontend2:6544/Myth/SendMessage)

The you have to either create a ring group that includes ****101# as one of 
it's extensions or add a follow me to ****101# to the extension you want 
send CallerID notifications for and forward incoming calls to either that 
ring group or extension.







More information about the mythtv-users mailing list