1

I followed this page to update a call to a conference room. Everytime I try to call the update function, I get an error: No 'To' number is specified. Even if I go the standard Twiml where the call entered, it says that. Nowhere in the document is stated that you need a To number.

The code I used:

$call = $tokens['client']->account->calls->get($call_sid);
$call->update(array(
        "Url" => $app["request"]->getSchemeAndHttpHost() . "/dial/api/assign_redirect?callsid=" . $call_sid,
        "Method" => "POST"
    ));

The twiml where it is redirected to:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman">Thank you for your patience. You are now connecting with an agent</Say>
<Dial record="true">
    <Conference startConferenceOnEnter="false" endConferenceOnExit="true" eventCallbackUrl="{{ url('API-record') }}" record="record-from-start">{{ callsid }}</Conference>
</Dial>

The other Twiml where the call is accepted:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial record='record-from-answer' callerId='{{ callerId }}'>
        {{ numberOrClient|raw }}
    </Dial>
</Response>

Twilio support was no help, they pointed me at: https://www.twilio.com/docs/errors/21201 which makes no sense.

I tried a bunch of question on SO already like :

Only the last one worked for me. But that creates a third leg. I want to stick to the existing ones. Anyone has a clue how to fix this?

Thanks in advance!

Edit: I am using the v4 of the PHP library.

Community
  • 1
  • 1
Duncan
  • 351
  • 2
  • 10
  • Can I ask which version of the PHP library are you using? v4 or v5? Thanks! – philnash Sep 06 '16 at 13:42
  • Hey, I am using the v4 version. – Duncan Sep 06 '16 at 14:05
  • Is there anything else going on around that first block of code? An update sent to a call resource with a call SID should never need a `To` number, so I'm just wondering if there's more context to it? – philnash Sep 06 '16 at 14:11
  • Not much, I use the v1.3 JS library for the client. The client can choose to reject, accept or forward the call to a conference. The first two work, the third one gives me a hard time. I got a second workflow using the workspace of Twilio, using the v4 PHP library, where I use roughly the same code and there it works, only I get the call sid from an iterator instead of the js library. – Duncan Sep 06 '16 at 14:21
  • Sorry to keep asking questions. Are you passing the SID from the front end to this code? And is it definitely arriving correctly? Can you log the call sid and the call object before making the call to `update` – philnash Sep 06 '16 at 14:24
  • No problem, rather have questions to come to a positive ending then no answers at all :) . But yeah, I use Ngrok to make my local env talk to twilio, so I can see the request made in the ngrok inspector. I also return it and console.log it back in the front end. It is an ajax request and I get it in PHP like: `$call_sid= $request->request->get('call_sid');` I tried debugging it some more, using the second leg call_sid, but that redirects the client and hangs up the incoming call, but gives no error. – Duncan Sep 06 '16 at 14:27
  • At which point are you getting this error though? When Twilio connects to the TwiML? I thought it was when you made the REST API call to update the call. Sorry for the confusion! We'll get through this, I promise! – philnash Sep 06 '16 at 14:29
  • I get it on the update, I see no request being made to the TwiML. If I force the request through, it connects to the TwiML and I get `Error - 12100 Document parse failure`, because it passes the Twilio error in the request to the TwiML (I can see the error before the TwiML in the Twilio debugger). – Duncan Sep 06 '16 at 14:32
  • Can you log what you have in the `$call` variable between the call to `get` and `update`? – philnash Sep 06 '16 at 14:34
  • Thats 1 big object: http://pastebin.com/SbE2mDmz – Duncan Sep 06 '16 at 14:44
  • Yeah it is! And right down the bottom, line 2163-2164 you can see that you don't have the call SID (in the sid key or in the URL). You're not getting that call sid through from your Ajax request properly. That's where you should be looking. – philnash Sep 06 '16 at 14:47
  • Still strange. The error doesn't make still doesn't make sense and the return shows the same call_sid as in the ngrok post request, give me a sec to check – Duncan Sep 06 '16 at 14:53
  • I believe what has happened is that when calling `get` without a call sid you've ended up getting a reference to the list instance for calls. Then calling `update` on that makes a `POST` request and that thinks it's making a request to create a call and that is why you are getting the error that a `To` number is required. – philnash Sep 06 '16 at 14:55
  • Some of my debug code broke the call_sid indeed. After a revert and another test I get: http://pastebin.com/B8CJpA6Y – Duncan Sep 06 '16 at 14:58
  • Okay, I fixed it. After messing around with the `->account->calls->get`, I ended up with an iterator, just like the workspace one. `foreach ($tokens['client_token']->account->calls->getIterator(0, 50, array("CallSid" => $call_sid )) as $call)` and that works, I succesfully connected the client to a conference. Thanks for your help @philnash – Duncan Sep 06 '16 at 15:01

1 Answers1

1

I fixed it by getting both call_sids of the legs and creating an iterator like in the docs. If you forward the result the To error is gone, it is a bit more extensive and is way slower then the get, but it works.

Duncan
  • 351
  • 2
  • 10