Register for SIGNAL by 8/31 for $250 off. Register now.

TwiML™ for Programmable Voice

TwiMLとは何か

TwiML (the Twilio Markup Language) is a set of instructions you can use to tell Twilio what to do when you receive an incoming call, SMS, or fax. 

How TwiML works

When someone makes a call to one of your Twilio numbers, Twilio looks up the URL associated with that phone number and sends it a request. Twilio then reads the TwiML instructions hosted at that URL to determine what to do, whether it's recording the call, playing a message for the caller, or prompting the caller to press digits on their keypad.

At its core, TwiML is an XML document with special tags defined by Twilio to help you build your Programmable Voice application.

Not making phone calls? TwiML powers more than just Twilio Programmable Voice – check out the documentation on how to use TwiML with Programmable SMS and Programmable Fax.

The following will say "Hello, world!" when someone dials a Twilio number configured with this TwiML:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>Hello, world!</Say>
</Response>

You can always return raw TwiML from your language of choice, or leverage the Twilio helper libraries to automatically create valid TwiML for you. In the code sample below, toggle to your preferred web programming language to see how the above TwiML looks using the helper library.

コードサンプルを読み込んでいます...
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.say('Hello World');

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Say("Hello World");

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

$response = new TwiML();
$response->say('Hello World');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.say(message: 'Hello World')

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

response = VoiceResponse()
response.say('Hello World')

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


