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

Talk Python's Mastodon Michael Kennedy's Mastodon