SMS and MMS Marketing Notifications with Java and Servlets
Ready to implement SMS and MMS marketing notifications with Java and Servlets?
下記が、ひととおりの仕組みの概要になります:
- A possible customer sends an SMS to a Twilio phone number you advertise somewhere.
- Your application confirms that the user wants to receive SMS and MMS notifications from your company.
- An administrator or marketing campaign manager uses a web form to craft a message to push to all subscribers via SMS/MMS message.
ビルディングブロック
これを行うには、以下のツールを操作します。
- TwiML and the <Message> verb: We'll use TwiML to manage interactions initiated by the user via SMS.
- Messages Resource: We will use the REST API to broadcast messages out to all subscribers.
さぁ、はじめましょう! 下のボタンをクリックして、チュートリアルの次の手順に移動してください。
The Subscriber Model
Before send out marketing notifications to a subscriber, we need to start with the perfect model:
phoneNumber
stores where to send the notifications.subscribed
stores if a subscriber is active (only an active subscriber will receive notifications).
Let's see how to handle incoming messages.
Handle Incoming Messages
これは、アプリケーションがメッセージを受信するたびに呼び出されるエンドポイントです。
We begin by getting the user's phone number from the incoming Twilio request. Next, we try to find a Subscriber
model with that phone number.
If there's no subscriber with this phone number, we create one, save it, and respond with a friendly message asking our newest user to send an SMS with "add" as a command. This is done to confirm that they want to receive messages from us.
Twilio can send your web application an HTTP request when certain events happen, such as an incoming text message to one of your Twilio phone numbers. These requests are called webhooks, or status callbacks. For more, check out our guide to Getting Started with Twilio Webhooks. Find other webhook pages, such as a security guide and an FAQ in the Webhooks section of the docs.
We've created a Subscriber
model to keep track of the people that want our messages. Now, let's look at the options we provide our users for opting in or out.
Managing User Subscriptions
ユーザーの購読状態の管理に、add
と remove
という2つのSMSコマンドを提供することにします。
These commands will toggle a boolean flag for their Subscriber
record in the database and will determine whether they get our marketing messages. Because we want to respect our user's preferences, we don't opt them in automatically - rather, we have them confirm that they want to receive SMSes or MMSes from us.
これを実現するためには、着信テキストメッセージを処理するコントローラーロジックを更新して、以下の操作を実行する必要があります。
- If it is a
add
orremove
command, create/update aSubscription
with the right status in the database. - もし認識しないコマンドだった場合は、利用可能な2つのコマンドを説明するメッセージを送信します。
Let's now take a look at how to send notifications.
Send Notifications Out
When a form is submitted, we first grab the message text and/or image URL. Second, we loop through all Subscribers and call the method send
on our Sender
domain object.
When the messages are on their way, render the index page with a success message and delight the marketing team.
Let's take a closer look at how to send SMS or MMS notifications.
SMSおよびMMS(日本未対応)通知の送信
When the model object is loaded, it creates a Twilio REST API client that can be used to send SMS and MMS messages. The client requires your Twilio account credentials (an account SID and auth token), which can be found in the console:
Next, all we need to do is create
a message using the MessageCreator
class. The Twilio Message API call creator requires To
, From
and Body
parameters. MediaUrl
is an optional parameter.
これで終わりです。SMS および MMS マーケティングキャンペーンを実行するためのオプトインプロセスと管理インターフェイスを実装しました。これで、あと必要なのはテキストまたは MMS でユーザーと共有するキラーコンテンツのみとなりました。
次はどこでしょうか?
Love Java? So do we at Twilio! Here are two other excellent tutorials you should check out:
SMS 通知は、重要なイベントが発生した場合に迅速にアラートを送信するのにうってつけの方法です。この例では、Web アプリケーションでエラーが発生した場合に、リストに載っている関係者に SMS 通知を送信する方法を示します。
Don't let valuable insights slip away - survey your customers with Voice and SMS.
これは役に立ちましたか?
Thanks for checking out this tutorial... tweet @twilio to let us know how you did and what you're building!
ヘルプが必要ですか?
誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。