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,
0:02
we gathered up all the information.
0:04
We need to send that over to the Cloud City Cake Company and actually record the
0:08
order. Tell the Bakers here is what the user,
0:11
through chat through WhatsApp has decided they want.
0:14
Let's get that started. So in order to do that,
0:17
we decided to create an API of our own.
0:20
And we did that in Flask,
0:21
and we hosted it through in ngrok,
0:23
Remember, one of the challenges is how does Twilio Studio running up in the cloud
0:28
get all the way back into your machine, so it can call those API You can
0:32
test it. So we did that with in ngrok,
0:34
and that's what will be this cloud city.ngrok.io domain here.
0:38
And then it goes to /api/order.
0:40
And this time we decided we're making a change and we want to submit a complex
0:45
JSON body. So we made the request method post.
0:49
We changed the content type of application,
0:51
JSON. And then we just typed out the JSON document here at the end and
0:55
where the values went, we put whatever came from the various widgets and things in
1:01
the flow. We use liquid to get that back.
1:05
One thing to realize here is that puts the raw text into this field.
1:08
But in JSON, that has to be put in quotes unless it's a number or
1:12
something like that. But strings have to go in quotes,
1:15
so we have to put double quotes around both of these.
1:18
It's not super obvious, but that right there is a double quote,
1:22
just like the one at the end of the line.
1:24
The thing that's happening, I believe,
1:25
is that blue outline that highlights the fact that this is some kind of liquid template
1:31
section. It's Z order. Its position is above or in front of the part
1:36
of the double quote, so just be really careful.
1:39
There's weird things around, like spaces and quotes that kind of get obscured.
1:42
So you just have to do a little testing.
1:44
But be really careful on the lookout.
1:45
That's double quote on both ends,
1:47
even though visually, it doesn't look that way.
1:49
So this is a really great way for the studio flow to hand off control of
1:53
what happens next over to our flask application. and it was python from there on up.