marcelog / PAMI

PHP Asterisk Manager Interface ( AMI ) supports synchronous command ( action )/ responses and asynchronous events using the pattern observer-listener. Supports commands with responses with multiple events. Very suitable for development of operator consoles and / or asterisk / channels / peers monitoring through SOA, etc

Home Page:http://marcelog.github.com/PAMI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No support for custom AMI actions?

InterLinked1 opened this issue · comments

There does not appear to be any support for custom AMI actions (custom AMI events work fine, obviously).

I looked through all of the files in Actions and did not find anything. The two things I tried:

  1. Using ActionMessage. I get an error that I cannot instantiate an abstract class, since all the other actions simply extend this.
  2. Using the UserEvent action and then doing setKey('Action', $myEventName) afterwards to override. This fails since setKey is a protected method.

In other words, it seems things are set up to prevent users from sending custom AMI actions.

This capability is important, since a) this library is unlikely to keep up with the new AMI actions being added to Asterisk and b) there will always be custom AMI actions that cannot be anticipated in advance.

Can there simply be an action, like "CustomAction" that is similar to UserEvent except it accepts the action name, rather than setting it to "UserEvent", and then an array of keys to set?

Something like this is what we need:

class CustomAction extends ActionMessage
{
    /**
     * Constructor.
     *
     * @param string $userEvent CustomAction
     * @param array $headers
     */
    public function __construct($userEvent, array $headers = [])
    {
        parent::__construct('CustomAction');
        $this->setKey('Action', $userEvent);
        foreach ($headers as $key => $value) {
            $this->setKey((string)$key, (string)$value);
        }
    }
}