找到你要的答案

Q:Asterisk Integration with Symfony2 application

Q:Asterisk集成Symfony2应用

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?!

我新星号,它已经安装了我所有主机的细节,我需要的是如何使用星号我Symfony2 Web应用;有人有一个想法或他曾在这之前呢?

编辑

以下是我在web应用程序中应该做什么:

  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.

编辑 1

我从我控制器中的小代码开始:

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();

但我不知道我可以在视图页或连接后做什么?

我如何用代码来执行命令?!

answer1: 回答1:

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());
    }
    

我有一个symfony的应用程序使用星号。我们是如何做到的:

  • 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.

对于你来说最大的问题是如何传递声音,一种方法是使用闪光灯。

电话号码验证-你会发现很多解决方案在谷歌上。

更详细的指令:

  • Create a bundle for Asterisk, there create your entities and Asterisk Service Class
  • 您将需要一个控制器-将处理您的请求和调用服务。例如你要挂断电话,你需要一个行动在你的控制器和服务你的行动。在控制器的初始化服务和你的电话服务,挂机挂断电话行动。

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

    /服务代码

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

Please have a look at AGI, AMI and ARI interface. They are language/platform agnostics way to communicate/integrate with asterisk from external application.

There are some great PHP libraries for asterisk exists as well.

PAGI, PAMI, PHPARI etc.

All of these libraries are available via composer. You can use it with Symfony2 just like other PHP packages.

请在AGI一看,AMI和ARI接口。他们的语言/平台不可知论者的沟通方式和外部应用星号整合。

有一些伟大的PHP库存在以及星号。

早晨,PAMI,phpari等

所有这些库都可以通过作曲家。你可以使用Symfony2就像其他PHP包。

answer3: 回答3:

You can try this bundle https://github.com/ryzhov/asterisk-bundle, but it connect through asterisk AMI interface (5038 tcp port) for request and event, not stasis.

code example here https://github.com/ryzhov/example-asterisk-ami

你可以试着用这束https://github.com/ryzhov/asterisk-bundle,但它通过Asterisk AMI接口(TCP端口5038)请求和事件,不是停滞。

在这里https://github.com/ryzhov/example-asterisk-ami代码示例

symfony2  asterisk  voip  telephony  asteriskami