LoginSignup
1
3

More than 5 years have passed since last update.

【Twilio超入門】Twilioを使用して固定電話や携帯電話へ"ロボット音声"電話を送る方法

Last updated at Posted at 2018-12-18

Twilioとは

簡単に言えば音声ロボットを作って
そのロボットに電話を任せることが出来ます。

"宅配便の再配達"電話等の
ロボットによる電話サービスを作れます。

参考URL

Programmable Voice クイックスタート for Node.js

コマンドプロンプトの実行手順(上記URL参考)

今回はWindowsで使用します。

command_prompt (node.jsのバージョンを確認)
C:\WINDOWS\system32>node –version
v8.11.4
command_prompt (パスを変更)
C:\WINDOWS\system32>cd C:\Users\wafuu\Desktop\node
command_prompt (twilioをインストール)
C:\Users\wafuu\Desktop\node>npm install twilio
npm WARN deprecated scmp@0.0.3: scmp v2 uses improved core crypto comparison since Node v6.6.0
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\wafuu\Desktop\node\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\wafuu\Desktop\node\package.json'
npm WARN node No description
npm WARN node No repository field.
npm WARN node No README data
npm WARN node No license field.

+ twilio@3.24.0
added 81 packages in 7.55s
command_prompt (make_call.jsを実行)

C:\Users\wafuu\Desktop\node>node make_call.js
CA6f152f91422b4d3cbb32c899cc24c94d

C:\Users\wafuu\Desktop\node>

make_call.jsの中身

make_call.js
// Download the helper library from https://jp.twilio.com/docs/node/install
// Your Account Sid and Auth Token from twilio.com/console
const accountSid = 'AC〇〇'; // 変更箇所
const authToken = '〇〇'; // 変更箇所
const client = require('twilio')(accountSid, authToken);

client.calls
      .create({
         url: 'http://demo.twilio.com/docs/voice.xml', // 通話で実行するURL
         to: '+81〇〇', // かける電話番号
         from: '+81〇〇' // サービスに登録した電話番号
       })
      .then(call => console.log(call.sid))
      .done();

このコードはC:\Users\wafuu\Desktop\nodeフォルダの中に置いてある。
このコードを実行すると登録した電話番号に電話がかかる。

voice.xmlの中身

voice.xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say voice="alice">Thanks for trying our documentation. Enjoy!</Say>
    <Play>http://demo.twilio.com/docs/classic.mp3</Play>
</Response>

かかってきた電話に出ると、
classic.mp3が再生される(音声ファイル)

以上、導入方法でした。

1
3
0

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
1
3