JavaおよびServletを使用したSMSおよびMMS(日本未対応)通知
This Java Servlets tutorial will walk you through how you can automatically notify your system administrators if - well, when - something goes wrong on your server.
これから舞台裏で起こっていることを事細かにつまびらかにしていきます。 ほどなくして、ご自身のアプリケーションで通知が機能するようにするのがいかに簡単か気がつくことでしょう。
See how EMC uses Twilio SMS to send IT alerts to 68,000 employees.
Sound good? Let's get started!
下のボタンをクリックして、チュートリアルの次の手順に移動してください。
List Your Server Administrators
ここでは、サーバーエラーが発生したときに通知されるべき管理者(および選択した他の人たち)の一覧を作成します。
The only essential piece of data we need is a text-enabled phoneNumber
for each person you list.
Next at the plate: we'll take a look at how to set up the Twilio REST client.
Twilioクライアントを構成する
To send a message we'll need to initialize the TwilioRestClient
(for details, see the Twilio Java Helper LibraryTwilio Java Helper Library documentation).
環境変数から TWILIO_ACCOUNT_SID
およびTWILIO_AUTH_TOKEN
を読み込むことが必要です。
アカウントSIDと認証トークンの値は、Twilio Consoleから取得できます:
Next, let's look at how we're handling application exceptions.
アプリケーションの例外を処理する
Servlet Filterを使用して、Servletまたは特定のURLを処理するためにセットアップされたFilterによってスローされた、ハンドルされていない例外を捕捉できます。
そして、ここがサーバー管理者に通知を創出するロジックを追加する場所になります。
Next up, let's look at how to craft a custom message upon spotting an exception.
Crafting a Custom Alert Message
ここでは、テキストメッセージを介して送信されるアラートメッセージを作成します。
Feel free to also include a picture with your notification message. Perhaps a screenshot of the application when the exception happened? Some meme from a chain email?
続いて、管理者の一覧の読み込みを見てみましょう。
JSONファイルから管理者の一覧を読み込む
続いて、JSONファイルから管理者を読み込みます。
We're relying on the Gson Java library to convert our JSON text file into the Administrator
objects from our application.
And for our next trick, we'll show how the text messages themselves are sent. Carry on!
テキストメッセージの送信
Twilio REST APIを使用したSMSの送信には、3つのパラメーターが必要です: From
、To
、およびBody
です。
US and Canadian phone numbers can also send an image with the message. Other countries will have the picture url automatically shortened.
以上で作業は完了です!
We've just implemented an automated server notification system that can send your administrators push alerts if anything goes wrong. Twilio makes it easy to incorporate these important - and useful - functions for your own use cases.
続けて、弊社のお客様がTwilioを使用している便利な方法をいくつか見ていきます。
次はどこでしょうか?
We've built a lot of sample applications with Twilio and Java, and we'd love to share them all. However, we'll limit our suggestions to just two:
Instantly collect structured data from your users with a survey conducted over a voice call or SMS text messages. That will help you quantify the impact of your support call handling, for starters.
If you're having issues with customers missing booked meetings, this tutorial is where you should head next. We look at sending automatic reminders as a meeting approaches.
これは役に立ちましたか?
Thanks for checking out this tutorial! Tweet to us @twilio to let us know what you thought or what you're building next!
ヘルプが必要ですか?
誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。