Create Conference AMI - PHP - Web App

Hi

My first post here , very new to Asterisk but not coding so just need some pointers

i have lots of questions but will try and limit them as much as i can.

What i need to do is this:

  1. Caller A calls the call centre

  2. Agent B picks up the call , puts Caller A on hold

  3. Agent B calls - Person C - asks if he is available to take this call (there is authorisation via a web interface Agent B has to do )

  4. Agent B , links up Caller A and Person C onto a call .

  5. If Agent B hangs up the call between A and C continues.

  6. If possible others can join the call between A and C

So in my mind the best way to do this is via a Conference Call and put both A and C into it and then others can join it too.

Key point is ideally Caller A shouldn’t have to do anything they transfer to Conference Call should be seamless (if possible)

There could be a number of calls like this going on at one time.

I have tried to create a conference room using AMI and PHP (just basic PHP ) but to no avail using the “Application: ConfBridge”

Any idea would be great , remember i am new to Asterisk and i dont mind reading around but pointers would be good

Yes you have the right Idea, you can use php and AMI to do that. What’s the issue with confbridge that you have?

This is my code below … it rings the number when i answer (via softphone X-Lite ) the call just hangs up , id have thought it would put me into conference room . Even if i change the application name to something else it does the same. So i don’t think i am doing things right at all. I was using the below as a basis for my code

As you can see i am just at the testing stage yet

 <?php
    // Replace with your port if not using the default.
    // If unsure check /etc/asterisk/manager.conf under [general];
    $port = 5038;
    // Replace with your username. You can find it in /etc/asterisk/manager.conf.
    // If unsure look for a user with "originate" permissions, or create one as
    // shown at http://www.voip-info.org/wiki/view/Asterisk+config+manager.conf.
    $username = "cxpanel";
    // Replace with your password (refered to as "secret" in /etc/asterisk/manager.conf)
    $password = "cxmanager*con";
    // Internal phone line to call from
    $internalPhoneline = "126";
    // Context for outbound calls. See /etc/asterisk/extensions.conf if unsure.
    $context = "from-internal";
    $target = "700";
    $socket = stream_socket_client("tcp://192.168.0.16:$port");
    if($socket)
    {
        echo "Connected to socket, sending authentication request.\n";
        // Prepare authentication request
        $authenticationRequest = "Action: Login\r\n";
        $authenticationRequest .= "Username: $username\r\n";
        $authenticationRequest .= "Secret: $password\r\n";
        $authenticationRequest .= "Events: off\r\n\r\n";
        // Send authentication request
        $authenticate = stream_socket_sendto($socket, $authenticationRequest);
        if($authenticate > 0)
        {
            // Wait for server response
            usleep(200000);
            // Read server response
            $authenticateResponse = fread($socket, 4096);
            // Check if authentication was successful
            if(strpos($authenticateResponse, 'Success') !== false)
            {
                echo "Authenticated to Asterisk Manager Inteface. Initiating call.\n";
                // Prepare originate request
                $originateRequest = "Action: Originate\r\n";
                $originateRequest .= "Channel: PJSIP/$internalPhoneline\r\n";
                $originateRequest .= "Application: ConfBridge\r\n";
                $originateRequest .= "Callerid: Click 2 Call\r\n";
                $originateRequest .= "ChannelId: 12333\r\n\r\n";
               // $originateRequest .= "Exten: $target\r\n";
              // $originateRequest .= "Context: $context\r\n";
               // $originateRequest .= "Priority: 1\r\n";
               // $originateRequest .= "Async: yes\r\n\r\n";
                
                // Send originate request
                $originate = stream_socket_sendto($socket, $originateRequest);
                if($originate > 0)
                {
                    // Wait for server response
                    usleep(200000);
                    // Read server response
                    $originateResponse = fread($socket, 4096);
                    // Check if originate was successful
                    if(strpos($originateResponse, 'Success') !== false)
                    {
                        echo "Call initiated, dialing.";
                    } else {
                        echo "Could not initiate call.\n";
                    }
                } else {
                    echo "Could not write call initiation request to socket.\n";
                }
            } else {
                echo "Could not authenticate to Asterisk Manager Interface.\n";
            }
        } else {
            echo "Could not write authentication request to socket.\n";
        }
    } else {
        echo "Unable to connect to socket.";
    }

