Search code examples
symfonyasteriskvoiptelephonyasteriskami

Asterisk Integration with Symfony2 application


I'm new about Asterisk, it's already installed and I have all host details, what I need is how to use Asterisk in my symfony2 web application; Someone have an idea or he worked on this before?

EDIT

Here is the list what I should do in my web application:

  1. Create a stasis application
  2. Listen for a call.
  3. Play the “beep” sound which is already installed on the asterisk server.
  4. Allow the user to enter a US formatted phone number.
  5. Create a method to validate the phone number.
  6. Hangup.

EDIT 1

I start by that small code in my controller :

use Pastum\Component\PAMI\Client\Client;

/* These are (in order) the options we can pass to PAMI client:
 *
 * The hostname or ip address where Asterisk AMI is listening
 * The scheme can be tcp:// or tls://
 * The port where Asterisk AMI is listening
 * Username configured in manager.conf
 * Password configured for the above user
 * Connection timeout in milliseconds
 * Read timeout in milliseconds
 */
 $options = array(
'host' => '127.0.0.1',
'scheme' => 'tcp://',
'port' => 9999,
'username' => 'admin',
'secret' => 'mysecret',
'connect_timeout' => 10000,
'read_timeout' => 10000
);

$client = new Client($options);

// Open the connection
$client->open();

// Close the connection
$client->close();

But I do not know what I can do in the view page or after connection?

And how I can execute needs commands with code?!


Solution

  • I have used Asterisk in a Symfony Application. How We've done it:

    • custom class for connecting to AMI and executing needed commands, like originate a call, whisper, hangup or listen
    • add as second db your asterisk db if it is required, generate entities.

    The biggest problem for you will be how to transfer the sound, one way is to use flash.

    Phone number validation - you will find a lot of solutions on GOOGLE.

    More detailed instruction:

    • Create a bundle for Asterisk, there create your entities and Asterisk Service Class
    • You'll need a Controller - that will handle your requests and call the service. For example you have to hangup a call, you need an action in your controller and an action in your service. In controller you init the service and call hangup action from service that will hangup call.

      public function hangupAction(Request $request)
      {
          $asteriskService = // Get the asterisk service
          $asteriskService->hangup();
      
          return new JsonReponse();
      }
      

      // Code from the service

      public function hangup($agent)
      {
          fputs($this->getSocket(), "Action:Hangup\r\n");
          fputs($this->getSocket(),     "Channel:/^SIP/".$agent."-.*$/\r\n\r\n");
          fclose($this->getSocket());
      }