简体   繁体   中英

How can I pass parameters to a Twilio number voice URL with PHP?

Currently, I making a call using Twilio with their REST API using the Twilio php helper library, I'm dialing the a Twilio number which have a Voice URL setup, in this case, I need to send some parameters to that URL from the REST API call which I can't for the moment, because the URL is set on the Twilio console and I need to sent some user data based on the call, but I haven't seen anything that allows me to do that, in the documentation it's not saying anything about that, it's possible to achieve that?

Thank you beforehand

Twilio developer evangelist here.

You can set parameters in the Voice URL in the Twilio dashboard using URL parameters. For example, if you set the URL to be http://example.com/voice?foo=bar then you should be able to extract bar with $_REQUEST['foo'] .

Twilio also sends a number of parameters to your URL with an incoming call, including the number that was dialled (useful if you have multiple incoming numbers), the number dialled from and many more . You should be able to use the information in the request from Twilio to choose where to dial your call onto. For example, if you are expecting a call from a particular number and you know you want to forward that call onto a different number, you can setup a conditional based on the From parameter.

Let me know if that helps at all.

You can pass parameters dynamically in your code like this:

<?php
$query_string = array(
    'param1' => $param1,
    'param2' => $param2
);
?>

    $call = $twilio_client->account->calls->create(
        '+1' . $outbound_caller_id,
        '+1' . $number_to_call,
        ' http://example.com/voice' . '?' . http_build_query($query_string, '', '&'),
        array(
            'StatusCallback' => ' http://example.com/statuscallbaclurl' . '?' . http_build_query($query_string, '', '&')
        )
    );

When using the REST API to create a call you can specify a ULR that will be requested once the call is answered by the dialed party, and as showed above you can pass query string parameters. In addition you can do the same to the StatusCallback URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM