Twilioで何が構築できるかを確認する

通話メニューのデモを試して仕組みをご確認ください。

Twilioで何が構築できるかを確認する

(323) 992-0315に電話し、コード6240を入力してください

(このデモの終了後に、お客様の電話番号を保存したり使用したりすることはありませんので、ご安心ください)。

こんにちは!

(323) 992-0315に電話して「6240」を入力してください。通話とこのテキストエディタがペアリングされます。IVRに電話すると聞こえるメッセージをTwilioがカスタマイズします。

次へ: 通話メニューをカスタマイズ


using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;

var response = new VoiceResponse();

var gather = new Gather(input: "dtmf", numDigits: 1);
gather.Say("Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you've made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.");

response.Append(gather);

Console.WriteLine(response.ToString());

var gather = new Gather(input: "dtmf", numDigits: 4);
gather.Say("Please enter the 4 digit code on your screen to get started");

response.Append(gather);

Console.WriteLine(response.ToString());

import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.*;

import java.util.Arrays;

Say say = new Say.Builder("Please enter the 4 digit code on your screen to get started.")
	.build();

Gather gather = new Gather.Builder()
	.inputs(Arrays.asList(Gather.Input.DTMF))
	.numDigits(4)
	.say(say)
	.build();

VoiceResponse response = new VoiceResponse.Builder().gather(gather)
	.build();

System.out.println(response.toXml());

const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();

const gather = response.gather({
	input: 'dtmf',
	numDigits: '4',
});

gather.say('Please enter the 4 digit code on your screen to get started');

console.log(response.toString());

<?php
require_once './vendor/autoload.php';

use Twilio\TwiML;

$response = new TwiML();

$gather = $response->gather(['input' => 'dtmf', 'numDigits' => '4']);
$gather->say('Please enter the 4 digit code on your screen to get started.');

echo $response;

from twilio.twiml.voice_response import VoiceResponse, Gather

response = VoiceResponse()

gather = Gather(input='dtmf', num_digits=4)
gather.say('Please enter the 4 digit code on your screen to get started.')

response.append(gather)

print(response)

require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new do |r|
  r.gather(numDigits: 4, input: 'dtmf') do |g|
    g.say(message: 'Please enter the 4 digit code on your screen to get started.')
  end
end

puts response

<Response>
	<Gather input="dtmf" numDigits="1">
		<Say>Please enter the 4 digit code on your screen to get started.</Say>
	</Gather>
</Response>

import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.*;

import java.util.Arrays;

Say say = new Say.Builder("Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you&rsquo;ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.")
&#x9;.build();

Gather gather = new Gather.Builder()
	.inputs(Arrays.asList(Gather.Input.DTMF))
	.numDigits(1)
	.say(say)
	.build();

VoiceResponse response = new VoiceResponse.Builder().gather(gather)
	.build();

System.out.println(response.toXml());
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();

const gather = response.gather({
  input: 'dtmf',
  numDigits: '1',
});

gather.say('Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you’ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.');

console.log(response.toString());

<?php
require_once './vendor/autoload.php';

use Twilio\TwiML;

$response = new TwiML();

$gather = $response->gather(['input' => 'dtmf', 'numDigits' => '1']);
$gather->say('Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you\'ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.');

echo $response;
from twilio.twiml.voice_response import VoiceResponse, Gather

response = VoiceResponse()

gather = Gather(input='dtmf', num_digits=1)
gather.say('Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you\'ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.')

response.append(gather)

print(response)

require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new do |r|
	r.gather(numDigits: 1, input: 'dtmf') do |g|
		g.say(message: 'Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you’ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.')
	end
end

puts response

<Response>
	<Gather input="dtmf" numDigits="1">
		<Say>Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you’ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR. </Say>
	</Gather>
</Response>

つながっていますか?ウェルカムメッセージが聞こえているはずです。このウェルカムメッセージを変更し、電話を掛け直すか「*」を押すと、編集後の内容を聞くことができます。

よくできました!通話の処理方法をTwilioに伝える手順を説明します。

次へ:  TwiML


using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;

var response = new VoiceResponse();

var gather = new Gather(input: "dtmf", numDigits: 1);
gather.Say("Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you've made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.");

response.Append(gather);

Console.WriteLine(response.ToString());

import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.*;

import java.util.Arrays;

Say say = new Say.Builder("Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you&rsquo;ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.")
&#x9;.build();

Gather gather = new Gather.Builder()
	.inputs(Arrays.asList(Gather.Input.DTMF))
	.numDigits(1)
	.say(say)
	.build();

