How Could you Trigger a Recorded Page to a Phone from an API Request to freePBX?

Here is the use case: a motion sensor is set off in my garage, my home automation system sends a https request to freePBX, freePBX then pages a recorded message to phones in a page group letting me know someone is in my garage.

Before I start digging too deep, I’m trying to figure if it’s possible. And if so, what will I need to get this to work. Does freePBX support triggering pages through it’s API? Do I need the commercial/paid paging module?

Sure. You basically need to originate a call to the page group and the destination will be the playback application with the file you want to play.

There’s two ways how you can do it.

  1. Asterisk ARI. You can create a channel directly from your automation system. [1]
  2. Build a small PHP “webhook” on your FreePBX which will either originate the call via AMI or by generating a call file. [2] [3]

With that being said, some home automation systems allow you to install NodeRED. NodeRED has AMI plugins which allows you to send AMI commands from the home automation system. There’s also an ARI plugin, but the last time I checked, it wasn’t very mature.

There’s another way you can originate a call and that is via the asterisk control, but I’m not sure how helpful that is for you… [4]

asterisk -x"channel originate local/<page exten>@from-internal application playback <playback file - usually it's like custom/my-page>"

[1] Asterisk 18 Channels REST API - Asterisk Project - Asterisk Project Wiki

[2] Asterisk 18 ManagerAction_Originate - Asterisk Project - Asterisk Project Wiki

[3] Asterisk Call Files - Asterisk Project - Asterisk Project Wiki

[4] Creating and Manipulating Channels from the CLI - Asterisk Project - Asterisk Project Wiki

Excellent! Not working yet, but I’m making good headway now.

This is a very basic example of how to do FreePBX stuff with PHP:

include '/etc/freepbx.conf';

if($astman->connected()) {
	//list endpoints
	//asterisk -rx "pjsip list endpoints"
	$endpoints=$astman->Command('pjsip list endpoints')['data'];
}else echo 'no asterisk manager connection';

Another example:

include '/etc/freepbx.conf';

if($astman->connected()) {
	$astman->Command('channel originate local/<internal extension>@from-internal extension <external number>@from-internal');
}else echo 'no asterisk manager connection';

If you put the files in /var/www/html you can execute them from the browser simply by entering https://[fqdn]/name_of_your_script.php. Might be best to put them in a directory of their own.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.