And what’s the output of the asterisk CLI when you execute that code? Also take a look into phpagi library that will help you a lot.

Thanks for the pointer i totally forgot to look at the CLI output here is what i get

WARNING[3380]: app_confbridge.c:2192 confbridge_exec: ConfBridge requires an argument (conference name[,options])

Trying to work out which parameter to send through to avoid this error , i have tried “Conference: NewConf” to no avail

Will keep googling but any help much appreciated

In addition i am using AsteriskNow and FreePbx as my setup if that helps

     $originateRequest .= "ActionID: newone\r\n";
     $originateRequest .= "Data: Conf1234\r\n";

Added the two things above and it worked…

Thanks for the help i think this place is going to become my fav website :slight_smile:

You can use the asterisk cli to get the sintax of each command, in this case you can use core show application confbridge to see all the options and parameters that you can pass to it.

Thanks for the help

I am now using the PAMI library for php and i have two parties in the conference but not sure how to add Caller A to the conference … it rings the two numbers who can join the same conference .

If i have Caller A on hold how do i automatically add him to the same conference , i have tried the bridge command but not sure … This is just test code… the output from the CLI is

[2017-05-30 15:50:46] WARNING[26025][C-00000037]: chan_sip.c:22814 func_header_read: This function can only be used on SIP channels.

$call = new OriginateAction('PJSIP/786');
$call->setApplication('ConfBridge');
$call->setActionID('newaction');
$call->setData('MYAPP.php');

// $call->setContext(‘from-internal’);
// $call->setPriority(1);
// $call->setExtension(‘786’);
$call->setAsync(true);
$call->setCallerId(‘waseem’);

$call2 = new OriginateAction('PJSIP/126');
$call2->setApplication('ConfBridge');
$call2->setActionID('newaction2');
$call2->setData('MYAPP.php');
// $call->setContext('from-internal');
// $call->setPriority(1);
//  $call->setExtension('786');
$call2->setAsync(true);
$call2->setCallerId('waseem2');

$c = $call2->getKey('channel');

$response = $a->send($call);

$response = $a->send($call2);

$b = new BridgeAction(‘PJSIP/786’,‘PJSIP/126’,false);

[quote=“neowaseem, post:1, topic:70873”]
Caller A calls the call centre
Agent B picks up the call , puts Caller A on hold
[/quote] Maybe its better to transfer Caller A to the bridge in the step above, Caller A will listen MOH until anyone join the call.

[quote=“neowaseem, post:1, topic:70873”]
Agent B calls - Person C - asks if he is available to take this call (there is authorisation via a web interface Agent B has to do )
Agent B , links up Caller A and Person C onto a call .
[/quote]Here if Person C accept the call, then Agent B make another transfer to the bridge previously created, if not hangup, and Agent B join the bridge to tell Caller A.

[quote=“neowaseem, post:1, topic:70873”]
If Agent B hangs up the call between A and C continues.
If possible others can join the call between A and C
[/quote]Since the begginig everyone is in the bridge so anyone can join and left the call.

If you are doing all of this with AMI:
– create the bridge dynamically
– Insert AgentB on it by default
– when Caller A make into the CC join the bridge.
– Agent B do his stuff and call C
– If C accept the call use AMI REDIRECT to put C&B sip channels into the bridge.
– Hangup the call of Agent B.

All of this can be handle by simple dialplan, not sure why you need to use AMI but thats an idea on how to redirect calls and bridge channels

Thanks i will look at dialplams too , the reason i need AMI (i think) is all of this needs to be handled eventually via web app