Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Sending outbound text messages
Lecture: Concept: Send a message to whatsapp

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The final thing with our exchange with our user. When they were ordering a cake after they had gone through the whole twilio studio interaction
0:07 they had placed the order. The orders showed up in our admin back end.
0:11 The baker saw that order, bake the cake and clicked fulfilled to let them know that
0:16 it was done. What we told them was we're going to send you a WhatsApp message, when your cake is ready and here we go. This is how we do it.
0:23 It's quite simple, right? We create a from and until you have a proper account registered over at WhatsApp, we're just gonna use this number here.
0:31 This is the WhatsApp test sandbox number. And then we're gonna use the 'to' number being the number we saved in the database
0:38 on the user associated with that order. And remember that there's certain templates that we have to follow in this Test Dev mode
0:45 before we get them approved. So your cakes order status code is ready for pickup is what we said. Then we just create a twilio rest client,
0:52 given the user name to be the SID and the password to be the Auth token that we got out of Twilio studio.
0:58 Remember, we store those secretly in our secret.json and we don't let those get into our GitHub. We just create a message.
1:05 We say the body is the message body the 'to' is 'to' and 'from' is 'from' super straightforward. As long as no error message came back,
1:11 we're assuming things must be good. So we check for the error message. If there is one, we raise an exception to let everyone know otherwise,
1:18 we've now sent a WhatsApp message over to our users, Super super cool. So this is a really nice way to communicate back to them.
1:27 Remember, outside of that 24 hour window of interaction, the messages must confirm to a couple of template options.
1:34 And this link down here shows you where you can go and actually explore what the
1:37 few options are and learn more about how to register your own message templates over at whatsapp.


Talk Python's Mastodon Michael Kennedy's Mastodon