Search code examples
asteriskfreepbx

how to write application to freepbx


I see a lot of modules in freepbx and try to understand how they work without success.

the point I can't understand how they hook a call and when call is made so they called and do they work

for example lets say I write module that print "CALL IS MADE" when call is made and I have install.php and uninstall.php and module.xml and function.inc.php and all the files that need to and I have the next code in Function.inc.php

function callmade(){agi->Verbose("Call is Made");}

now I know i can create dialplan manualy in extension_freepbx.conf (not in extension.conf) that call my php but how to make freepbx auto do it (like all modules)

I sorry for my english thks for helpers


Solution

  • References to install.php or functions.inc.php are outdated, this is not how modern FreePBX modules are built any longer. All work is done in a class in the FreePBX\modules namespace. So within your module directory you'll have this class file:

    Mymodule.class.php

    <?php
    namespace FreePBX\modules;
    
    class Mymodule extends \FreePBX\FreePBX_Helpers implements \FreePBX\BMO
    {
        public function install()
        {
            // here is the install stuff
        }
    
        public function uninstall()
        {
            // here is the uninstall stuff
        }
    
        public function myDialplanHooks()
        {
            // signal our intent to hook into the dialplan
            return true;        
        }
    
        public function doDialplanHook(&$ext, $engine, $pri)
        {
            // this is run when the PBX is reloaded
            $context = "from-internal";
            $extension = "s";
            $ext->splice($context, $exten, "n", new \ext_log(1, "Call is made"));    
        }
    }
    

    Now, I have no idea if this will work. I'm very familiar with FreePBX modules, but don't usually hook into the dialplan. But it will give you an idea where to start. Take a look at the modules provided by FreePBX, and dig around in the code. Keep in mind a lot of the modules are still using the legacy files mentioned above, but they are deprecated and will be removed in a future version.