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.
- A guest requests a reservation for a property
- ホストには予約リクエストを知らせるSMSが受信されます。 ホストは予約を「承諾」または「否認」します
- The guest is notified whether a request was rejected or accepted
We'll be using the Twilio REST API to send our users messages at important junctures. Here's a bit more on our API:
Let's get started! Click the below button to begin.
For this workflow to work, we need to have
Users created in our application, and allow them to log into Airtng.
User model stores a user's basic information including their phone number. We'll use that to send them SMS notifications later.
Next, let's look at how we define the VacationProperty model.
In order to build a vacation rentals company we need a way to create the property listings.
image_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.
vacation_propertythe guest is requesting (and associated host)
Now that we have our models, let's see how a user would create 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
reject response, the system knows which
reservation to update.
Now that we have seen how we will initiate a reservation, let's look at how to notify the host.
When a reservation is created for a property, we want to notify the
host of the reservation request.
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.
Next, let's see how to handle incoming messages from Twilio webhooks.
This method handles the Twilio request triggered by the host's SMS and does three things:
- Checks for a pending reservation from a user
- Responds to the host and sends a notification to the user
In the Twilio console, you should change the 'A Message Comes In' webhook to call your application's endpoint in the route
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:
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.
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!