Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Sending outbound text messages
Lecture: WhatsApp API keys
Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now, in order to work with the Twilio messaging service, we're going to use the Twilio project.
0:06 No surprise there. So over on pypi.org it's just twilio We're just going to pip install twilio. And of course,
0:14 the thing that we're going to need to do to use it is to create the REST client. That's fine. But here we go. This is the part with our secrets.
0:22 We need to set the account and the token. Well, where do we get those from? Much like we did with send grid. We need a safe place to store them.
0:31 But let me show you first where to go and find yours. We go to our project and we go here and click settings and go to our
0:38 general settings. We've got an account SID. But more importantly, if you scroll down, not going to click it. But here,
0:45 behind this little section is our auth token. So this is our SID. And then here's our actual token that we're going to use.
0:54 Do you want to get your version of this token and put it somewhere safe? We already have a place for that,
1:01 right? over here, we have our secrets which are not opening and its golden because it's not stored in git.
1:10 But we have our template. And for our template, we're going to have something like we had before. Twilio, is want to put our SID and AUTH token in here
1:18 And of course, say"TODO: Set in secrets.json, Just like before. We don't get the value here.
1:29 This is just a template to help us make sure we can recreate it successfully. You go set in your secrets.json I've already just now done that.
1:38 Of course not recording. And the last thing we got to do is go load it just like we did before. So even over in our app,
1:44 we have configured secrets. A little bit more is happening. So we're already verifying that we can load up this secrets.json
1:50 and we want to go over and have not just in our secrets, not just the send grid name. We're going to have twilio _sid.
2:03 Which is going to be one of those. And twilio_key, which looks like that as well. You want to set those two things and here will say it.
2:13 twilio_keys. Then let's look at our template. What we call them 'sid' and auth_token. So there's the 'sid' and our auth_token.
2:35 Let's make sure we just run this. Everything hangs together. Yeah, it looks like we were able to read those out
2:42 just fine. Again. Don't really want to look at them because they're secret, But we'll get that all set up.
2:49 Well, when I want to go and import our app secrets, we also need to use twilio. So let's just go out and throw twilio in here
2:56 Click Install, pip install-Our requirements.txt take your pick and then we'll say from twilio.rest import client.
3:14 We'll start by saying our client here is going to be one of these clients that we create. What we can do is just set the username and the password here
3:21 and the username is going to be app_secrets.twilio_sid And the password can be app_secret.twilio_key, All right,
3:33 that's going to create our client that we're ultimately going to use to send our WhatsApp
3:37 message. Let's just make sure one more time that we can call this and this all gets set up just correctly.
3:44 So we'll go over here, go to the admin section to fulfill one more of these things. Perfect. We still haven't actually sent the message.
3:53 There's a little bit more to explore to make that happen, but it looks like we're able to create the client,
3:57 get the private security keys and so on and get that all set up and ready to go.