VoiceResponse response = new VoiceResponse.Builder().gather(gather)
	.build();

System.out.println(response.toXml());

const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();

const gather = response.gather({
  input: 'dtmf',
  numDigits: '1',
});

gather.say('Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you’ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.');

console.log(response.toString());

<?php
require_once './vendor/autoload.php';

use Twilio\TwiML;

$response = new TwiML();

$gather = $response->gather(['input' => 'dtmf', 'numDigits' => '1']);
$gather->say('Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you\'ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.');

echo $response;

from twilio.twiml.voice_response import VoiceResponse, Gather

response = VoiceResponse()

gather = Gather(input='dtmf', num_digits=1)
gather.say('Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you\'ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.')

response.append(gather)

print(response)

require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new do |r|
	r.gather(numDigits: 1, input: 'dtmf') do |g|
		g.say(message: 'Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you’ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR.')
	end
end

puts response

<Response>
	<Gather input="dtmf" numDigits="1">
		<Say>Welcome to the Twilio IVR! You can modify this message by changing this text in your browser. Hang up and call back to hear the changes you’ve made or press * to restart this IVR with your changes. Press 2 to continue with the IVR. </Say>
	</Gather>
</Response>

Twilioで電話を制御するには、TwiML(Twilio Markup Language)を使用します。お客様のTwiMLコードにより、お客様のアプリが新しい通話を受信したときにTwilioがすべきことを指示します。TwiMLは、raw XMLや右に示すお好みのサーバー側言語(加えて、Twilioヘルパーライブラリー)を使用して書くことができます。

TwiMLの動詞の<Say>は、このダイナミックテキストを発信者に向けて読み上げるようにTwilioに指示するコードです。25言語の50以上の音声が用意されています。一方、事前録音されたメッセージや音楽などの音声ファイルを発信者に対して再生するときは、<Play>を使用します。

TwiML動詞の<Gather>では、数字を収集するか、発信者の話をテキスト化します。発信者が話し終えると、Twilioはそのデータを指定の`action` URLへ送信します。

次へ: 詳細を知りたいコマンドを選んでください: <Dial><Record>SMS


using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;

var response = new VoiceResponse();

var gather = new Gather(input: "speech dtmf", numDigits: 1);
gather.Say("Please choose from the following options. Press 1 or say “dial” to be connected to the Twilio support phone menu. Press 2 or say “record” to leave yourself a message. Press 3 or say “message” to send yourself an SMS. While you choose your own adventure, here’s a lovely Chopin nocturne.");

var play = new Play(new Uri("http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3"));
gather.Append(play);

response.Append(gather);

Console.WriteLine(response.ToString());

import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.*;

import java.util.Arrays;

Say say = new Say.Builder("Please choose from the following options. Press 1 or say “dial” to be connected to the Twilio support phone menu. Press 2 or say “record” to leave yourself a message. Press 3 or say “message” to send yourself an SMS. While you choose your own adventure, here’s a lovely Chopin nocturne.")
	.build();

Play play = new Play.Builder("http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3")
	.build();

Gather gather = new Gather.Builder()
	.inputs(Arrays.asList(Gather.Input.DTMF, Gather.Input.SPEECH))
	.numDigits(1)
	.say(say)
	.play(play)
	.build();

VoiceResponse response = new VoiceResponse.Builder().gather(gather)
	.build();

System.out.println(response.toXml());

const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();

const gather = response.gather({
	input: 'speech dtmf',
	numDigits: '1',
});

gather.say('Please choose from the following options. Press 1 or say “dial” to be connected to the Twilio support phone menu. Press 2 or say “record” to leave yourself a message. Press 3 or say “message” to send yourself an SMS. While you choose your own adventure, here’s a lovely Chopin nocturne.');

gather.play('http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3');

console.log(response.toString());
<?php
require_once './vendor/autoload.php';

use Twilio\TwiML;

$response = new TwiML();

$gather = $response->gather(['input' => 'speech dtmf', 'numDigits' => '1']);
$gather->say('Please choose from the following options. Press 1 or say "dial" to be connected to the Twilio support phone menu. Press 2 or say "record" to leave yourself a message. Press 3 or say "message" to send yourself an SMS. While you choose your own adventure, here’s a lovely Chopin nocturne.');
$gather->play('http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3');

echo $response;

from twilio.twiml.voice_response import VoiceResponse, Gather

response = VoiceResponse()

