2

Taking a look from here: https://www.twilio.com/docs/voice/client/twiml The closest I could get was this:

$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;

but it throws an invalid XML warning:

<?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>

In the docs, it's supposed to look like this:

<Response>
    <Dial>
        <Client>
            <Identity>joey</Identity>
            <Parameter name="firstname" value="Test Firstname"/>
            <Parameter name="lastname" value="Test lastname"/>
        </Client>
    </Dial>
</Response>

I've tried so many things but they all throw an application error. Here are two that I've tried. The other stuff I've tried I've already forgotten.

// 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",
]))

Any help would be much appreciated!

Thank you!

  • Hope this will help you :- https://stackoverflow.com/questions/30430270/is-there-a-way-to-pass-a-custom-parameter-when-make-a-call-with-twilio/35318869 – Alive to die - Anant Nov 29 '19 at 04:39
  • Hi @AnantSingh---AlivetoDie, thanks. I've passed that but it's a bit outdated since it's from 2015. The docs show that TwiML has a capability to pass custom parameters but doesn't state how in php. – JR Requiroso Nov 29 '19 at 04:54
  • @JRRequiroso I think you have to pass this parameter related code in the new created variable of client function related code. Let me check this thing at my end. – Bhavin Thummar Nov 29 '19 at 07:07

1 Answers1

2

You can refer to the below PHP code sample to add the custom parameter and this code is tested by me at on local system now.

        require_once './vendor/autoload.php';
        use Twilio\TwiML\VoiceResponse;

        $response = new VoiceResponse();
        $dial = $response->dial('');
        $client = $dial->client();
        $identity = $client->Identity('user-jane');

        $client->parameter([
             "name" => "firstname",
             "value" => "Test Firstname",
        ]);

        $client->parameter([
            "name" => "lastname",
            "value" => "Test lastname",
        ]);

        echo $response;

Response is below

<Response>
<Dial>
    <Client>
        <Identity>user-jane</Identity>
        <Parameter name="firstname" value="Test Firstname" />
        <Parameter name="lastname" value="Test lastname" />
    </Client>
</Dial>

Bhavin Thummar
  • 1,255
  • 1
  • 12
  • 29