Python-powered Chat Apps with Twilio and SendGrid Course

6.2 hours, 100% free
Take this course for FREE

Course Summary

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 just wanted to tell you that I'm enjoying the Python for Absolute Beginners course. This is the first time I find a course that I truly like and understand. I loved the visualizing part with PythonTutor you included. That's definitely a game changer for me and is the type of add on examples I look for in courses.
-- Luis

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

Welcome to the course
7:05
Course introduction
2:01
What will we build?
3:01
Topics covered
1:22
Student prerequisites
0:41
Setup and following along
6:02
Do you have Python 3?
2:10
A Python code editor
1:41
Database visualization tools
1:17
Git the code!
0:54
Messaging and workflows with Twilio Studio
59:31
Welcome to Twilio Studio
1:33
App walkthrough
4:43
Twilio dashboard
3:19
Intro to Twilio Studio
2:13
Receiving and sending our first message
3:20
Choosing the cake size
4:26
Liquid templating language
2:14
Using Liquid in the flow
2:15
Integrating external APIs
8:03
Concept: Messaging workflow at twilio
1:41
Asking for the cake flavor
4:02
The rest of the order details
4:56
Restarting running workflows
3:01
Pricing the order with the order API
5:28
Concept: calling an api in studio basic
1:28
Confirm the price of the cake
4:07
Gather personal info (name, email, etc)
2:42
Creating the Flask Python web app
44:43
Flask time
0:41
Create the Flask app
6:02
Structuring the app for growth
6:21
Adding the static web design
3:05
Building the API order endpoint
3:20
Concept: Creating an HTTP JSON API
2:39
Posting the order to the API via Studio
3:23
Concept: Calling an API in studio parameters
1:59
Allowing external systems to call our dev API with NGrok
4:34
Call the order API from WhatsApp
3:33
Modeling the posted data with Pydantic
7:32
A little more Pydantic validation
1:34
Using our database with the SQLAlchemy ORM
53:45
Database introduction
1:06
Need to learn SQLAchemy? See the appendix
0:57
Defining the ORM order
3:13
Defining the ORM user
1:31
Turning the classes into SQLAlchemy models
6:00
Concept: SQLAlchemy model class
2:03
SQLAlchemy session and unit of work pattern
3:27
Connecting to the database
5:00
Relationships between orders and users
4:51
Saving an order to the database
9:11
Concept: Inserting data with SQLAlchemy
2:39
Testing the API
2:39
Returning order details
3:30
Calling the order API in Studio flow
1:30
Placing the order in WhatsApp
2:30
Error handling in the API
3:38
Creating the admin backend for Flask
23:25
Intro to admin backend
0:42
Remember the admin section?
2:56
The admin index view method
5:35
The admin index HTML template
6:13
Fulfilling a cake order in the admin backend
5:52
Concept: Fulfilling an order
2:07
Beautiful confirmation emails
45:54
Introducing SendGrid
1:00
Intro to SendGrid
1:42
Email service layer
4:09
Storing secrets, secretly
4:02
Loading the secrets
6:03
Send the first email: Basic version
6:39
Generating proper HTML content
4:22
Stylized, beautiful HTML emails
4:45
What about plaintext?
2:33
Concept: Sending an email with SendGrid
1:23
Generate the invoice HTML
2:00
HTML to PDF file
3:20
Concept: Jinja to HTML email content
1:17
Attaching the PDF to the email with SendGrid
2:39
Sending outbound text messages
14:15
Time for outbound messages
0:31
The final notification: Your cake is ready
2:04
WhatsApp API keys
4:03
The messages we can send, and the ones we can't
1:40
Sending the cake ready message with Twilio
4:13
Concept: Send a message to whatsapp
1:44
Course conclusion and review
11:32
You've done it!
0:34
Review: Twilio Studio
0:36
Review: Creating a Flask API
1:36
Review: Calling an API in Studio
1:18
Review: SQLAlchemy model class
1:39
Review: Inserting data with SQLAlchemy
1:13
Review: Admin backend - fulfilling an order
0:36
Review: Sending an email with SendGrid
1:34
Review: Send a message to WhatsApp
1:39
Review: Want to keep going?
0:26
Time to say goodbye
0:21
Appendix: Modeling data with SQLAlchemy classes
54:50
Introducing SQLAlchemy
4:07
Who uses SQLAlchemy?
1:35
Architecture
2:14
The database model
3:10
Modeling packages
8:31
SQLAlchemy model base class
1:51
Connecting to our 'database'
6:01
Creating tables
6:26
Indexes
5:00
The rest of the tables
4:24
Relationships
7:16
Concepts: Modeling
4:15
Appendix: Using SQLAlchemy
52:56
Creating the basic insert script
2:18
Connecting to the database (again)
1:36
Setting package values
1:33
Saving the package to the db
3:36
Running the inserts
2:34
Adding type hints to the session factory
1:20
Inserting real PyPI data
5:09
Concept: Unit of work
2:22
Querying data: Home page
5:55
Querying data: Latest releases
9:03
Working with package details
9:18
Concept: Querying data
4:03
Concept: Ordering data
0:44
Concept: Database updates
0:49
Concept: Relationships
1:59
Concept: Inserting data
0:37
Take this course for FREE
Talk Python's Mastodon Michael Kennedy's Mastodon