gather = Gather(input='speech dtmf', num_digits=1)
gather.say('Please choose from the following options. Press 1 or say "dial" to be connected to the Twilio support phone menu. Press 2 or say "record" to leave yourself a message. Press 3 or say "message" to send yourself an SMS. While you choose your own adventure, here’s a lovely Chopin nocturne.')
gather.play('http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3')

response.append(gather)

print(response)

require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new do |r|
  r.gather(numDigits: 1, input: 'dtmf') do |g|
    g.say(message: 'Please choose from the following options. Press 1 or say “dial” to be connected to the Twilio support phone menu. Press 2 or say “record” to leave yourself a message. Press 3 or say “message” to send yourself an SMS. While you choose your own adventure, here’s a lovely Chopin nocturne.')
    g.play(url: 'http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3')
  end
end

puts response

<Response>
	<Gather input="speech dtmf" numDigits="1">
	<Say>Please choose from the following options. Press 1 or say "dial" to be connected to the Twilio support phone menu. Press 2 or say "record" to leave yourself a message. Press 3 or say "message" to send yourself an SMS. While you choose your own adventure, here’s a lovely Chopin nocturne.</Say>
	<Play>http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3</Play>
	</Gather>
</Response>

<Dial>という動詞は、発信者を適切な場所に転送します。対象が、別の電話番号、電話会議、オペレーターでも、Programmable Wireless SIMでも転送できます。

この例では<Dial>を使用してTwilioサポートIVRに転送します。お客様はIVRを使用してTwilioの販売チーム、サポートチーム、フロントデスクチームにつながります。

お試しいただきありがとうございました。

無料Twilioアカウントにサインアップして専用のTwilio番号を取得し、初めてのプログラム可能な通話メニューを構築しましょう。


using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;

var response = new VoiceResponse();

response.Say("During an active call, you can use the Dial verb to connect the current caller to another party. We’re now going to connect you to the Twilio support phone menu, which we built with these same TwiML verbs.");
response.Dial("+18448144627");

Console.WriteLine(response.ToString());

import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.*;

import java.util.Arrays;

Say say = new Say.Builder("During an active call, you can use the Dial verb to connect the current caller to another party. We’re now going to connect you to the Twilio support phone menu, which we built with these same TwiML verbs.")
	.build();

Dial dial = new Dial.Builder("+18448144627")
	.build();

VoiceResponse response = new VoiceResponse.Builder()
	.say(say)
	.dial(dial)
	.build();

System.out.println(response.toXml());
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();

response.say('During an active call, you can use the Dial verb to connect the current caller to another party. We’re now going to connect you to the Twilio support phone menu, which we built with these same TwiML verbs.');

response.dial('+18448144627');

console.log(response.toString());

<?php
require_once './vendor/autoload.php';

use Twilio\TwiML;

$response = new TwiML();

$response->say('During an active call, you can use the Dial verb to connect the current caller to another party. We\'re now going to connect you to the Twilio support phone menu, which we built with these same TwiML verbs.');
$response->dial('+18448144627');

echo $response;
from twilio.twiml.voice_response import VoiceResponse, Gather

response = VoiceResponse()

response.say('During an active call, you can use the Dial verb to connect the current caller to another party. We\'re now going to connect you to the Twilio support phone menu, which we built with these same TwiML verbs.')
response.dial('+18448144627')

print(response)

require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new do |r|
  r.say(message: 'During an active call, you can use the Dial verb to connect the current caller to another party. We’re now going to connect you to the Twilio support phone menu, which we built with these same TwiML verbs.')
  r.dial(number: '+18448144627')
end

puts response

<Response>
	<Say>During an active call, you can use the Dial verb to connect the current caller to another party. We’re now going to connect you to the Twilio support phone menu, which we built with these same TwiML verbs.</Say>
	<Dial>+18448144627</Dial>
</Response>
Flowchart

完璧に動作するサンプルアプリケーションを使用した、通話メニューチュートリアルはこちら

Twilio IVRを本稼働させるために必要な残りのコードについてはこちら。

Flowchart

Twilioにより実現できる他のサービスを確認する

電話認証、予約リマインダー、Webチャットなどの本番仕様のサンプルプロジェクトをご覧ください。

Flowchart

ドラッグアンドドロップで通話メニューを設計する

Twilio Studioにより時間とスプリントを節約しましょう。チームの誰もが、お客様自身のコードかTwilioのコードを使用し、共通のフレームワーク内で音声フローを作成し変更することができます。