Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Beautiful confirmation emails
Lecture: What about plaintext?
0:00 I'm delighted with how our HTML message came out.
0:03 But remember, if your client you said I want to receive text only plain text
0:08 only well, you're going to get a much less impressive response.
0:14 Your receipt. Thanks for ordering a small cake that's not convincing.
0:19 That's not fun. So there's two things we could do.
0:21 We could actually put like some kind of markdown plain text template here and use jinja
0:28 to render it. That's one option.
0:30 But then, of course, you still have to keep them in sync.
0:32 That's tricky. What if we could just have a friendly version of text here,
0:36 like even maybe a markdown version?
0:38 That would be cool. Can we do that?
0:40 Yes, yes, we can, watch this.
0:43 We go over here, you Pypi.
0:46 There's a cool library called html2text,
0:49 and what does it do is a script that converts HTML and that clean and easy
0:54 to read text. Better yet,
0:55 that also happens to be marked down,
0:58 for example. So if you've got like a bulleted list,
1:00 it'll put Star Item 1 star,
1:02 Item 2 and so on, so that would make it a little bit easier to
1:05 read. How hard is this to use?
1:07 Well, Not hard at all.
1:09 It's over here. We want to use
1:11 html2text install that and then we go to our HTML.
1:22 We say html to text. We import this and then on there we can say
1:28 html the text. And what does it take?
1:31 It requires that we give it html, like so, that's it.
1:38 Now we've converted over to HTML.
1:40 Let's print the text and then return real quick.
1:49 We're not going to see this in my Gmail account so,
1:51 That's not gonna help. Let's send it again.
1:55 Look at this. We've got our image and I guess we could exclude the image
2:01 Exclude the links if we want,
2:03 But your cake is being processed.
2:05 How fantastic is that? Hey,
2:07 Mike Kennedy, Thank you for ordering our award winning cake.
2:11 This is your confirmation order and we've got a little emphasis in our text.
2:15 And then here's a table looking thing that we might have, so size is small, flavors
2:20 such and such and so on.
2:21 Really, really nice. I think this is pretty decent.
2:24 It's not perfect, but as a way of saying here's a pretty good guess at
2:28 what the text should look like. I think that's pretty neat.