6

I'm trying to create a phone system where a caller gets enqueued, and ideally, the system will then call out to an agent, who would then pickup and then modify the call to bridge the top of the queue.

What I've accomplished thus far is the dialing loop, where a user calls in, and it dials agents in sequence, until someone picks up, or gives the user the option to leave a message or stay on the line while hearing it ring. And a simple enqueue with hold music.

I just can't seem to figure out how to combine these two systems.

The closest I've found is this post, and it's helpful, but it glosses over how to call out once the caller is enqueued.

Unfortunately, the only Twilio documentation I've found thus far tells me how to dial into the queue, which isn't what I want out of this system. I want this system to place a caller in a queue with hold music, while the system then dials agent numbers until an agent picks up.

Any and all help is much appreciated.

Thanks.

Edit:

Solution

index.php

This is the general IVR tree that the caller initially hits.

<Say>This hits your general IVR tree</Say>
<Say>As the last action, since the caller hasn't pressed anything and should be enqueued, redirect the caller to EnqueueCaller.php</Say>
<Redirect>./EnqueueCaller.php</Redirect>

Since PHP is a preprocessor, there's no real way to sleep or timeout the dialing of the call. The redirect in the IVR tree is necessary so the Agents aren't being dialed when the user is still in the IVR tree.

EnqueueCaller.php

This is where the Caller gets redirected once the IVR tree has finished and the user has chosen to wait for an agent. The call actually happens before the Enqueue, since PHP loads first before the TwiML xml is read (I think?). But since there's an inherent delay when calling, the caller will always be enqueued before an agent can pick up (I hope).

<Enqueue waitUrl="wait_file.xml">name_of_queue</Enqueue>
$call = $client->account->calls->create($from, $to, "http://example.com/DialQueueHandler.php", array( "StatusCallback" => "DialQueueEventHandler.php" );

DialQueueHandler.php

This simply bridges the agent and whoevers at the top of the queue.

<Say>Connecting to caller now.</Say>
<Dial><Queue>name_of_queue</Queue></Dial>

DialQueueEventHandler.php

This script houses the logic for what happens when the dialed agent state changes (answered, complete, initiated, ringing) from $_REQUEST['CallStatus']. In my case, I dialed a single agent from the enqueue script, and in this script, either continue dialing the next agents via setting of a flag.

switch($_REQUEST['CallStatus'] {
    case 'answered':
    case 'completed':
        $next = false;
        break;
    default:
        $next = true;
        break;
}
if($next) { $call = $client->account->calls->create($from, $nextAgentNumber, "http://example.com/DialQueueHandler.php", array( "StatusCallback" => "DialQueueEventHandler.php?agentOffset=$num" ); } //same line from EnqueueCaller.php, and track where we are in agent array.

If the call is not answered or completed, then dial the next agent. Otherwise when the call is picked up by an agent, the DialQueueHandler.php file gets hit and the call becomes bridged.

Community
  • 1
  • 1
Jeff Kelly
  • 83
  • 1
  • 6
  • Hi, please don't put the solution in the question but rather create your own response. It will be more clear :) – TOPKAT Dec 08 '22 at 09:04

1 Answers1

0

Jeff, I'm Megan from Twilio.

You can utilize the workflowSid attribute of <Enqueue> to configure a Task which initiates the call flow to an available agent using TaskRouter. There is a TaskRouter quickstart in PHP and I think given where you've gotten so far, you could pick up on the third part.

Let me know if you find this to be helpful.

Megan Speir
  • 3,745
  • 1
  • 15
  • 25
  • 3
    Hi Megan! Thanks for the link, and response. After banging my head against the wall for most of my day, I figured out simply using the PHP API, and putting the account->calls->create _after_ the response->enqueue worked exactly like I needed it to. It connected calls perfectly fine. This works because the create call doesn't utilize twiml like the enqueue does, so the enqueue happens, and then any PHP after that happens as it normally would. I'll post a follow up when I finish and cleanup the app next week. Cheers and thanks again. – Jeff Kelly Nov 07 '15 at 01:24
  • Excellent, glad to hear it! Have a great weekend. – Megan Speir Nov 07 '15 at 04:16