0

Aim: Put incoming calls into conference.

What I would like to achieve is:

  1. generate call signal to all available agents
  2. put an incoming call into conference
  3. when agent picks up, its connected to the conference

On an incoming voice call I have this code:

      $response = new Twiml();
      $dial = $response->dial([
        'callerId' => $input['From'],
      ]);

      $dial->client('testagent',
      [
        'url' => "/twilio/conference/create"
      ]);

How do I expand this twiml with an instruction to put an incoming call to conference, right after calls to agents are created?

Currently agent successfully resides in conference, while incoming call is still ringing...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ulterior
  • 2,786
  • 3
  • 30
  • 58
  • Not specifically answering your question with code, but have you checked out TaskRouter (https://www.twilio.com/taskrouter). Its designed specifically to make this scenario easy. You define agents and their availability. Incoming calls automatically get placed into a queue, and when an agent becomes available they automatically get bridged with the next call in the queue, Plus way way more stuff. – Devin Rader Jan 31 '18 at 20:15
  • @DevinRader I will look it up, but I would really like to understand why putting a customer to conference cannot be done together with calls to agent... – Ulterior Jan 31 '18 at 20:18

2 Answers2

0

Twilio Developer Evangelist here.

Couple of bits to understand about how the TwiML you're generating above works:

  • The <Dial> verb tells Twilio hold on to the call it just answered while we place an outbound call (to one instance of Client in your case). If that outbound call is answered, we will directly bridge those two calls together (no conference in between).
  • The TwiML returned by the url parameter you've included in the <Client> noun will get executed only on outbound leg we dialed and before Twilio directly bridges the two calls together. There is a limited subset of TwiML that you can return from that URL and unfortunately <Dial> isn't on of them: https://www.twilio.com/docs/glossary/call-whisper

  • Its possible to use a technique called a simuldial to have Twilio dial out to multiple agents: https://www.twilio.com/docs/api/twiml/client#examples-2. In this scenario whichever agent answers the call first will get bridged to the original incoming call. There is no conference involved in that scenario. Its a direct bridge but the direct bridge makes it pretty hard to do things like put a call on hold, transfer it to another party or add a third person. If you don't care about any of those scenarios then that might be an option for you.

If you do care about any of the above, I highly recommend using TaskRouter.

Hope that helps.

Devin Rader
  • 10,260
  • 1
  • 20
  • 32
  • I have used instruction => 'conference' in the assignment callback to convert all calls to conference and used task router to do rest of the things but the call does not get routed to multiple worker. If I remove order_by from task router json, then it manages to do its work somehow but still there is problem when only 1 worker is available. Is there any better way of converting all incoming call to conference. – Nabin May 08 '18 at 22:01
0

I managed to do this with an additional Twilio REST call and a route for agents

Added 'action' which executes after agent picks up a call and updates its leg:

  $response = new Twiml();
  $dial = $response->dial([
    'callerId' => $input['From'],
    'action' => '/twilio/conference/join',
  ]);

  $dial->client('testagent',
  [
    'url' => "/twilio/conference/create"
  ]);

when agent route "/twilio/conference/create" is executed before sending dummy Twiml, I execute this Twilio Rest call:

  $call = $client->account->calls($input['CallSid'])->fetch();
  $call->update([
    "url" => "/twilio/conference/join"
  ]);

This puts agent leg into conference, disconnects the caller which executes 'action' route on behalf of customer

I would really like to know why this couldnt be done with Twiml response on agent route...

Ulterior
  • 2,786
  • 3
  • 30
  • 58