简体   繁体   中英

Twilio add incoming call to queue and call to the agent

I have run in the situation where i'm handling incoming call using PHP/laravel, so when client calls to the company number the response is this method :

 public function respondToUser()
{
    $response = new Twiml();

    $audio_file_path = trans('ivr_file_paths.welcome');
    $response->play($audio_file_path);
    $response->redirect('/ivr/call/enqueue', ['method' => 'POST']);

    return $response;
}

But what I want to achieve next is to put incoming call in queue and then run the music in background if the operator (one operator /agent only) is busy, if not then connect to him.

this is what it looks like now

 public function enqueueCall(Request $request)
 {

  $please_wait_audio_file = trans('paths.please_wait');


  $please_wait_audio_file = trans('ivr_file_paths.please_wait');

  $response = new Twiml();

  $dial = $response->dial();

  $dial->number('+number');
  $response->enqueue('support', ['waitUrl' => $please_wait_audio_file]);

  Log::info($response);
  echo $response;
}

I know there is no queue right now, but this method just ends up the call..

Any suggestions? Thank you very much!

Twilio developer evangelist here.

I recommend you start by looking at the <Enqueue> TwiML verb which queues a caller up, followed by <Queue> which you can use within <Dial> to pop the next user off from the queue and talk to them.

If you need anything more complicated than that, then start reading into TaskRouter .

edit some example code:

Enqueue the caller and dial your agent.

public function enqueueCall(Request $request)
  {
  // build up the TwiML
  $please_wait_audio_file = trans('ivr_file_paths.please_wait');
  $response = new Twiml();
  $response->enqueue('support', ['waitUrl' => $please_wait_audio_file]);

  // make the call to your agent
  $client = new Client($yourTwilioAccountSid, $yourTwilioAuthToken);
  $call = $client->calls->create(
      $yourAgentNumber,
      $yourTwilioNumber,
      array("url" => "http://example.com/ivr/call/queue")
  );

  Log::info($response);
  echo $response;
}

When the agent connects, dial the queue:

public function dialQueue(Request $request)
  {
  $response = new Twiml();
  $dial = $response->dial();
  $dial->queue('support');

  echo $response;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM