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.
0:02 When they were ordering a cake after they had gone through the whole twilio studio interaction
0:06 they had placed the order.
0:08 The orders showed up in our admin back end.
0:10 The baker saw that order, bake the cake and clicked fulfilled to let them know that
0:15 it was done. What we told them was we're going to send you a WhatsApp
0:18 message, when your cake is ready and here we go.
0:21 This is how we do it.
0:22 It's quite simple, right? We create a from and until you have a proper
0:26 account registered over at WhatsApp, we're just gonna use this number here.
0:30 This is the WhatsApp test sandbox number.
0:33 And then we're gonna use the 'to' number being the number we saved in the database
0:37 on the user associated with that order.
0:39 And remember that there's certain templates that we have to follow in this Test Dev mode
0:44 before we get them approved. So your cakes order status code is ready for pickup
0:47 is what we said. Then we just create a twilio rest client,
0:51 given the user name to be the SID and the password to be the
0:54 Auth token that we got out of Twilio studio.
0:57 Remember, we store those secretly in our secret.json and we don't let those
1:01 get into our GitHub. We just create a message.
1:04 We say the body is the message body the 'to' is 'to' and 'from' is 'from'
1:07 super straightforward. As long as no error message came back,
1:10 we're assuming things must be good.
1:12 So we check for the error message.
1:14 If there is one, we raise an exception to let everyone know otherwise,
1:17 we've now sent a WhatsApp message over to our users, Super super cool.
1:22 So this is a really nice way to communicate back to them.
1:26 Remember, outside of that 24 hour window of interaction,
1:29 the messages must confirm to a couple of template options.
1:33 And this link down here shows you where you can go and actually explore what the
1:36 few options are and learn more about how to register your own message templates over at whatsapp.