Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Creating the Flask Python web app
Lecture: Concept: Calling an API in studio parameters
Login or purchase this course to watch this video and the rest of the course contents.
0:00 At the very end of our studio flow, we gathered up all the information.
0:05 We need to send that over to the Cloud City Cake Company and actually record the order. Tell the Bakers here is what the user,
0:12 through chat through WhatsApp has decided they want. Let's get that started. So in order to do that, we decided to create an API of our own.
0:21 And we did that in Flask, and we hosted it through in ngrok, Remember, one of the challenges is how does Twilio Studio running up in the cloud
0:29 get all the way back into your machine, so it can call those API You can test it. So we did that with in ngrok,
0:35 and that's what will be this cloud city.ngrok.io domain here. And then it goes to /api/order.
0:41 And this time we decided we're making a change and we want to submit a complex JSON body. So we made the request method post.
0:50 We changed the content type of application, JSON. And then we just typed out the JSON document here at the end and
0:56 where the values went, we put whatever came from the various widgets and things in the flow. We use liquid to get that back.
1:06 One thing to realize here is that puts the raw text into this field. But in JSON, that has to be put in quotes unless it's a number or
1:13 something like that. But strings have to go in quotes, so we have to put double quotes around both of these.
1:19 It's not super obvious, but that right there is a double quote, just like the one at the end of the line. The thing that's happening, I believe,
1:26 is that blue outline that highlights the fact that this is some kind of liquid template
1:32 section. It's Z order. Its position is above or in front of the part of the double quote, so just be really careful.
1:40 There's weird things around, like spaces and quotes that kind of get obscured. So you just have to do a little testing.
1:45 But be really careful on the lookout. That's double quote on both ends, even though visually, it doesn't look that way.
1:50 So this is a really great way for the studio flow to hand off control of
1:54 what happens next over to our flask application. and it was Python from there on up.