メニュー

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

SMS and MMS Marketing Notifications with C# and ASP.NET MVC

SMS および MMS マーケティング通知を実装する準備はできましたか?

Excellent - you've come to the right place. Today we'll explore adding them to a C# and ASP.NET MVC application.

下記が、ひととおりの仕組みの概要になります:

  1. A possible customer sends an SMS to a Twilio phone number you advertise somewhere.
  2. Your application confirms that the user wants to receive SMS and MMS notifications from your company.
  3. 管理者またはマーケティングキャンペーンマネージャーは、ウェブフォームを使用して、すべての購読者に SMS/MMS メッセージで送信されるメッセージを作成します。

ビルディングブロック

To get this done, we'll be working with the following Twilio tools:

さぁ、はじめましょう! 矢印ボタンをクリックして、チュートリアルの次のステップに進みましょう。

購読者

In order to send out marketing notifications to a subscriber, we need to first provide the right model:

  • PhoneNumber will store where to send the notifications.
  • Subscribed will store who is opted in to receive notifications.
        
        
        
        
        MarketingNotifications.Web/Models/Subscriber.cs

        購読者モデル

        MarketingNotifications.Web/Models/Subscriber.cs

        Next, let's look at how we'll manage incoming messages.

        着信メッセージの処理

        これは、アプリケーションがメッセージを受信するたびに呼び出されるエンドポイントです。

        It relies on a MessageCreator abstraction that produces the message that will be returned to the sender. It also neatly hides the complexity behind creating new subscribers.

              
              
              
              
              MarketingNotifications.Web/Controllers/SubscribersController.cs

              The Subscribers Controller

              MarketingNotifications.Web/Controllers/SubscribersController.cs

              When a new user sends us a message, we need to manage adding him or her to our database. We'll explore that functionality next.

              Add Some New Users

              Creating New Subscribers

              We begin by getting a new customer'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 to reply "add" back. We are very careful to confirm they want to receive messages from our company before flagging them as subscribed.

                    
                    
                    
                    
                    MarketingNotifications.Web/Domain/MessageCreator.cs

                    Looking up a user and potentially adding them to the database

                    MarketingNotifications.Web/Domain/MessageCreator.cs

                    このステップですべきことはこれでおしまいです。 メッセージを要求した人を捕捉するため、Subscriber オブジェクトを作成しました。 また彼らが初回にメッセージを送信するときに、それをデータベースに保存します。

                    Next let's go further and look at how a user will modify his or her subscriber status.

                    購読を管理する

                    ユーザーの購読状態の管理に、addremove という2つのSMSコマンドを提供することにします。 

                    These commands will toggle a boolean flag for their Subscriber record in the database, and will determine whether or not they want to receive messages from our marketing campaign. Because we want to respect our users' desires, we don't opt them in automatically. We are sure to have them confirm that they want to receive our messages.

                    これを実現するためには、着信テキストメッセージを処理するコントローラーロジックを更新して、以下の操作を実行する必要があります。

                    • ユーザーがすでにデータベースに登録されている場合、送られてきたメッセージを解析して既知のコマンドであるかどうか確認します。
                    • If it is a add or remove command, update her or his subscription status in the database.
                    • If it is a command we don't recognize, send her or him a message explaining available commands.
                          
                          
                          
                          
                          MarketingNotifications.Web/Domain/MessageCreator.cs

                          Dealing with incoming user commands

                          MarketingNotifications.Web/Domain/MessageCreator.cs

                          With the logic behind subscribing and unsubscribing implemented, let's move on to sending messages out.

                          通知の送信

                          On the server, we grab an incoming form's text and (optional) image URL, then loop through all Subscribers to call the method Send on our MessageSender domain object.

                          When the messages are on their way, we redirect the form submitter back to the same form with a ViewBag Property message containing feedback about the messaging attempt.

                                
                                
                                
                                
                                MarketingNotifications.Web/Controllers/NotificationsController.cs

                                The Notifications controller

                                MarketingNotifications.Web/Controllers/NotificationsController.cs

                                And how do we actually send the MMS or SMS messages? Glad you asked - let's go there next.

                                Send MMS and SMS Messages

                                SMS または MMS 通知を送信する

                                Now that we have a list of subscribers for our awesome SMS and MMS content, we need to provide our marketing team some kind of interface to send out their perfectly crafted messages.

                                When the model object is loaded, it initializes a Twilio REST API client that it 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 call MessageResource.CreateAsync in order to send our message. The Twilio Message API call requires a From and To parameter, and either Body or a MediaUrl (or both).

                                      
                                      
                                      
                                      
                                      MarketingNotifications.Web/Domain/NotificationService.cs

                                      A Notifications service

                                      MarketingNotifications.Web/Domain/NotificationService.cs

                                      And that's a wrap! You should now be able to easily integrate this awesome feature into your own application. On the next pane, we'll look at some other easy-to-implement features.

                                      他に構築できるもの

                                      次はどこでしょうか?

                                      That's it! We've just implemented a an opt-in process and an administrative interface to run an SMS and MMS marketing campaign all through C# and ASP.NET MVC. Now all you need is killer content to share with your users via text or MMS... and you're on your own for that.

                                      Twilio and .NET go together very well - perhaps you'd enjoy these other tutorials?

                                      IVR: フォンツリー

                                      Build an automated phone tree with C# and Twilio's powerful features.

                                      自動アンケート

                                      Don't let valuable feedback slip away - conduct instant surveys with voice or SMS.

                                      これは役に立ちましたか?

                                      このチュートリアルをお読みいただき、ありがとうございます。

                                      We'd love to hear from you - Tweet to us @twilio with what you're building!

                                      Agustin Camino Andrew Baker Paul Kamp Kat King Hector Ortega
                                      Rate this page:

                                      ヘルプが必要ですか?

                                      誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。