通話のキューへの追加

概要

このガイドでは、Twilio のキュー機能を使用して、単純な通話キューイングシステムを作成する方法について説明します。着信通話は、順番にキューに入ります。その後は、キューの最初の通話を別の通話に簡単に接続できます。着信通話を受信し、キューに入れて、ライブエージェントをキューの最初の通話に接続する方法を示す詳細なサンプルコードを次に示します。

このデモでは、2 つの Twilio 電話番号を使用します。したがって、このコードを実際に試す場合は、2 つの電話番号を購入する必要があります。音声設定の詳細なヘルプについては、Getting Started ガイドをご覧ください。

発信者をキューに入れる

1 番目の番号が呼び出されると、Twilio は、キューに発信者を入れるように、サーバーにリクエストを送信します。

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.enqueue({
    waitUrl: 'wait-music.xml'
}, 'support');

console.log(response.toString());
using Twilio.TwiML;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Enqueue("support", waitUrl: new Uri("wait-music.xml"));

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$response->enqueue('support', ['waitUrl' => 'wait-music.xml']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.enqueue(name: 'support', wait_url: 'wait-music.xml')

puts response
from twilio.twiml.voice_response import Enqueue, VoiceResponse

response = VoiceResponse()
response.enqueue('support', wait_url='wait-music.xml')

print(response)
import com.twilio.twiml.voice.Enqueue;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Enqueue enqueue = new Enqueue.Builder().waitUrl("wait-music.xml")
            .name("support").build();
        VoiceResponse response = new VoiceResponse.Builder().enqueue(enqueue)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Enqueue waitUrl="wait-music.xml">support</Enqueue>
</Response>
単純なEnqueue

最初に、TwiML 応答を作成します。この応答は、Enqueue 動詞を使用して新しいキューを作成し、発信者をそこに入れます。

自分のアプリケーションから TwiML を提供する方法の詳細については、webhook ガイドをご覧ください。使用可能なすべての TwiML 機能については、TwiML ドキュメントをご覧ください。

エージェントをキューに接続する

2 番目の番号が呼び出されると、Twilio は、キューにエージェントを接続するように、サーバーにリクエストを送信します。

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.queue({
    url: 'about_to_connect.xml'
}, 'support');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        dial.Queue("support", url: new Uri("about_to_connect.xml"));

        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$dial = $response->dial();
$dial->queue('support', ['url' => 'about_to_connect.xml']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.queue('support', url: 'about_to_connect.xml')
end

puts response
from twilio.twiml.voice_response import Dial, Queue, VoiceResponse

response = VoiceResponse()
dial = Dial()
dial.queue('support', url='about_to_connect.xml')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.voice.Queue;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Queue queue = new Queue.Builder("support").url("about_to_connect.xml")
            .build();
        Dial dial = new Dial.Builder().queue(queue).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Queue url="about_to_connect.xml">support</Queue>
    </Dial>
</Response>
待ち行列にダイヤルする

名前を指定してキューダイヤルすると、キューの 1 番目の発信者に接続します。

次の発信者に自動的に接続する

エージェントまたは発信者が電話を切ると、デフォルトでは通話は終了しますが、引き続き次の発信者に自動的に接続したい場合がよくあります。

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 4.x
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • XML
  • TwiML
// Download the Node helper library from twilio.com/docs/node/install
var twilio = require('twilio');
var twiml = new twilio.TwimlResponse();

twiml.say('You will now be connected to the first caller in the queue.')
    .dial({}, function() {
        this.queue('Queue Demo');
    })
    .redirect();

console.log(twiml.toString());
// Download the Node helper library from twilio.com/docs/node/install
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const twiml = new VoiceResponse();

twiml.say('You will now be connected to the first caller in the queue.')
const dial = twiml.dial();
dial.queue('Queue Demo');
twiml.redirect();

console.log(twiml.toString());
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using Twilio.TwiML;
using Twilio.TwiML.Mvc;

private static TwiMLResult AutoConnect()
{
    var twiml = new TwilioResponse();
    twiml.Say("You will now be connected to the first caller in the queue.");
    twiml.BeginDial()
          .Queue("Queue Demo")
          .EndDial();
    twiml.Redirect();
    return new TwiMLResult(twiml);
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require("Services/Twilio.php");
$response = new Services_Twilio_Twiml;
$response->say("You will now be connected to the first caller in the queue.");
$dial = $response->dial();
$dial->queue("Queue Demo");
$response->redirect();
print $response;
require 'sinatra'
require 'twilio-ruby'

# Handles the POST request from Twilio and generates the TwiML that connects agent 
# with the first caller in the Queue
post '/agent/?' do
  response = Twilio::TwiML::Response.new do |r|
    r.Say "You will now be connected to the first caller in the queue."
    r.Dial do |d|
      d.Queue "Queue Demo"
    end
    r.Redirect
  end
  response.text
end
<?php
// NOTE: This example uses the next generation Twilio helper library - for more
// information on how to download and install this version, visit
// https://www.twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php';

use Twilio\Twiml;

$response = new Twiml();

$response->say("You will now be connected to the first caller in the queue.");
$dial = $response->dial();
$dial->queue("Queue Demo");
$response->redirect();

echo $response;
# Download the Python helper library from twilio.com/docs/python/install
from twilio import twiml

r = twiml.Response()
r.say("You will now be connected to the first caller in the queue.")
with r.dial() as d:
    d.queue("Queue Demo")
r.redirect()
print(str(r))
require 'sinatra'
require 'twilio-ruby'

# Handles the POST request from Twilio and generates the TwiML
# that connects agent with the first caller in the Queue
post '/agent/?' do
  response = Twilio::TwiML::Response.new do |r|
    r.Say 'You will now be connected to the first caller in the queue.'
    r.Dial do |d|
      d.Queue 'Queue Demo'
    end
    r.Redirect
  end
  response.text
end
// Install the Java helper library from twilio.com/docs/java/install
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.twilio.sdk.verbs.Dial;
import com.twilio.sdk.verbs.Queue;
import com.twilio.sdk.verbs.Redirect;
import com.twilio.sdk.verbs.Say;
import com.twilio.sdk.verbs.TwiMLException;
import com.twilio.sdk.verbs.TwiMLResponse;

public class Example extends HttpServlet {

  @Override
  public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    TwiMLResponse twiml = new TwiMLResponse();
    Say say = new Say("You will now be connected to the first caller in the queue.");
    Dial dial = new Dial();
    Queue queueInDial = new Queue("Queue Demo");
    Redirect redirect = new Redirect();

    try {
      twiml.append(say);
      twiml.append(dial);
      dial.append(queueInDial);
      twiml.append(redirect);
    } catch (final TwiMLException e) {
        e.printStackTrace();
    }

    return twiml.toXML();
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.twiml.voice_response import VoiceResponse, Dial

r = VoiceResponse()
r.say("You will now be connected to the first caller in the queue.")
d = Dial()
d.queue("Queue Demo")
r.append(d)
r.redirect('http://example.org')
print(str(r))
// Install the Java helper library from twilio.com/docs/java/install
import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.twilio.twiml.*;

public class Example extends HttpServlet {
  public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Say say =
        new Say.Builder("You will now be connected to the first caller in the queue.").build();

    Queue queueInDial = new Queue.Builder("Queue Demo").build();

    Dial dial = new Dial.Builder()
        .queue(queueInDial)
        .build();

    Redirect redirect = new Redirect.Builder().build();

    VoiceResponse twiml = new VoiceResponse.Builder()
        .say(say)
        .dial(dial)
        .redirect(redirect)
        .build();

    response.setContentType("application/xml");

    try {
      response.getWriter().print(twiml.toXml());
    } catch (TwiMLException e) {
      e.printStackTrace();
    }
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>You will now be connected to the first caller in the queue.</Say>
  <Dial>
    <Queue>Queue Demo</Queue>
  </Dial>
  <Redirect></Redirect>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>You will now be connected to the first caller in the queue.</Say>
  <Dial>
    <Queue>Queue Demo</Queue>
  </Dial>
  <Redirect></Redirect>
</Response>
次の発信者に自動的に接続する

空の <Redirect> 動詞は、発信者を TwiML の先頭にリダイレクトします。TwiML は、キューの次の人にダイヤルして接続します。最後の仕上げとして、<Say> 動詞を追加して、エージェントに別の発信者に接続されていることを通知します。

高度なワークフロー

Twilio のタスクルーターを使用して、次のような、非常に高度なコールセンターワークフローを実装できます。

  • キューの次の発信者に空いているエージェントを割り当てる
  • 料金別サポートプランを提供し、プレミアム利用者はキューをスキップできるようにする
  • ビジネスロジックに基づいて、特定の発信者を特定のチームにルーティングする

このガイドは、Twilio のキューを使い始めるために役立つように作成されていますが、さらにキューの機能について詳しく知りたいことがあれば、メールでご連絡ください。

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。

コードサンプルを読み込んでいます...
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.enqueue({
    waitUrl: 'wait-music.xml'
}, 'support');

console.log(response.toString());
using Twilio.TwiML;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Enqueue("support", waitUrl: new Uri("wait-music.xml"));

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$response->enqueue('support', ['waitUrl' => 'wait-music.xml']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.enqueue(name: 'support', wait_url: 'wait-music.xml')

puts response
from twilio.twiml.voice_response import Enqueue, VoiceResponse

response = VoiceResponse()
response.enqueue('support', wait_url='wait-music.xml')

print(response)
import com.twilio.twiml.voice.Enqueue;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Enqueue enqueue = new Enqueue.Builder().waitUrl("wait-music.xml")
            .name("support").build();
        VoiceResponse response = new VoiceResponse.Builder().enqueue(enqueue)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Enqueue waitUrl="wait-music.xml">support</Enqueue>
</Response>
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const dial = response.dial();
dial.queue({
    url: 'about_to_connect.xml'
}, 'support');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();
        dial.Queue("support", url: new Uri("about_to_connect.xml"));

        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$dial = $response->dial();
$dial->queue('support', ['url' => 'about_to_connect.xml']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
    dial.queue('support', url: 'about_to_connect.xml')
end

puts response
from twilio.twiml.voice_response import Dial, Queue, VoiceResponse

response = VoiceResponse()
dial = Dial()
dial.queue('support', url='about_to_connect.xml')
response.append(dial)

print(response)
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.voice.Queue;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Queue queue = new Queue.Builder("support").url("about_to_connect.xml")
            .build();
        Dial dial = new Dial.Builder().queue(queue).build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Queue url="about_to_connect.xml">support</Queue>
    </Dial>
</Response>
SDKバージョン:
  • 4.x
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • XML
  • TwiML
// Download the Node helper library from twilio.com/docs/node/install
var twilio = require('twilio');
var twiml = new twilio.TwimlResponse();

twiml.say('You will now be connected to the first caller in the queue.')
    .dial({}, function() {
        this.queue('Queue Demo');
    })
    .redirect();

console.log(twiml.toString());
// Download the Node helper library from twilio.com/docs/node/install
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const twiml = new VoiceResponse();

twiml.say('You will now be connected to the first caller in the queue.')
const dial = twiml.dial();
dial.queue('Queue Demo');
twiml.redirect();

console.log(twiml.toString());
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using Twilio.TwiML;
using Twilio.TwiML.Mvc;

private static TwiMLResult AutoConnect()
{
    var twiml = new TwilioResponse();
    twiml.Say("You will now be connected to the first caller in the queue.");
    twiml.BeginDial()
          .Queue("Queue Demo")
          .EndDial();
    twiml.Redirect();
    return new TwiMLResult(twiml);
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require("Services/Twilio.php");
$response = new Services_Twilio_Twiml;
$response->say("You will now be connected to the first caller in the queue.");
$dial = $response->dial();
$dial->queue("Queue Demo");
$response->redirect();
print $response;
require 'sinatra'
require 'twilio-ruby'

# Handles the POST request from Twilio and generates the TwiML that connects agent 
# with the first caller in the Queue
post '/agent/?' do
  response = Twilio::TwiML::Response.new do |r|
    r.Say "You will now be connected to the first caller in the queue."
    r.Dial do |d|
      d.Queue "Queue Demo"
    end
    r.Redirect
  end
  response.text
end
<?php
// NOTE: This example uses the next generation Twilio helper library - for more
// information on how to download and install this version, visit
// https://www.twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php';

use Twilio\Twiml;

$response = new Twiml();

$response->say("You will now be connected to the first caller in the queue.");
$dial = $response->dial();
$dial->queue("Queue Demo");
$response->redirect();

echo $response;
# Download the Python helper library from twilio.com/docs/python/install
from twilio import twiml

r = twiml.Response()
r.say("You will now be connected to the first caller in the queue.")
with r.dial() as d:
    d.queue("Queue Demo")
r.redirect()
print(str(r))
require 'sinatra'
require 'twilio-ruby'

# Handles the POST request from Twilio and generates the TwiML
# that connects agent with the first caller in the Queue
post '/agent/?' do
  response = Twilio::TwiML::Response.new do |r|
    r.Say 'You will now be connected to the first caller in the queue.'
    r.Dial do |d|
      d.Queue 'Queue Demo'
    end
    r.Redirect
  end
  response.text
end
// Install the Java helper library from twilio.com/docs/java/install
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.twilio.sdk.verbs.Dial;
import com.twilio.sdk.verbs.Queue;
import com.twilio.sdk.verbs.Redirect;
import com.twilio.sdk.verbs.Say;
import com.twilio.sdk.verbs.TwiMLException;
import com.twilio.sdk.verbs.TwiMLResponse;

public class Example extends HttpServlet {

  @Override
  public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    TwiMLResponse twiml = new TwiMLResponse();
    Say say = new Say("You will now be connected to the first caller in the queue.");
    Dial dial = new Dial();
    Queue queueInDial = new Queue("Queue Demo");
    Redirect redirect = new Redirect();

    try {
      twiml.append(say);
      twiml.append(dial);
      dial.append(queueInDial);
      twiml.append(redirect);
    } catch (final TwiMLException e) {
        e.printStackTrace();
    }

    return twiml.toXML();
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.twiml.voice_response import VoiceResponse, Dial

r = VoiceResponse()
r.say("You will now be connected to the first caller in the queue.")
d = Dial()
d.queue("Queue Demo")
r.append(d)
r.redirect('http://example.org')
print(str(r))
// Install the Java helper library from twilio.com/docs/java/install
import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.twilio.twiml.*;

public class Example extends HttpServlet {
  public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Say say =
        new Say.Builder("You will now be connected to the first caller in the queue.").build();

    Queue queueInDial = new Queue.Builder("Queue Demo").build();

    Dial dial = new Dial.Builder()
        .queue(queueInDial)
        .build();

    Redirect redirect = new Redirect.Builder().build();

    VoiceResponse twiml = new VoiceResponse.Builder()
        .say(say)
        .dial(dial)
        .redirect(redirect)
        .build();

    response.setContentType("application/xml");

    try {
      response.getWriter().print(twiml.toXml());
    } catch (TwiMLException e) {
      e.printStackTrace();
    }
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>You will now be connected to the first caller in the queue.</Say>
  <Dial>
    <Queue>Queue Demo</Queue>
  </Dial>
  <Redirect></Redirect>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>You will now be connected to the first caller in the queue.</Say>
  <Dial>
    <Queue>Queue Demo</Queue>
  </Dial>
  <Redirect></Redirect>
</Response>