TwiML™ Voice: <Number>
<Number>
is a noun for the TwiML verb <Dial>
and it specifies a phone number to dial. Using the noun's attributes you can specify particular behaviors that Twilio should apply when dialing the number.
<Dial>
動詞で最大 10 件の <Number>
名詞を使用して、全宛先に同時に電話をかけることができます。最初に応答があった電話が現在の通話に接続され、残りの電話は切断されます。各 <Number>
名詞について、webhook を受け取るコールプログレスイベントの種類を指定できます。
名詞の属性
この名詞<Number>
は振る舞いを変更する属性をサポートします。
属性名 | 許容値 | 初期値 |
---|---|---|
sendDigits | Any digits | なし |
url | 相対または絶対 URL | なし |
method | GET , POST |
POST |
byoc | BYOC Trunk SID | なし |
statusCallbackEvent | initiated , ringing , answered , completed |
completed |
statusCallback | Any URL | なし |
statusCallbackMethod | GET , POST |
POST |
Phone numbers should be formatted with a +
and country code, for example: +16175551212
(E.164 format). Twilio will also accept unformatted US numbers, e.g., (415) 555-1212 or 415-555-1212.
sendDigits
The sendDigits
attribute tells Twilio to play DTMF tones when the call is answered. This is useful when dialing a phone number and an extension. Twilio will dial the number, and when the automated system picks up, send the DTMF tones to connect to the extension.
url
The url
attribute allows you to specify a URL that will return a TwiML response to be run on the called party’s end, after they answer, but before the parties are connected.
You can use this TwiML to privately <Play>
or <Say>
information to the called party. You could also provide a chance to decline the phone call using <Gather>
and <Hangup>
. The url
attribute does not support any other TwiML verbs.
If the answerOnBridge attribute is used on <Dial>
, the current caller will continue to hear ringing while the TwiML document executes on the other end. TwiML documents executed in this manner are not allowed to contain the <Dial>
verb.
method
method
属性では、Twilioがurl
属性で与えられたURLにアクセスする際に、どのHTTPメソッドを用いるかを指定します。デフォルトは POST
です。
byoc
The byoc
attribute allows you to specify which configured customer BYOC Trunk Twilio should use to route the call to the PSTN. The default is none, in which case the call will be routed via the Twilio Super Network.
statusCallbackEvent
When dialing out to a number using <Dial>
, an outbound call is initiated. The call transitions from the initiated
state to the ringing
state when the phone starts ringing. It transitions to the answered
state when the call is picked up, and finally to the completed
state when the call is over.
With statusCallbackEvent
, you can subscribe to receive webhooks for the different call progress events for a given call: initiated
, ringing
, answered
, or completed
. Non-relative URLs must contain a valid hostname (underscores are not permitted).
The statusCallbackEvent
attribute allows you to specify which events Twilio should trigger a webhook on. To specify multiple events separate them with a space: initiated ringing answered completed
. If a statusCallback
is provided and no status callback events are specified, the completed
event will be sent by default.
一報APIを通じてアウトバウンドコールが生成されるとき、<Dial>
を使ってアウトバウンドコールはすぐさま開始され、キュー(queue)に入ることがありません。下記の返却されうるコールイベントのタイムラインです。異なるコールステータスが<Dial>
レグ(leg)で発生します。
イベント | 概要 |
---|---|
initiated | Twilioがダイヤリングを始めた時、initiated イベントが発動します。 |
ringing | 電話が鳴り始めると、ringing イベントが発動します。 |
answered | 通話を開始(受話)するとanswered イベントが発動します。 |
completed | completed イベントは端末の状態に関係なく(busy 、canceled 、completed 、failed 、no-answer )コールが終了した時に発動します。 StatusCallbackEvent が指定されない場合、completed がデフォルトで発動されます。 |
statusCallback
statusCallback
属性は statusCallbackEvent
属性に含まれるそれぞれの指定されたイベントに送るwebhookリクエストのURL特定します。
statusCallbackMethod
statusCallbackMethod
属性では、TwilioがstatusCallback
属性で与えられたURLにアクセスする際に、どのHTTPメソッドを用いるかを指定します。デフォルトは POST
です。
Status Callback HTTP パラメーター
TwilioがTwilio番号の一つのコールを受信した時、Twilioがアプリケーションに渡すStatusCallback
に送信される非同期のリクエスト中のパラメーターはTwiML検索するために非同期のリクエストにパラメーターを含めます。全てのリストと詳細はTwiML Voiceリクエストドキュメントをご覧ください。
コールプログレスイベントが発動された時、コールバックリクエストは、この他にも次のパラメーターを渡します。
パラメーター | 概要 |
---|---|
CallSid | Twilio が生成したこの通話のユニークな識別子です。CallSid は新しい TwiML URLと共に Call/{CallSid}をPOSTし、チャイルドコールを修正することができます。 |
ParentCallSid | 親コールを一意に特定する識別子 |
CallStatus | このコールのステータス詳細取りうる値は queued (キューに入った), initiated (処理が開始された), ringing (呼び出し中), in-progress (通話中), busy (話し中), failed (失敗), no-answer (電話に出ず) です。詳細はコールのステータス セクションをご覧ください |
CallDuration | 通話の秒数completed のイベントにのみ現れます。 |
RecordingUrl | 音声通話の録音済みオーディオのURLです。 このパラメーターは録音が <Dial> で設定されている場合に追加され、その他の手段で開始された録音には含まれません。 RecordingUrl は completed イベント内にのみ存在します。 |
RecordingSid | この通話から発生した録音の一意なIDRecordingSid はcompleted のイベントでのみ発生します。 |
RecordingDuration | 録音されたオーディオの長さ (秒) です。 RecordingDuration は completed イベント内にのみ存在します。 無音部分を削除した後の正確な録音の長さの確定値を取得するには、RecordingStatusCallbackを使用してください。 |
Timestamp | このイベントが生成された日付の UTC 表記です。RFC 2822フォーマットを使用します。 |
CallbackSource | webhookのソースを記述する文字webhookがなぜ発生したか曖昧さの排除に役立ちます。Status Callback では、値は常にcall-progress-events です。 |
SequenceNumber | イベントが発動する順番は、0 から始まります。イベントが順々に発動すると、分離されたHTTPリクエストを生成し、同じ順番の到着は保証されません。 |
サンプル
例 1: sendDigits を使う
In this case, we want to dial the 1928 extension at 415-123-4567. We use a <Number>
noun to describe the phone number and give it the attribute sendDigits
. We want to wait before sending the extension, so we add a few leading w
characters. Each w
tells Twilio to wait half a second instead of playing a digit. This lets you adjust the timing of when the digits begin playing to suit the phone system you are dialing.
例 2: 一斉発信
In this case, we use several <Number>
tags to dial three phone numbers at the same time. The first of these calls to answer will be connected to the current caller, while the rest of the connection attempts are canceled.
例 3: コールプログレスイベント
In this case, we want to receive a webhook for each call progress event when dialing a number using <Dial>
.
例 4:コールプログレスイベントによる複数のダイヤル
In this case, we want to receive a webhook for each call progress event for each number when dialing multiple numbers using <Dial>
.
Example 5: Running TwiML Before Parties Are Connected
In this case, we want to connect two parties using <Dial>
, but we also want TwiML instructions to be sent to the party we are calling before they are connected to the call. By setting the url
attribute, we can specify a URL that will return a TwiML response to be run on the called party’s end. This TwiML will run after they answer, but before the parties are connected.
ヒントとテクニック
- You can specify up to ten numbers within a
<Dial>
verb to dial simultaneously. - Simultaneous dialing is useful when you have several phones (or several people) that you want to ring when you receive an incoming call. Keep in mind that the first call that connects will cancel all the other attempts. If you dial an office phone system or a cellphone in airplane mode, it may pick up after a single ring, preventing the other phone numbers from ringing long enough for a human ever to answer. So you should take care to use simultaneous dialing only in situations where you know the behavior of the called parties.
ヘルプが必要ですか?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.