public class Example {
    public static void main(String[] args) {
        Say say = new Say.Builder("Hello World").build();
        VoiceResponse response = new VoiceResponse.Builder().say(say).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Say>Hello World</Say>
</Response>
<Say> "Hello" to an inbound caller

Check out our short tutorial on responding to incoming phone calls, available in our six supported helper library languages. You can also leverage Twilio's TwiML bins, our serverless solution that lets you write TwiML that Twilio will host for you so you can quickly prototype a solution without spinning up a web server.

Outbound calls (calls from a Twilio number to an outside number) are controlled using TwiML in the same manner. When you initiate an outbound call with the Twilio API, Twilio then requests your TwiML to learn how to handle the call. 

Twilio executes just one TwiML document to the caller at a time, but many TwiML documents can be linked together to build complex interactive voice applications.

TwiML elements

In TwiML parlance, XML elements are divided into three groups: the root <Response> element, verbs, and nouns.

TwiML elements (verbs and nouns) have case-sensitive names. For example, using <say> instead of <Say> will result in an error. Attribute names are also case sensitive and camelCased.

You can use XML comments freely in your TwiML; the interpreter ignores them.

<Response>要素

In any TwiML response to a Twilio request, you must nest all verb elements within <Response>, the root element of Twilio's XML markup:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>
      This message must be nested in a Response element
      in order for Twilio to say it to your caller.
    </Say>
</Response>

Any other structure is considered invalid.

TwiML verbs for Programmable Voice

TwiML verbs tell Twilio what actions to take on a given call. Because of this, most elements in a TwiML document are TwiML verbs. Verb names are case sensitive, as are their attribute names. 

You can use different combinations of TwiML verbs to create all kinds of interactive voice applications. The core TwiML verbs for Programmable Voice are:

  • <Say> - Read text to the caller
  • <Play> - Play an audio file for the caller
  • <Dial> - Add another party to the call
  • <Record> - Record the caller's voice
  • <Gather> - Collect digits the caller types on their keypad

The following verbs may be used to control the flow of your call:

  • <Hangup> - Hang up the call
  • <Enqueue> - Add the caller to a queue of callers.
  • <Leave> - Remove a caller from a queue of callers.
  • <Redirect> - Redirect call flow to a different TwiML document.
  • <Pause> - Wait before executing more instructions
  • <Reject> - Decline an incoming call without being billed.

There are certain situations when the TwiML interpreter may not reach verbs in a TwiML document because control flow has passed to a different document. This usually happens when a verb's action attribute is set.

For example, if a <Say> verb is followed by a <Redirect> and then another <Say>, the 2nd <Say> is unreachable because <Redirect> transfers full control of a call to the TwiML at a different URL.

TwiML名詞

A TwiML noun describes the phone numbers and API resources you want to take action on. Effectively, a TwiML noun is anything nested inside a verb that is not itself a verb: it's whatever the verb is acting on.

TwiML nouns are usually just text. However, as in the case of <Dial> with its <Number> and <Conference> nouns, at times there are nested XML elements that are nouns.

開発者のアプリケーションへのTwilioからのリクエスト

When someone makes an inbound call to one of your Twilio phone numbers, Twilio needs to request TwiML from your application to get instructions for handling the call.

You can configure your Twilio phone number to point to your application's URL by visiting the phone numbers section of the console. Select your phone number, then scroll to the 'Voice & Fax' section to set a webhook, TwiML bin, or Twilio Function for Twilio to send that HTTP request when a call comes in:

音声通話用の電話番号でWebhookを構成する

Twilio makes its request over HTTP, either as a GET or POST, just like requesting a web page in your browser or submitting a form.

TwilioはPOSTリクエストをキャッシュできません。 Twilioに静的なTwiMLページをキャッシュさせたい場合は、GETを使用してTwilioからリクエストを送信させるようにしてください。

By including parameters and values in its request, Twilio sends data to your application that you can act upon before responding.

リクエストパラメーター

Twilio always sends the following parameters with its request.

These will send as either POST parameters or URL query parameters, depending on which HTTP method you've configured.

パラメーター 説明
CallSid Twilio が生成したこの通話のユニークな識別子です。
AccountSid あなたの Twilio アカウント ID。AC から始まる 34 文字の文字列です。
From

The phone number or client identifier of the party that initiated the call.

Phone numbers are formatted with a '+' and country code, e.g. +16175551212 (E.164 format). Client identifiers begin with the client: URI scheme; for example, on a call from a client named 'charlie' the From parameter will be client:charlie.

To

The phone number or client identifier of the called party.

Phone numbers are formatted with a '+' and country code, e.g. +16175551212(E.164 format). Client identifiers begin with the client: URI scheme; for example, for a call to a client named 'joey', the To parameter will be client:joey.

CallStatus

A descriptive status for the call.

The value is one of the following: queuedringingin-progresscompletedbusyfailed or no-answer. See the CallStatus section below for more details.

ApiVersion

この通話の際使用されたTwilioのAPIバージョン

For incoming calls, this is determined by the API version set on the called number. For outgoing calls, this is the version used by the REST API request from the outgoing call.

Direction

A string describing the direction of the call: 

inbound for inbound calls

outbound-api for calls initiated via the REST API

outbound-dial for calls initiated by a <Dial> verb.

ForwardedFrom

This parameter is set only when Twilio receives a forwarded call, but its value depends on the caller's carrier including information when forwarding.

Not all carriers support passing this information.

CallerName This parameter is set when the IncomingPhoneNumber that received the call has had its VoiceCallerIdLookup value set to true ($0.01 per lookup).
ParentCallSid

A unique identifier for the call that created this leg.

This parameter is not passed if this is the first leg of a call.

Twilio also attempts to look up geographic data based on the To and From phone numbers. If available, Twilio will send the following parameters with its request:

パラメーター 説明
FromCity The city of the caller
FromState The state or province of the caller
FromZip The postal code of the caller
FromCountry The country of the caller
ToCity The city of the called party
ToState The state or province of the called party
ToZip The postal code of the called party
ToCountry The country of the called party

通話中に起こったことに応じて、他の変数も送信されることがあります。

For example, when Twilio receives SIP, it will send additional parameters to your web application: you'll find the list of parameters sent with SIP in "SIP and TwiML interaction".

CallStatus 値

The following are the possible values for the CallStatus parameter. These values also apply to the DialCallStatus parameter, which is sent with HTTP requests to a <Dial> action URL.

Status 説明
queued 通話は発信待ち状態です。
ringing 呼び出し中です。
in-progress The call was answered and is actively in progress.
completed 相手が応答し、通話が正常に終了しました。
busy 相手からビジー信号を受信しました。
failed 通話を接続できませんでした。通常は、ダイヤルした電話番号が存在しません。
no-answer 相手が応答せず、通話が終了しました。
canceled 通話がqueued(発信待機中)またはringing(呼び出し中)の間に、REST APIによってキャンセルされました。

Ending the call: callback requests

After receiving a call, requesting TwiML from your app, processing it, and finally ending the call, Twilio will make an asynchronous HTTP request to the StatusCallback URL configured for the Twilio number that was called.

You need to explicitly provide this URL to your application in the StatusCallback parameter of each message for which you want the status callbacks. The raw TwiML for this looks like:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>
        <Number
         statusCallbackEvent="initiated ringing answered completed"
         statusCallback="https://myapp.com/calls/events"
         statusCallbackMethod="POST">
            +12316851234
        </Number>
    </Dial>
</Response>

The code sample below shows how to set your StatusCallback URL with plain TwiML or using the helper library of your choice:

コードサンプルを読み込んでいます...
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.number(
  {
    statusCallbackEvent: 'initiated ringing answered completed',
    statusCallback: 'https://myapp.com/calls/events',
    statusCallbackMethod: 'POST',
  },
  '+14158675310'
);

console.log(response.toString());
using System;
using Twilio.Http;
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System.Collections.Generic;
using Twilio.Types;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();

        dial.Number("+14158675310",
            statusCallbackEvent: new List<Number.EventEnum> (
                new Number.EventEnum [] {
                      Number.EventEnum.Initiated,
                      Number.EventEnum.Ringing,
                      Number.EventEnum.Answered,
                      Number.EventEnum.Completed
                  }),
            statusCallback: new Uri("https://myapp.com/calls/events"),
            statusCallbackMethod: HttpMethod.Post
        );

        response.Append(dial);

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

$response = new TwiML();
$dial = $response->dial();
$dial->number('+14158675310',
    ['statusCallbackEvent' => 'initiated ringing answered completed',
    'statusCallback' => 'https://myapp.com/calls/events',
    'statusCallbackMethod' => 'POST']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.number('+14158675310',
              status_callback_event: 'initiated ringing answered completed',
              status_callback: 'https://myapp.com/calls/events',
              status_callback_method: 'POST')
end

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

response = VoiceResponse()
dial = Dial()
dial.number(
    '+14158675310',
    status_callback_event='initiated ringing answered completed',
    status_callback='https://myapp.com/calls/events',
    status_callback_method='POST'
)
response.append(dial)

print(response)
import com.twilio.http.HttpMethod;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.voice.Number;
import com.twilio.twiml.voice.Number.Event;
import com.twilio.twiml.VoiceResponse;
import java.util.Arrays;

public class Example {
    public static void main(String[] args) {
        Number number = new Number.Builder("+14158675310")
            .statusCallback("https://myapp.com/calls/events")
            .statusCallbackMethod(HttpMethod.POST).statusCallbackEvents(Arrays
            .asList(Event.INITIATED, Event.RINGING, Event.ANSWERED, Event
            .COMPLETED)).build();
        Dial dial = new Dial.Builder().number(number).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>
        <Number
         statusCallbackEvent="initiated ringing answered completed"
         statusCallback="https://myapp.com/calls/events"
         statusCallbackMethod="POST">
            +14158675310
        </Number>
    </Dial>
</Response>
Set a StatusCallback

By providing a StatusCallback URL for your Twilio number and capturing this request, you can determine when a call ends and receive information about the call. Please note that non-relative URLs must contain a valid hostname, and underscores are not permitted.

StatusCallback request parameters

When Twilio sends parameters to your application in an asynchronous request to the StatusCallback URL, they include the same parameters passed in a synchronous TwiML request.

この他にも、StatusCallback リクエストは次のパラメーターを渡します。

パラメーター 説明
CallDuration 通話の秒数
RecordingUrl 音声通話の録音済みオーディオのURLです。 このパラメーターはREST APIリクエストにRecorded=trueが設定されている場合にのみ追加され、 <Dial> または <Record> での録音には含まれません。
RecordingSid この通話に関連づけられた録音の一意なIDです。
RecordingDuration 録音された音声ファイルの長さ (秒) です。

データフォーマット

電話番号

All phone numbers in requests from Twilio are in E.164 format if possible. For example, (231) 685-1234 would come through as '+12316851234'. However, there are occasionally cases where Twilio cannot normalize an incoming caller ID to E.164. In these situations, Twilio will report the raw caller ID string.

日付と時間

Twilioからのリクエスト内のすべての日付と時刻にはRFC 2822形式のGMTが使用されます。 たとえば、日本時間で2010年8月20日の午前10時13分は、「Fri, 20 Aug 2010 01:13:42 +0000」として表されます。

Twilioはお行儀のよいHTTPクライアントです

URL へ HTTP リクエストを送信する際、Twilio は通常のウェブ ブラウザと同じように振る舞います。

  • Cookie: 通常のWebブラウザーと同様、TwilioはHTTP Cookieを受け入れ、これらを (Twilioからの) 各リクエストに追加します。
  • リダイレクト: こちらも通常のWebブラウザーと同様、HTTPリダイレクト (HTTPステータスコード301、307、など) に従います。
  • キャッシュ: こちらも通常のWebブラウザーと同様、HTTPヘッダーで許可されており (ETagおよびLast-Modifiedヘッダー) 、かつHTTPメソッドがGETである場合、Twilioはファイルのキャッシュを行います。

MIME Type に対応

Twilio はユーザー アプリケーションのレスポンスの MIME Type に応じて異なる動作をします。

MIME Type 動作
text/xml, application/xml, text/html Twilioは返されたドキュメントをXMLの命令セットとして解釈します (これをTwiMLと呼んでいます) 。これは最もよく使われるレスポンスです。
various audio types Twilio plays the audio file to the caller, and then hangs up. See the <Play> documentation for supported MIME types.
text/plain  Twilio は発信者に向けてテキストの内容を読み上げ、通話を終了します。

Twilioにレスポンスを返す

In your response to Twilio's request to your configured URL, you can tell Twilio what to do on a call.

How the TwiML interpreter works

When your application responds to a Twilio request with XML, Twilio runs your document through the TwiML interpreter. To keep things simple, the TwiML interpreter only understands the few specially-named XML elements that make up TwiML: <Response>, verbs, and nouns.

The interpreter starts at the top of your TwiML document and executes instructions (verbs) in order from top to bottom.

The following code snippet reads "Hello World" to the caller before playing Cowbell.mp3 for the caller and then hanging up.

<?xml version="1.0" encoding="UTF-8"?>
<Response> 
    <Say>Hello, World!</Say>
    <Play>https://api.twilio.com/Cowbell.mp3</Play>
</Response>

Just as with all TwiML, you can use the helper libraries to help you play some music to a caller. Include the loop attribute to tell Twilio to loop this recording 10 times (or until the caller hangs up):

コードサンプルを読み込んでいます...
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.play({
    loop: 10
}, 'https://api.twilio.com/cowbell.mp3');

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Play(new Uri("https://api.twilio.com/cowbell.mp3"), loop: 10);

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

$response = new TwiML();
$response->play('https://api.twilio.com/cowbell.mp3', ['loop' => 10]);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.play(loop: 10, url: 'https://api.twilio.com/cowbell.mp3')

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

response = VoiceResponse()
response.play('https://api.twilio.com/cowbell.mp3', loop=10)

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


public class Example {
    public static void main(String[] args) {
        Play play = new Play.Builder("https://api.twilio.com/cowbell.mp3")
            .loop(10).build();
        VoiceResponse response = new VoiceResponse.Builder().play(play).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Play loop="10">https://api.twilio.com/cowbell.mp3</Play>
</Response>
Play and loop some music for your callers

Status callbacks in your response

ステータスコールバックは通話フローを制御しないため、TwiMLを返す必要はありません。 レスポンスを行う場合は、204 No Contentのステータスコードか、Content-Type: text/xmlと空の<Response/>をBodyに指定した200 OKを使用してください。 正しくレスポンスを返さないと、デバッガーで警告が発生します。

関連トピック

Go in-depth to learn more about the various TwiML verbs you'll use with Twilio's Programmable Voice, such as <Dial> to connect a call or <Gather> for speech recognition and collecting user key presses. You'll find all in-depth reference documents linked above.

You may also wish to explore how to generate TwiML with Twilio's helper libraries, provided to let you generate TwiML in your favorite language.

For a guided walkthrough, check out our quickstarts that will show you how to make and receive phone calls with Twilio in C#/.NET, Java, Node.js, PHP, Python, or Ruby.

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、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.say('Hello World');

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Say("Hello World");

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

$response = new TwiML();
$response->say('Hello World');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.say(message: 'Hello World')

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

response = VoiceResponse()
response.say('Hello World')

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


public class Example {
    public static void main(String[] args) {
        Say say = new Say.Builder("Hello World").build();
        VoiceResponse response = new VoiceResponse.Builder().say(say).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Say>Hello World</Say>
</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.number(
  {
    statusCallbackEvent: 'initiated ringing answered completed',
    statusCallback: 'https://myapp.com/calls/events',
    statusCallbackMethod: 'POST',
  },
  '+14158675310'
);

console.log(response.toString());
using System;
using Twilio.Http;
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System.Collections.Generic;
using Twilio.Types;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var dial = new Dial();

        dial.Number("+14158675310",
            statusCallbackEvent: new List<Number.EventEnum> (
                new Number.EventEnum [] {
                      Number.EventEnum.Initiated,
                      Number.EventEnum.Ringing,
                      Number.EventEnum.Answered,
                      Number.EventEnum.Completed
                  }),
            statusCallback: new Uri("https://myapp.com/calls/events"),
            statusCallbackMethod: HttpMethod.Post
        );

        response.Append(dial);

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

$response = new TwiML();
$dial = $response->dial();
$dial->number('+14158675310',
    ['statusCallbackEvent' => 'initiated ringing answered completed',
    'statusCallback' => 'https://myapp.com/calls/events',
    'statusCallbackMethod' => 'POST']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
  dial.number('+14158675310',
              status_callback_event: 'initiated ringing answered completed',
              status_callback: 'https://myapp.com/calls/events',
              status_callback_method: 'POST')
end

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

response = VoiceResponse()
dial = Dial()
dial.number(
    '+14158675310',
    status_callback_event='initiated ringing answered completed',
    status_callback='https://myapp.com/calls/events',
    status_callback_method='POST'
)
response.append(dial)

print(response)
import com.twilio.http.HttpMethod;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.voice.Number;
import com.twilio.twiml.voice.Number.Event;
import com.twilio.twiml.VoiceResponse;
import java.util.Arrays;

public class Example {
    public static void main(String[] args) {
        Number number = new Number.Builder("+14158675310")
            .statusCallback("https://myapp.com/calls/events")
            .statusCallbackMethod(HttpMethod.POST).statusCallbackEvents(Arrays
            .asList(Event.INITIATED, Event.RINGING, Event.ANSWERED, Event
            .COMPLETED)).build();
        Dial dial = new Dial.Builder().number(number).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>
        <Number
         statusCallbackEvent="initiated ringing answered completed"
         statusCallback="https://myapp.com/calls/events"
         statusCallbackMethod="POST">
            +14158675310
        </Number>
    </Dial>
</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();
response.play({
    loop: 10
}, 'https://api.twilio.com/cowbell.mp3');

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


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Play(new Uri("https://api.twilio.com/cowbell.mp3"), loop: 10);

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

$response = new TwiML();
$response->play('https://api.twilio.com/cowbell.mp3', ['loop' => 10]);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.play(loop: 10, url: 'https://api.twilio.com/cowbell.mp3')

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

response = VoiceResponse()
response.play('https://api.twilio.com/cowbell.mp3', loop=10)

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


public class Example {
    public static void main(String[] args) {
        Play play = new Play.Builder("https://api.twilio.com/cowbell.mp3")
            .loop(10).build();
        VoiceResponse response = new VoiceResponse.Builder().play(play).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Play loop="10">https://api.twilio.com/cowbell.mp3</Play>
</Response>