Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Beautiful confirmation emails
Lecture: What about plaintext?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I'm delighted with how our HTML message came out. But remember, if your client you said I want to receive text only plain text
0:09 only well, you're going to get a much less impressive response. Your receipt. Thanks for ordering a small cake that's not convincing.
0:20 That's not fun. So there's two things we could do. We could actually put like some kind of markdown plain text template here and use jinja
0:29 to render it. That's one option. But then, of course, you still have to keep them in sync.
0:33 That's tricky. What if we could just have a friendly version of text here, like even maybe a markdown version? That would be cool. Can we do that?
0:41 Yes, yes, we can, watch this. We go over here, you Pypi. There's a cool library called HTML2text,
0:50 and what does it do is a script that converts HTML and that clean and easy to read text. Better yet, that also happens to be marked down,
0:59 for example. So if you've got like a bulleted list, it'll put Star Item 1 star, Item 2 and so on, so that would make it a little bit easier to
1:06 read. How hard is this to use? Well, Not hard at all. It's over here. We want to use HTML2text install that and then we go to our HTML.
1:23 We say HTML to text. We import this and then on there we can say HTML the text. And what does it take?
1:32 It requires that we give it HTML, like so, that's it. Now we've converted over to HTML. Let's print the text and then return real quick.
1:50 We're not going to see this in my Gmail account so, That's not gonna help. Let's send it again.
1:56 Look at this. We've got our image and I guess we could exclude the image Exclude the links if we want, But your cake is being processed.
2:06 How fantastic is that? Hey, Mike Kennedy, Thank you for ordering our award winning cake.
2:12 This is your confirmation order and we've got a little emphasis in our text.
2:16 And then here's a table looking thing that we might have, so size is small, flavors such and such and so on.
2:22 Really, really nice. I think this is pretty decent. It's not perfect, but as a way of saying here's a pretty good guess at
2:29 what the text should look like. I think that's pretty neat.

Talk Python's Mastodon Michael Kennedy's Mastodon