when we make call using rest api then what twiml we use on that url parameter

…衆ロ難τιáo~ 提交于 2019-12-02 14:23:27

问题


I am Creating the call using the rest api-

try{
        // Initiate a new outbound call
        $call = $this->client->calls->create(

            // to call.
            "num2",

            // Step 5: Change the 'From' number below to be a valid Twilio number 
            // that you've purchased or verified with Twilio.
            "num1",


            array("url" => "url-tw",
            'IfMachine'=>'Continue')

        );
        echo "Started call: " . $call->sid;
    } catch(Exception $e){
        echo "Error: " . $e->getMessage();
    }

and on the url-tw what twiml should I use which can't disconnect the call.

Before I was handling the call using the TwiML but now I have to detect the AnsweredBy option which is only available if I make the call using the REST API so.

for now I m using the same twiml I have used before when I was making calls using the twiML like use the <Dial> which let to dial again but if I dont use any twiml it disconnect the call.So any advice where I m going wrong.


回答1:


Twilio evangelist here.

The value of the url parameter should be a publicly accessible URL that returns TwiML containing the instructions that you want Twilio to execute to the caller.

Your PHP to start the call would look like:

// Initiate a new outbound call
$call = $this->client->calls->create(
    "num2",
    "num1",
    array("url" => "http://example.com/answer.php", 'IfMachine'=>'Continue')
);

Then in answer.php, you can do two things:

  1. Check the AnsweredBy parameter to see if Twilio detected a machine or a human.
  2. Generate the Twiml you want to return based on that value

For example to say something different to a machine v a human, you could do something like this in your PHP:

<?php
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<?php if ($_REQUEST['AnsweredBy']=='machine'): ?>
    <Response>
        <Say>Hello machine</Say>
    </Response>
<?php else: ?>
    <Response>
        <Dial>+15555555555</Dial>
    </Response>
<?php endif ?>

Hope that helps.



来源:https://stackoverflow.com/questions/42417185/when-we-make-call-using-rest-api-then-what-twiml-we-use-on-that-url-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!