ryzhov/asterisk-bundle

AsteriskBundle for symfony framework

Installs: 155

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 3

Open Issues: 0

Type:symfony-bundle

v1.0 2017-02-11 19:33 UTC

This package is not auto-updated.

Last update: 2024-04-13 23:56:58 UTC


README

The AsteriskBundle provides integration of the Asterisk PAMI library into the Symfony2 framework.

License

This bundle is released under the MIT license

Installation

Require the bundle and its dependencies with composer:

$ composer require ryzhov/asterisk-bundle

Register the bundle:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        new Ryzhov\Bundle\AsteriskBundle(),
    );
}

Usage

Add the asterisk section in your configuration file:

asterisk:
    connections:
        default:
            host: "%asterisk_host%"
            port: "%asterisk_ami_port%"
            username: "%asterisk_ami_username%"
            secret: "%asterisk_ami_secret%"
            connect_timeout: 5
            read_timeout: 5

    clients:
        main:
            connection: default
            logger_channel: ami

Here we configure the connection parameter and the AMI client that our application will have. In this example your service container will contain the service asterisk.main_client and asterisk.ami_connection.default connection parameters. AMI client service interface reference here Asterisk PAMI.

Register async event handler with tag asterisk.ami_event_handler will handle only specified events.

parameters:
    events: 
        - "PAMI\\Message\\Event\\DeviceStateChangeEvent"
        - "PAMI\\Message\\Event\\PeerStatusEvent"

services:
    service.event_handler:
        class: AppBundle\Service\EventHandler
        calls:
            - [setLogger, ["@logger"]]
        tags:
            - { name: monolog.logger, channel: event }
            - { name: asterisk.ami_event_handler, client: asterisk.main_client, events: "%events%" }

Event handler example:

namespace AppBundle\Service;

use PAMI\Listener\IEventListener;
use PAMI\Message\Event\EventMessage;

class EventHandler implements IEventListener
{
    . . .

    public function handle(EventMessage $event)
    {
        $this->logger->debug(sprintf('class: "%s" handle', get_class($event)));
    }
}

This is example of code ryzhov/example-asterisk-ami

$ composer create-project ryzhov/example-asterisk-ami
-- configure ami socket parameters here --
asterisk_host (localhost): 127.0.0.1
asterisk_ami_port (5038): 
asterisk_ami_username (ami):
asterisk_ami_secret (pass4ami):
--

$ cd example-asterisk-ami
$ php bin/console event-handler