Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now


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?



At its core, setting up a standardized workflow is about enabling your service providers (agents, hosts, customer service reps, administrators, and the rest of the gang) to better serve your customers.

To illustrate a very real-world example, today we'll build a Python and Flask webapp for finding and booking vacation properties — tentatively called Airtng.


  1. ホストが貸別荘の一覧を作成します
  2. A guest requests a reservation for a property
  3. ホストには予約リクエストを知らせるSMSが受信されます。 ホストは予約を「承諾」または「否認」します
  4. The guest is notified whether a request was rejected or accepted

AirbnbがTwilio SMSを使用して、世界中の6千万以上の旅行者たちに対するレンタル体験を明解にしている方法を学びましょう。


We'll be using the Twilio REST API to send our users messages at important junctures. Here's a bit more on our API:


        Load the application configuration


        さぁ、はじめましょう! 下のボタンをクリックしてください。

        Automate A Workflow

        User and Session Management

        For this workflow to work, we need to have Users created in our application, and allow them to log into Airtng.

        Our User model stores a user's basic information including their phone number. We'll use that to send them SMS notifications later.


              The Airtng User model


              Next, let's look at how we define the VacationProperty model.

              The VacationProperty Model

              In order to build a vacation rentals company we need a way to create the property listings.

              VacationProperty モデルはそれを作成した User(今後このユーザーをホストと呼ぶ)に属し、descriptionimage_url の 2 つのプロパティーだけが含まれます。

              We also include a couple database relationship fields to help us link vacation properties to their hosts as well as to any reservations our users make.




                    Next we'll take a look at how to model a reservation.


                    Reservation モデルは、このアプリケーションに対するワークフローの中心です。以下の追跡を担当します。

                    • 予約を実行した guest
                    • The vacation_property the guest is requesting (and associated host)
                    • 予約のステータス: pending(保留)、confirmed(承認)、またはrejected(否認)



                          Now that we have our models, let's see how a user would create a reservation.

                          Creating a Reservation

                          The reservation creation form holds only one field, the message that will be sent to the host user when reserving one of her properties.

                          The rest of the information necessary to create a reservation is taken from the user that is logged into the system and the relationship between a property and its owning host.

                          A reservation is created with a default status pending, so when the host replies with an accept or reject response, the system knows which reservation to update.


                                Routes for the Airtng workflow


                                Now that we have seen how we will initiate a reservation, let's look at how to notify the host.

                                Show Me How to Notify the Host

                                Notify the Host via SMS

                                When a reservation is created for a property, we want to notify the host of the reservation request.

                                We use Twilio's Rest API to send a SMS message to the host, using a Twilio phone number.

                                Now we just have to wait for the host to send an SMS response accepting or rejecting the reservation. At that point we can notify the user and host and update the reservation information accordingly.


                                      Notify the user and the host


                                      Next, let's see how to handle incoming messages from Twilio webhooks.

                                      Hook 'Em

                                      Handle Incoming Twilio Requests

                                      This method handles the Twilio request triggered by the host's SMS and does three things:

                                      1. Checks for a pending reservation from a user
                                      2. 予約のステータスを更新する
                                      3. Responds to the host and sends a notification to the user

                                      Setting Up Incoming Twilio Requests

                                      In the Twilio console, you should change the 'A Message Comes In' webhook to call your application's endpoint in the route /confirm:

                                      SMS Webhook

                                      One way to expose your machine to the world during development is using ngrok. Your URL for the SMS web hook on your phone number should look something like this:


                                      Twilio からの着信リクエストには、有益なパラメーターが付いています。From 電話番号やメッセージ Body などです。

                                      We'll use the From parameter to look up the host and check if he or she has any pending reservations. If she does, we'll use the message body to check for the message 'accepted' or 'rejected'. Finally, we update the reservation status and use the SmsNotifier abstraction to send an SMS to the guest telling them the host accepted or rejected their reservation request.

                                      TwiML レスポンス

                                      In our response to Twilio, we'll use Twilio's TwiML Markup Language to command Twilio to send an SMS notification message to the host.



                                            You've just learned how to automate your workflow with Twilio Programmable SMS. In the next pane, we'll look at some other features Twilio makes it easy to add.



                                            To improve upon this you could add anonymous communications so that the host and guest could communicate through a shared Twilio phone number: Call Masking with Python and Flask.



                                            Create a seamless customer service experience by building an IVR (Interactive Voice Response) Phone Tree for your company.


                                            ウェブトラフィックをボタンのクリック 1 つで、電話のトラフィックに変換します。


                                            Thanks for checking out this tutorial! If you have any feedback to share with us, please hit us up on Twitter and let us know what you're building!

                                            Andrew Baker Jose Oliveros Agustin Camino Paul Kamp David Prothero Kat King
                                            Rate this page:


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