如何使用 PHP 在 Twilio 中传递自定义参数?

从这里看一下:https ://www.twilio.com/docs/voice/client/twiml 我能得到的最接近的是:


$response = new Twiml();

$callerIdNumber = config('services.twilio')['number'];

$dial = $response->dial(['callerId' => $callerIdNumber]);

$dial->parameter([

     "name" => "firstname",

     "value" => "Test Firstname",

]);


$dial->parameter([

    "name" => "lastname",

    "value" => "Test lastname",

]);


$dial->client('support_agent');

return $response;

但它会引发无效的 XML 警告:


<?xml version="1.0" encoding="UTF-8"?>

<Response>

    <Dial callerId="+12055461045">

        <Parameter name="firstname" value="Test Firstname"/>

        <Parameter name="lastname" value="Test lastname"/>

        <Client>support_agent</Client>

    </Dial>

</Response>

在文档中,它应该看起来像这样:


<Response>

    <Dial>

        <Client>

            <Identity>joey</Identity>

            <Parameter name="firstname" value="Test Firstname"/>

            <Parameter name="lastname" value="Test lastname"/>

        </Client>

    </Dial>

</Response>

我已经尝试了很多东西,但它们都引发了应用程序错误。这是我尝试过的两个。我试过的其他东西我已经忘记了。


// trial 1

$dial->client->identity('support_agent')

$dial->client->parameter([

    "name" => "firstname",

    "value" => "Test Firstname",

]);


//trial 2

$dial->client->identity('support_agent', array('parameter' => [

    "name" => "firstname",

    "value" => "Test Firstname",

]))

任何帮助将非常感激!


慕田峪9158850
浏览 111回答 1
1回答

呼啦一阵风

您可以参考下面的 PHP 代码示例来添加自定义参数,我现在在本地系统上测试了此代码。&nbsp; &nbsp; &nbsp; &nbsp; require_once './vendor/autoload.php';&nbsp; &nbsp; &nbsp; &nbsp; use Twilio\TwiML\VoiceResponse;&nbsp; &nbsp; &nbsp; &nbsp; $response = new VoiceResponse();&nbsp; &nbsp; &nbsp; &nbsp; $dial = $response->dial('');&nbsp; &nbsp; &nbsp; &nbsp; $client = $dial->client();&nbsp; &nbsp; &nbsp; &nbsp; $identity = $client->Identity('user-jane');&nbsp; &nbsp; &nbsp; &nbsp; $client->parameter([&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"name" => "firstname",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"value" => "Test Firstname",&nbsp; &nbsp; &nbsp; &nbsp; ]);&nbsp; &nbsp; &nbsp; &nbsp; $client->parameter([&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "name" => "lastname",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "value" => "Test lastname",&nbsp; &nbsp; &nbsp; &nbsp; ]);&nbsp; &nbsp; &nbsp; &nbsp; echo $response;回复如下<Response><Dial>&nbsp; &nbsp; <Client>&nbsp; &nbsp; &nbsp; &nbsp; <Identity>user-jane</Identity>&nbsp; &nbsp; &nbsp; &nbsp; <Parameter name="firstname" value="Test Firstname" />&nbsp; &nbsp; &nbsp; &nbsp; <Parameter name="lastname" value="Test lastname" />&nbsp; &nbsp; </Client></Dial>
打开App,查看更多内容
随时随地看视频慕课网APP