Twilio call transfer from in-call

前端 未结 2 1024
一生所求
一生所求 2021-01-06 07:36

I\'m not finding a definite answer from the Twilio docs on this. I\'m trying to build a phone system that can place the other party on hold while in-call and only from the p

相关标签:
2条回答
  • 2021-01-06 07:45

    Twilio evangelist here.

    This sounds like it might be a good place to use some <Conference>s.

    Lets define the actors in your scenario: Agent1, Agent2, Field.

    Lets say that Field calls Agent1. Instead of connecting the two directly with a <Dial> you could <Dial> Field into a <Conference> (lets call it ConferenceA), then use the REST API to initiate an outbound call to Agent1. When they answer <Dial> them into the same <Conference>. The system will need to grab the CallSid's of both Agent1 and Field, as well as the Sid of the <Conference>, persist them in some type of storage to use later.

    Using <Conference> in this scenario gives you more flexibility to manipulate each leg of the call independent of the other than you would have if you use <Dial> to connect Field and Agent1.

    So now Agent2 calls Field. Agent2 would go through the same process, just in reverse. Agent2 would get dialed into a <Conference> (lets call it ConferenceB) and your system would use the REST API to call Field. When Field answers they get <Dial>ed into the same conference as Agent2. Again, the system will need to grab the CallSid's of both Agent2 and Field, as well as the Sid of the <Conference>, persist them in some type of storage to use later.

    Now, Field needs a way to tell the system to connect Agent2 with Agent1. To do that you can utilize the <Dial>s hangupOnStar attribute in the TwiML you hand Twilio when you dial Field into the ConferenceB. The <Dial> verb would look something like:

    <Dial hangupOnStar="true" action="[process_hangup_url]">
        <Conference>ConferenceB</Conference>
    </Dial>
    

    hangupOnStar tells Twilio to disconnect the caller (Field) from whoever they <Dial>ed (the conference), but still makes a request to the URL defined in the <Dial> verbs action attribute. That is important because when Field needs to tell the system to redirect Agent2 into the ConferenceA with Agent1, and the request to the URL in s action attribute gives the system the opportunity to prompt Field to see if thats what he wants to do. So you might have Twilio execute some TwiML like this:

    <Response>
        <Gather action=[gather_handler]>
            <Say>Press 1 to connect this caller to another<Say>
        </Gather>
    </Response>
    

    If Field presses one, the system (who knows all of the CallSids for all of the parties involved here, and the conference sids), can use the REST API to redirect Agent2 out of the ConferenceB and into ConferenceA.

    It makes for a bit more complicated of a system, but it should work for you.

    Hope that helps

    0 讨论(0)
  • 2021-01-06 07:58
    Redirect an incoming call to new url:    
    
    <?php
     // Get the PHP helper library from twilio.com/docs/php/install
     require_once '/path/to/vendor/autoload.php'; // Loads the library
     use Twilio\Rest\Client;
     // Your Account Sid and Auth Token from twilio.com/user/account
     $sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
     $token = "your_auth_token";
     $client = new Client($sid, $token);
     // Get an object from its sid. If you do not have a sid,
     $call = $client
        ->calls("CAe1644a7eed5088b159577c5802d8be38")
        ->update(
            array(
                "url" => "your_url/test.xml",
                "method" => "POST"
            )
        );
    
     echo $call->to;
    
     XML Code: 
     ---------
     <Response>
        <Redirect method="POST">url goes here</Redirect>
     </Response>
    
    0 讨论(0)
提交回复
热议问题