Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duckfullstop/d1fdf24368f7861e7f4a79f72f62b251 to your computer and use it in GitHub Desktop.
Save duckfullstop/d1fdf24368f7861e7f4a79f72f62b251 to your computer and use it in GitHub Desktop.
FreePBX CallerID Superfecta - HTTP POST incoming caller

wat

This is a stupidly trivial additional module for FreePBX's CallerID Superfecta (CID Superfecta) that adds support for sending the caller ID name and number to an external host using a HTTP POST request.

This is absolutely perfect for trigging webhooks in things like Home Assistant, where a GET request may be undesirable.

howe

Make sure you have CID Superfecta installed (that's outside the scope of this readme, I'm sure you can figure it out)

Copy contents into /var/www/html/admin/modules/superfecta/sources/source-Send_to_URL_POST.module. The source should show up immediately in CID Superfecta.

Configure as any other source, making sure you enable it when ready. Probably best placed at the end of your processing chain.

home assistant

If you're using this with Home Assistant, create an automation triggered by a webhook.

Once you've done this, use the following URL in this module's config:

https://[home-assistant-url]/api/webhook/[webhook-id]

You can then access the data inside your actions using the {{trigger.data.name}} and {{trigger.data.number}} template variables.

license

MIT license.

<?php
/*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
* Developer Notes:
*
* Version History
* 2021-11-04 Initial commit
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***/
class Send_to_URL_POST extends superfecta_base {
public $description = "This source will send the CID number and the CID name to an URL for external processing with a POST request. The URL you enter will receive a HTTP POST request containing the JSON values 'name' and 'number'.";
public $version_requirement = "2.11";
public $source_param = array(
'URL_address' => array(
'description' => 'Specify a URL to send CID/CNAM data to using a HTTP POST request. Use the format \'http://url.org\'',
'type' => 'textarea',
'default' => "http://10.0.0.10/webhook"
)
);
function post_processing($cache_found, $winning_source, $first_caller_id, $run_param, $thenumber) {
if (($run_param['URL_address'] != '') && ($first_caller_id != '')) {
$url = $run_param['URL_address'];
$data['name'] = urlencode($first_caller_id);
$data['number'] = urlencode($thenumber);
$this->DebugPrint("Sending to URL: {$url}");
$value = $this->get_url_contents($url, $data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment