Python-powered Chat Apps with Twilio and SendGrid Course

6.2 hours, 100% free
Take this course for FREE
Twilio is a platform that enables you to build applications that integrate with text/SMS messages as well as other channels such as WhatsApp and voice calls. In this course, we will build a production-grade Flask application with Python 3 that adds deep integration with a customer service and ordering bot using Twilio's WhatsApp features. Additionally, we'll add SendGrid outbound email support to send our customers PDF and well-design HTML messages.

What students are saying

I thought it a well done, interesting and enjoyable program that provides very usable tips and tricks for people to be better prepared to start developing applications in Python.
-- Jeff M.

Source code and course GitHub repository

github.com/talkpython/twilio-and-sendgrid-python-course

What's this course about and how is it different?

Many courses will show you a quick how-to with Twilio. In this free course, we will build a complete, end-to-end Flask web application with modern Python tools. You will learn exactly what is needed to truly integrate text/chat with Python. We'll sketch out the workflow in Twilio Studio and then create a series of HTTP/ JSON APIs in Flask that perform key integration.

We will add text-intiated ordering for a hypothetical bakery called "Cloud City Cake Company". Over at the Cloud City website, we'll have a quick way to kick off a chat conversation in WhatsApp, hook important stages of that conversation with our Flask APIs, send rich emails and generate PDFs in Python.

Our customers will receive an email invoice as well an unprompted text message when their cake is ready for pickup. At the same time, this integration will communicate with our bakers about what cakes have been ordered and they can indicate when the cakes are finished.

What we'll build

Here is a visual summary of just some of what you'll build during this course:

Twilio demo app from the course

  • A Twilio chat interaction over WhatsApp with validation and API integration
  • Rich email response over SendGrid with formatted HTML, images, and attached generated PDF
  • A Flask admin backend to recieve the orders and notify users over chat their order is ready

What topics are covered

In this course, you will:

  • Learn how to build chat workflows in Twilio Studio
  • Integrate HTTP APIs (external and ours) with Twilio
  • Create a realistic Flask application
  • Validate chat responses and direct the workflow accordingly
  • Define HTTP JSON based endpoints for APIs with Flask
  • Use Pydantic for declarative data exchange, validation, and conversion with Flask
  • Define SQLAlchemy ORM classes to save data to a database
  • Query and update data with SQLALchemy ORMs classes
  • Send email using Python and SendGrid
  • Generate a rich PDB using Jinja2 templates in Python
  • Add attachments to outbound email
  • Send an unprompted text message to a user over WhatsApp with Twilio's Python API
  • And lots more

View the full course outline.

Who is this course for?

This course is for anyone who wants to build Twilio chat applications with Python as the backend language. The student requirements are quite light for this course. You'll need Basic Python language knowledge:

  • Basic Python language experience
  • Understanding of web applications (we'll talk through the Flask details)

Note: All Twilio and SendGrid services used in this course are based on free trial accounts. You won't have to subscribe to anything.

Concepts backed by concise visuals

While exploring a topic interactively with demos and live code is very engaging, it can mean losing the forest for the trees. That's why when we hit a new topic, we stop and discuss it with concise and clear visuals.

Here's an example of calling out the API for sending an outbound WhatsApp message with the Python Twilio library.

Example: Concepts backed by concise visuals

This course is delivered in very high resolution

Example of 1440p high res video

This course is delivered in 1440p (4x the pixels as 720p). When you're watching the videos for this course, it will feel like you're sitting next to the instructor looking at their screen.

Every little detail, menu item, and icon is clear and crisp. Watch the introductory video at the top of this page to see an example.

Follow along with subtitles and transcripts

Each course comes with subtitles and full transcripts. The transcripts are available as a separate searchable page for each lecture. They also are available in course-wide search results to help you find just the right lecture.

Each course has subtitles available in the video player.

Who am I? Why should you take my course?

Who is Michael Kennedy?

My name is Michael, nice to meet you. ;) There are a couple of reasons I'm especially qualified to teach you Python.

 1. I'm the host of the #1 podcast on Python called Talk Python To Me. Over there, I've interviewed many of the leaders and creators in the Python community. I bring that perspective to all the courses I create.

 2. I've been a professional software trainer for over 10 years. I have taught literally thousands of professional developers in hundreds of courses throughout the world.

 3. Students have loved my courses. Here are just a few quotes from past students of mine.

"Michael is super knowledgeable, loves his craft, and he conveys it all well. I would highly recommend his training class anytime." - Robert F.
"Michael is simply an outstanding instructor." - Kevin R.
"Michael was an encyclopedia for the deep inner workings of Python. Very impressive." - Neal L.

Free office hours keep you from getting stuck

One of the challenges of self-paced online learning is getting stuck. It can be hard to get the help you need to get unstuck.

That's why at Talk Python Training, we offer live, online office hours. You drop in and join a group of fellow students to chat about your course progress and see solutions via screen sharing.

Just visit your account page to see the upcoming office hour schedule.

The time to act is now

Meet your customers where they are. Text messaging is one of the highest open-rate channels and a great way for you to communicate with your users. Twilio is the leader in programmable messaging and Python one of the hottest and easiest languages out there. Put them all together with this free course. Join today.

Best of all, this course if 100% free, so give it a try. There's nothing to lose.

Course Outline: Chapters and Lectures

in a .
Head is like the header.
The body is the rows of data that we're going to put into it.
Now I'm going to copy and paste some data here, just so I remember what we're supposed to cover what's supposed to put in here in order.
But we're going to have the order_id the Customer Name, name the customer phone number, or WhatsApp number, their Email, Purchase Date, Completed Date and whether or not it is fulfilled.
And here will this non header.
Things like the action to fulfill it.
I'm going to copy this down again, and we can use that here.
So what we're going to do is we're going to add, come down here and say we're gonna do a loop and have {% for order in orders %}.
And let's just do something real simple.
7:05
show 2:01
show 3:01
show 1:22
show 0:41
6:02
show 2:10
show 1:41
show 1:17
show 0:54
59:31
show 1:33
show 4:43
show 3:19
show 2:13
show 3:20
show 4:26
show 2:14
show 2:15
show 8:03
show 1:41
show 4:02
show 4:56
show 3:01
show 5:28
show 1:28
show 4:07
show 2:42
44:43
show 0:41
show 6:02
show 6:21
show 3:05
show 3:20
show 2:39
show 3:23
show 1:59
show 4:34
show 3:33
show 7:32
show 1:34
53:45
show 1:06
show 0:57
show 3:13
show 1:31
show 6:00
show 2:03
show 3:27
show 5:00
show 4:51
show 9:11
show 2:39
show 2:39
show 3:30
show 1:30
show 2:30
show 3:38
23:25
show 0:42
show 2:56
show 5:35
show 6:13
{{order.id}}Just to see that we're actually getting something here so let's run this.
Make sure everything's hanging together.
There it is.
How exciting.
The one thing appeared one time with the number one.
All right, that's really good.
So this is working.
Let's go back and drop in a little more.
Now, We need to put in pieces of data, the dynamic data from our order, so I'll just crank those out and then talk you through the real quick with the order, which has an ID.
And then we're gonna use the relationship to the order.user.name, Similarly for the number.
Now the order has a created date.
If we just put it like this, you'll see, this is probably not how you want to see the date.
Not super amazing.
I think Maybe just that right there would be great.
So we can come over here and simply do .date() isoformat() like this.
Here we go.
That's a nicer date, and we'll do the same for the completed date if it exists.
So we want to use this, but only if this has been fulfilled.
Otherwise, we just want to leave it empty.
But nothing if not this else will put that similarly over here.
We will say, if it's not fulfilled, will put open otherwise, If it is fulfilled, I'll just put the word fulfilled.
Here we go.
Look, it's not completed so empty, and its status is open.
The final thing is, if it's open, we want to put a button.
And here we're just going to put a hyperlink, and the hyperlink is going to go to /admin/fulfilled.
We want to pass over the order id.
So would you like this and just fulfill and let's make it pretty well, give it a class of button btn-dash success.
All right, let's see how this looks.
There we go.
Look at that also looks a little bit big.
We can make it smaller, just do one more class 'sm' like that.
I did notice when I did the copy and paste.
All these
should be for the data, so let's do a quick replace.
How are things looking perfect Looks a little better on the table formatting and are fulfilled button.
Is the right size perfect.
Well, we've got our basic table view of the data, and whether or not it's completed or not, sitting right here, let's go and add one more order just to make sure that it's going to show up in our list.
Cake me.
It's time for more cake.
I'd better be small, though.
Remember, we've had a lot.
I'm going for a rainbow, chocolate and Sprinkles.
Now, just a quick reminder.
You have to have your ngrok running and have your website running in order for this to hit our API.
Just right here.
We got our post for the order that came in.
That's how it got into our database.
Presumably, let's refresh the page and see what happened.
Oh, look at that.
We have our second order with order id 2, that came in.
And if you notice in WhatsApp it said your order ideas too.
We've accepted it.
Thank you.
Well, it looks like our admin table for finding orders and fulfilling them is all set.
Really quickly, before we wrap this up, I just noticed that we had previously had user.number here our Json exchange the user number is passed across, but our actual database over here, our user, they have a phone.
So if you notice that that wasn't showing up, that's because that should be phone.
Here we go.
All good.
show 5:52
show 2:07
45:54
show 1:00
show 1:42
show 4:09
show 4:02
show 6:03
show 6:39
show 4:22
show 4:45
show 2:33
show 1:23
show 2:00
show 3:20
show 1:17
show 2:39
14:15
show 0:31
show 2:04
show 4:03
show 1:40
show 4:13
show 1:44
11:32
show 0:34
show 0:36
show 1:36
show 1:18
show 1:39
show 1:13
show 0:36
show 1:34
show 1:39
show 0:26
show 0:21
54:50
show 4:07
show 1:35
show 2:14
show 3:10
show 8:31
show 1:51
show 6:01
show 6:26
show 5:00
show 4:24
show 7:16
show 4:15
52:56
show 2:18
show 1:36
show 1:33
show 3:36
show 2:34
show 1:20
show 5:09
show 2:22
show 5:55
show 9:03
show 9:18
show 4:03
show 0:44
show 0:49
show 1:59
show 0:37
Take this course for FREE
Talk Python's Mastodon Michael Kennedy's Mastodon