4

I'm running into a double records issue when pulling a list of in-progress calls using the Twilio REST API. Here is how I want the workflow to go.

  1. Caller dials client's number. Check
  2. Caller hears welcome message and is placed into call queue. Check
  3. Operator sees caller in queue from dashboard. Issue
  4. Operator chooses to be connected to caller. Check
  5. Calls are bridged. Check

My problem is that when I make a query for all calls in progress, I am getting double records.

  • One record shows up as soon as the caller is placed in the queue, this record shows the caller's number in the from property, and the Twilio number in the to property.
  • The second record appears after choosing to connect the calls. It appears to be a duplicate of the first, but instead of showing the global Twilio number (the mother number) as the to property, it displays the agent's phone number.

Here is how I am pulling the list:

<?php foreach($client->account->calls->getIterator(0,50,array("Status" => "in-progress")) as $call): ?>
    <tr>
    <td><?=$call->start_time?></td>
    <td><?=$call->duration?></td>
    <td><?=$call->from?></td>
    <td><?=$call->to?></td>
    <td>
        <form action="actions/queue.php" method="post">
        <input type="hidden" name="caller" value="<?=$call->parent_call_sid?>" />
        <input type="submit" value="Return Call to Queue" style="color: #555;" />
        </form>
    </td>
    </tr>
<?php endforeach; ?><!-- foreach calls as call -->

A few extra things worth noting.

  • This has a little bit of styling so that I can see what I am doing, most of these interactions will eventually take place on an iPad or desktop software.
  • The second record mentioned above (the one that displays the agent's phone number) can move between the list of calls that show up as queued and the list of calls that show up as in-progress. It is only the first record (the one showing the Twilio phone number) that always appears an in-progress
  • Yes, I can filter the record out on my end by ignoring the records that show the Twilio number as the toproperty, but I would prefer to filter it on Twilio's end, if possible.
4

1 回答 1

3

Twilio Developer Evangelist here.

You can filter for only incoming or outgoing calls in your API request to Twilio. If you add a direction parameter to your getIterator call you should be able to get only the incoming call in your logs and not the outgoing call going to the agent:

foreach($client->account->calls->getIterator(0,50,array("Status" => "in-progress", "Direction" => "inbound")) as $call):

The reason you are getting multiple entries is because each person you call (aka the agent and the customer in this case) is counted as an individual leg of the call by Twilio.

于 2014-01-14T00:01:53.863 回答