简体   繁体   English

如何使用PHP将参数传递到Twilio数字语音URL?

[英]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? 目前,我使用Twilio php帮助程序库使用Twilio及其REST API进行呼叫,我拨打一个具有语音URL设置的Twilio号码,在这种情况下,我需要从REST向该URL发送一些参数我暂时无法进行API调用,因为URL是在Twilio控制台上设置的,我需要根据该调用发送一些用户数据,但是在文档中我没有看到任何允许我执行的操作这没说什么,有可能实现吗?

Thank you beforehand 预先谢谢你

Twilio developer evangelist here. Twilio开发人员布道者在这里。

You can set parameters in the Voice URL in the Twilio dashboard using URL parameters. 您可以使用URL参数在Twilio仪表板的“语音URL”中设置参数。 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'] . 例如,如果将URL设置为http://example.com/voice?foo=bar,则应该可以使用$_REQUEST['foo']提取bar

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 . Twilio还通过来电向您的URL发送许多参数,包括拨打的号码(如果您有多个来电号码,则很有用),拨打的号码等等 You should be able to use the information in the request from Twilio to choose where to dial your call onto. 您应该能够使用来自Twilio的请求中的信息来选择拨打电话的位置。 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. 例如,如果您希望从特定号码拨打电话,并且知道要将该呼叫转接到其他号码,则可以基于“ From参数设置条件。

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. 使用REST API创建呼叫时,您可以指定一个被呼叫方应答呼叫后将请求的ULR,并且如上所示,您可以传递查询字符串参数。 In addition you can do the same to the StatusCallback URL. 另外,您可以对StatusCallback URL进行相同的操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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