LoginSignup
51
51

More than 5 years have passed since last update.

【ハンズオン資料】電話API Twilio 初心者向け

Last updated at Posted at 2015-04-24

このページは、Twilioのハンズオン参加者向けで作成しました。

■ Twilio公式ドキュメント
Twilio公式ドキュメント
TwiML
REST API
サンプルコード
Helper ライブラリ

■ 新規アカウント登録(無料)
https://jp.twilio.com/try-twilio/kddi-web

・新規登録ガイドライン(ブログ)
http://twilio.kddi-web.com/blog/developper/entry000195.html

■ ハンズオンで使うコード
テキストを音声へ:Say
・ドキュメント:https://jp.twilio.com/docs/api/twiml/say

twiml-say.xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say language="ja-jp">テキストを音声に変換します。</Say>
</Response>

録音:Record
・ドキュメント:https://jp.twilio.com/docs/api/twiml/record

twiml-record.xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say language="ja-jp">録音を行います。メッセージを残してください。</Say>
    <Record />
</Response>

音声ファイルの再生:Play
・ドキュメント:https://jp.twilio.com/docs/api/twiml/play

twiml-play.xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say language="ja-jp">音声ファイルを再生します。</Say>
    <Play>{音声ファイルのURL}</Play>
</Response>

通話処理の分岐:Gather
・ドキュメント:https://jp.twilio.com/docs/api/twiml/gather

twiml-gather.xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather timeout="10" finishOnKey="*">
        <Say>電話機の数字ボタンを押してください。</Say>
    </Gather>
</Response>

・PHPライブラリーから発信

calling.php
<?php

require('../Services/Twilio.php');

$account_sid = "ACxxxxxxxxxxx";
$auth_token = "xxxxxxxxxxxx";

$client = new Services_Twilio($account_sid, $auth_token);

$call = $client->account->calls->create("+8150xxxxxxx", "+8180xxxxxxx", "http://xxxxxxx/say.xml", array("Method" => "GET"));
echo $call->sid;

■ コマンド
scp : scp -P 22 [filename] twilioapistudy@xxx.xxx.xxx.xxx:/var/www/html/twilio/xxxx/
例) scp -P 22 incomming.xml twilioapistudy@xxx.xxx.xxx.xxx:/var/www/html/twilio/xxxx/

mkdir(ディレクトリの生成) : mkdir [option] [ディレクトリ名]
rm(ディレクトリやファイルの削除) : rm [option] [ディレクトリもしくはファイル名]
[option] -d:ディレクトリ削除、-r,-R:ディレクトリ無いのファイルを含めて削除

■ TwilioJP-UG
https://twiliojp-ug.doorkeeper.jp/

■ Twilioのコミュニティ
◎ twitter : @twilioforkwc
◎ facebook page : https://facebook.com/TwilioforKWC
◎ facebook group: https://facebook.com/groups/twilioforkwc
◎ SlideShare : http://slideshare.net/twilioforkwc
◎ Doorkeeper:http://twiliomeetup.doorkeeper.jp
◎ GitHub:https://github.com/twilioforkwc
◎ YouTube:https://youtube.com/user/twilioforkwc

51
51
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
51