IVR: Node.jsおよびExpressを使用したフォンツリー
この Node.js Express サンプルアプリケーションは、一般的なコールセンターのエクスペリエンスをモデルとしていますが、さらに多くの Reese's Pieces が点在しています。
Stranded aliens can call a phone number and receive instructions on how to get out of earth safely, or call their home planet directly. In this tutorial, we'll show you the key bits of code to make this work.
このサンプルアプリを自分で実行するには、コードをダウンロードし、GitHub の指示に従ってください。
Read how Livestream and other companies built phone trees on IVR with Twilio. Find guides for many web languages on our IVR example page.
通話への応答
電話ツリーを始めるには、着信を受けたときに HTTP リクエストをウェブアプリケーションに送信するように、いずれかの Twilio 番号を設定しておく必要があります。
いずれかの番号をクリックして、アプリをポイントするように Voice URL を設定します。コードでは、経路は /ivr/welcome
になります。
If you don't already have a server configured to use as your webhook, ngrok is a great tool for testing webhooks locally.
構成済みのTwilio番号で、Twilioのリクエストに応答する準備が整います。
TwiML で Twilio リクエストに応答する
Our Twilio number is now configured to send HTTP requests to this route method on any incoming voice calls. Our app responds with TwiML to tell Twilio what to do in response to the message.
In this case we tell Twilio to Gather
the input from the caller and we Say
a welcome message.
After saying the text to the caller and retrieving their input, Twilio will send this input to our application.
発信者の入力を送信する場所
gather の action
パラメーターは値として絶対 URL または相対 URL を取ります(このケースでは、/ivr/menu
経路)。
When the caller has finished entering digits, Twilio will make a GET or POST request to this URL including a Digits
parameter with the number our caller chose.
このリクエストの発行後、Twilioはレスポンスで受信したTwiMLを使用して現在の通話を継続します。 <Gather>
の後に現れるTwiML動詞は、発信者が番号をプッシュしない限り到達できません。
Now that we have told Twilio where to send the caller's input, we can look at how to process that input.
メインメニュー:発信者の選択を処理する
この経路は、発信者の入力の処理を扱います。
If our caller chooses '1' for directions, we use the helper method giveExtractionPointInstructions
to respond with TwiML that will Say
directions to our caller's extraction point.
発信者が「2」を選択して彼らの母星に電話をかけた場合、追加の情報の収集が必要になります。 これについては次の手順で取り上げます。
発信者が他の番号を押した場合、メインメニューにリダイレクト (Redirect
) するTwiMLで応答します。
発信者が「2」を選択した場合は「惑星電話帳」に案内して、追加の入力を収集します。
惑星電話番号ディレクトリー:発信者を別の番号に接続する
If our callers choose to call their home planet we will read them the planet directory. This is akin to a typical "company directory" feature of most IVRs.
In this route, we grab the caller's selection from the request and store it in a variable called selectedOption
. We then use a Dial
verb with the appropriate phone number to connect our caller to their home planet.
現在の番号はハードコード化されていますが、データベースやファイルから読み取ることもできます。
これで終わりです。お客様を楽しませ、対応する IVR 電話ツリーを実装できました。
次はどこでしょうか?
Twilio を使う Node.js 開発者であれば、他のチュートリアルも調べてみてください。
Twilio および Twilio 駆動型 Authy を使用して、登録時のアカウント認証を実装します。
Twilio および Twilio 駆動型 Authy OneTouch を使用して、二要素認証(2FA)をウェブアプリケーションで実装します。
これは役に立ちましたか?
Thanks for checking out this tutorial! If you have any feedback to share with us, we'd love to hear it. Connect with us on Twitter and let us know what you build!
ヘルプが必要ですか?
誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。