Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Messaging and workflows with Twilio Studio
Lecture: Choosing the cake size

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We had our simple echo message here that just when we got a message to trigger the workflow, we said, Hey,
0:06 thanks for your cake interest, but it's time to start building something more interesting and
0:11 more useful. What we want to do is we're going to go out and get rid of this, because we want to do a send and wait for a reply.
0:20 Down here, we'll add our send and wait for reply, because what we're going to do, you wanna say, Welcome. Welcome to the cake company.
0:26 We would love to get you some cake, but we need to know a couple of things first. What size cake do you want? So let's go over here. And first of all,
0:34 give us a good name. Call it welcome. Remember, you have to use these names in programming. These are like variable names, basically so descriptive,
0:42 but not to the enormous gonna wire up the inbound message to it again. So when a message comes in, it's going to do whatever this does.
0:50 It's going to say, we'll say greetings from Cloud City Cake company. What size of cake would you like? Now we're gonna give them some options,
0:59 and they're supposed to respond with at least one of these. And if not, we'll tell them Well, that's not a good choice. You got to pick one of these,
1:05 so we have a small, medium and large. So this is the message that we're going to send over. And if a reply comes in,
1:15 what we want to do is we want to test it. Remember, they're going to say we have small, medium or large. They're supposed to,
1:21 anyway, and what we need to do is check. Do we actually have a response from them? That makes sense. If yes, we'll carry on.
1:29 If no, there's sorry that's not the right size or type of cake. And ask the question again. So we're going to do that with a split based
1:38 on an if statement like things. So, if we get a reply when I come over here and say check size
1:46 in order to check the size, we have to give it a variable. Wait a minute, variables what you type here, maybe a type of welcome, and sure enough,
1:55 as you start to type here, you'll see you get things that are useful. So we could type Welcome. We want inbound .Body,
2:05 but that's a variable we're going to test. And then we need to come over here and add a condition, if the value it
2:12 gets equal to. But it's going to be better is it matches any of, now for multiple values. We just separate with a comma(,),
2:19 so we'll say small, medium, large. I'm not sure about the space here, so let's do it like this.
2:26 A small, medium, large and now it's saved and let's just send, great that works or we're going to send them back around. So send a message like this.
2:39 If there's a match of one of those sizes, let's for now. Just go over here and say Great,
2:45 that's a good size. We'll fix the name in a minute as we change this meeting of this little control here. If it doesn't match, however,
2:55 though, let's send them another message. And here I will say wrong size. So we'll say Sorry, that wasn't a valid choice, like that.
3:13 Way back to the top. Here we say, Welcome again. So comes in. Welcome. What size? What kind of cake would you like?
3:20 We have these three sizes. We check their answer. If it's the right size great, that's a good size. For now, go ahead and follow my convention.
3:30 I'm going to say this is a temp because we're not really do anything with it yet. But we might have the wrong size,
3:36 in which case we say wrong size and we ask again. So we'll just go in this loop until they say small,
3:40 medium or large. Let's go ahead and publish it so that we can try this out. It's published after Whatapp we go,
3:47 I say, cake time! Greetings from Cloud City Cake Company. What size of cake would you like? We have small, medium and large. I want huge cake. Sorry,
3:58 that wasn't a valid choice from the cake company. What size would you like? We could also say that wasn't valid choice.
4:04 Please choose small, medium, large and just loop them back to ascend and wait for reply. But I think this is okay.
4:10 Let's try Small. Great Small is a good size. It was small, medium or large.
4:17 Fantastic. We've got this little bit of interactive exchange this back and forth in this validation, all happening over in twilio studio in our flow.


Talk Python's Mastodon Michael Kennedy's Mastodon