Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Messaging and workflows with Twilio Studio
Lecture: Pricing the order with the order API
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
We've gathered all the information about the order from the user. We've at each step along
0:05
the way verified what they entered was something that was actually valid.
0:09
We made sure that if they asked for a frosting that it actually was a frosting
0:13
available on our menu. So now it's time.
0:16
Once we got all that information to determine the price of the cake because ultimately they
0:20
want to purchase it and we're going to charge the money.
0:23
We need to at least tell them how much it's gonna cost.
0:25
Right? Recall We had our menu,
0:29
API appear that gave us the flavors,
0:31
the toppings and the frosting. We have a similar one for given this selection to
0:37
generate the price. Over here, we've got cloudcitycakecompany.azurewebsites.net/api
0:44
But now it's price calculator and we pass a bunch of
0:49
things along on the query string.
0:50
So size, flavor, topinng and frosting And these API's are
0:56
maintained by our British Software Development Team.
0:59
So we have our make sure we use our proper spelling over there.
1:03
So what I'm gonna do is I'm gonna copy.
1:04
Not the whole URL,
1:05
but this first part up to the query string,
1:09
but not including it. And we're going to use that over in studio to take
1:13
what they've given us and determine a price.
1:15
And ask them your cake is going to cost in this case,
1:18
eight gold coins. Do you want to buy it?
1:20
Yes or no? Alright. So back over here in studio instead of this test
1:24
where we said onward, we're going to actually do some other stuff.
1:28
So we'll go over here, and what we want to do is make another http
1:32
request, and I'm going to call it PriceCake.
1:36
And it's the right thing. We're gonna go over and call our API.
1:39
So then our URL is here.
1:42
Do a get with Form URL encoded data.
1:46
and notice down here we have an Http parameters.
1:48
This is the size of flavor and so on.
1:51
So instead of trying to come,
1:53
you know, build up a complicated URL
1:55
we're just going to do it over here,
1:57
so we'll have size, and then we need to use liquid to get the size
2:01
So cake. Uh, see,
2:04
this person came from the welcome.inbound.Message.body.
2:09
Remember, this is the thing we started of with.
2:11
I didn't mean to close it for you.
2:13
Make it larger. So this will be widgets.
2:15
Welcome, inbound body. This is welcome to the cake company.
2:19
What size of cake do you want?
2:21
The next thing that we need was we had the flavour and remember spell like that
2:26
So this was askcakeflavor.inbound.body
2:34
like so? So ask cake flavor,
2:39
widgets.AskCakeFlavor.inbound.Body
2:41
That's good. You have to add another will be our frosting.
2:47
Very similar. You can imagine Frosting.inbound!
2:55
Pick that one. widgets.AskCakeFrosting.inbound.Body
2:58
And last but not least,
3:01
are topping.inbound.Body like this,
3:10
which wigets.AskCakeTopping.inbound.Body save.
3:14
Oops! Save that one multiple saves on this piecer.
3:16
let's go back and actually send one more message.
3:25
Your cake will cost PriceCake.parsed
3:32
Okay. And we're gonna have our currently gold coins.
3:40
Save that. Connect them up.
3:42
Alright, Once we publish it,
3:44
we're ready to test. So can we call that PI with the right URL
3:48
and get the right response back.
3:51
We do. They're on to the next step.
3:54
Hi. Welcome, Welcome. Let's get a small cake.
3:58
Rainbow, Rainbow will be good, I think Vanilla on the toppings,
4:05
The frosting in the topping Let's go for Sprinkles.
4:11
Almost perfect. I guess if you're a program or maybe that's perfect.
4:15
So we got the total back end, I need to pull total out of the parse
4:18
value. So we'll do a .total on this,
4:21
But you can see that we successfully took all that information Small rainbow,
4:25
vanilla Sprinkle cake. And we sent that of to the pricing calculator and we did
4:29
get 22 back. It's got to work on our formatting.
4:32
So down here, we'll just say .total, we publish and order another cake.
4:45
Rainbow. Oh, I want a small rainbow,
4:56
some vanilla with Sprinkles. Check that out.
5:03
Your cake will cost 22 gold coins.
5:06
Come on over and pick up your cake.
5:08
Well, we're not quite that far yet,
5:09
are we? But we're getting there.
5:10
We're now figure out how much the thing cost.
5:13
We can ask them like this how much it's gonna cost.
5:15
Would you like to order your cake.
5:17
Now please say yes or no and then we'll go through,
5:20
get their information. What's their name?
5:22
What's their email and so on?
5:24
And we'll start their cake baking in the bakery.