---
title: "Generate Newsletter Draft"
video_id: 1xRgbAZ6yKk
url: https://www.youtube.com/watch?v=1xRgbAZ6yKk
workflow_page: https://workflows-of-ai.com/workflow/generate-newsletter-draft
language: en
captions: generated
---

0:01 This episode is sponsored by Freely
0:04 Give. If you need help with Drupal AI,
0:06 get in contact with us.
0:09 Hey everyone. So today we're going to
0:10 showcase a super simple uh workflow.
0:13 It's just going to create a newsletter
0:15 preview. So something that's human in
0:18 the loop based on in this case our
0:21 fictional website Laponia that is laptop
0:23 reviews. And it's going to create a
0:26 newsletter for the last week's reviews.
0:29 In this case, it's going to be three
0:30 reviews uh that got manually added into
0:34 triple CMS.
0:36 The reason I'm showcasing this is not
0:38 because this is something
0:40 groundbreaking. I want to show something
0:42 that's called the views automator that
0:44 you can find in AI module 1.2. And this
0:48 is super powerful, not because of Drupal
0:51 AI module, not because of AI, but
0:53 because of Drupal and views. because
0:56 this is such a powerful content listing
0:58 module and it has two things that are
1:02 almost unique I think compared to a lot
1:05 of other systems. So, one thing is that
1:07 it allows you to create filters or
1:11 arguments that are dynamic that the AI
1:14 can use, which in this case we're
1:17 showing a workflow, but if you have a
1:18 gentic AI uh later, this is crazy
1:22 powerful because it actually lets the
1:25 agent decide what it wants to look at.
1:29 uh and it does it in a safe way where
1:32 you can set it up in the UI. So you're
1:35 not dependent on someone writing like
1:37 filters in code. You're not dependent on
1:40 something even worse like uh uh you know
1:43 writing SQL queries or letting the AI
1:46 choose the SQL queries. Uh and the other
1:49 thing that's also super important, you
1:51 can choose exactly the amount of context
1:54 that the AI should see. And you can also
1:56 set this up in UI. This means that for
2:00 AI where you might not actually be
2:03 certain if you know if you show a whole
2:06 article is it actually going to handle
2:08 this or do I need to create a summary?
2:10 Do I need to maybe show just uh 75% of
2:14 it? Uh how do I show the title? How do I
2:18 show a link? You might need to
2:20 experiment with this back and forth
2:21 until you have the correct uh uh actual
2:24 output. And because of use this makes
2:27 this iteration super fast. So that is
2:30 the reason I want to showcase this
2:32 workflow. So happy viewing. So today's
2:35 tutorial will be actually very easy.
2:38 It's it's just a simple automator that
2:40 creates like a preview newsletter based
2:42 on your latest published content. So you
2:46 don't have to start writing yourself. It
2:49 it basically simplifies a copy and paste
2:52 example. But there it also showcases
2:55 something that's extremely powerful
2:57 which is the views automator. So what
3:01 what I have here
3:04 is uh Drupal CMS 2.0. So it's still in
3:07 development but I thought it would be
3:09 fun to play around with it because it's
3:11 going to be released probably uh start
3:13 of next year. Uh where I have added I've
3:17 just based it on the basic page. So, in
3:20 this case, we're the fictional uh laptop
3:22 review company or laptop review web page
3:25 Laponia
3:27 that creates uh laptop reviews like
3:29 this. And I'm just using the basic page
3:31 for it. So, it's just laptop reviews
3:35 uh uh with a image, a title, a
3:38 description, and also some tags. And the
3:41 tag laptop in this case is important.
3:44 It's important to know the ID of it,
3:45 which is 17. And I'm going to showcase
3:47 why. Because
3:49 what we want to do when the newsletter
3:51 gets created is that we want to look at
3:54 exactly the last week weeks laptops,
3:57 right? So I have created a view now then
4:01 that can showcase this. Uh it's very
4:04 simple. It's just a title with H1 and a
4:06 link. It's the featured image using a
4:09 specific image style I want to use in
4:11 the newsletter.
4:12 And it's the full content that the AI
4:15 can look at. What's important then it's
4:17 also we just want to show case published
4:20 once of course uh of the content type
4:24 basic page and we want to show the last
4:26 week but what's also important here we
4:29 have added and this is just to showcase
4:31 I could have hardcoded as a filter
4:33 criteria or I could create the exposed
4:35 filter criteria to do the same thing
4:38 that I'm showing here but I put it in
4:40 contextual filter so if you scroll down
4:42 to the preview we don't see anything
4:44 until we set which is laptop. So we
4:47 we're filtering just on laptops because
4:50 there is actually a terms of service
4:52 that was published last week as well and
4:54 we of course don't want that to be part
4:56 of the context of the newsletter we
4:58 create.
5:00 So that is and that is no so there's one
5:03 more thing I've done. I've run the AI
5:06 recipe as well which means that I have
5:08 to put put in in this case open AI key.
5:10 So you can see I have the assistant here
5:13 um uh usable because I have installed
5:16 the recipe but in this case
5:19 we're going to use the automators for
5:21 this. So this is not a agent task. This
5:24 is something that's definitely
5:25 automation.
5:27 And I I will also say I'm going to
5:29 create a newsletter preview
5:31 meaning that you can use something like
5:33 simple news in in Drupal if you want but
5:35 you can also use uh uh something
5:38 external I don't know mandril or
5:40 whatever newsletter service you have
5:42 just to create pre-create uh HTML that
5:45 is uh based on AI it's I have a very
5:49 weak prompt now you would have to create
5:51 a very good prompt to create something
5:53 that is like 95% useful where you just
5:57 have to scan through it and maybe change
5:59 something. Uh but that's the idea. You
6:01 create something that's for human in the
6:03 loop. It's not completely automated.
6:05 That would be possible as well if you
6:08 can generate something that's is on the
6:10 quality level that you would want it. Uh
6:14 after I've done this, I Oh, I want to go
6:17 to content types. That's what I want to
6:18 go to and create a new content type. Uh
6:21 we call it newsletter preview.
6:26 uh disable previewing in this case. Uh
6:31 and we're just going to start recreating
6:33 a plain text long. And this is what this
6:36 is going to do. It's going to look at
6:38 that view and just dump that information
6:41 into this uh
6:44 text plane view. And this at first
6:48 glance this might make no sense at all.
6:51 You might wonder why um why do you need
6:54 to do this? can't you create the
6:56 automator or something there there's
6:58 like the views preview field you could
7:00 use I think to look at it but the thing
7:03 is the the good thing I think with
7:06 automators is that when you actually
7:09 store every step it does it creates
7:11 auditability so you if if the end result
7:14 is weird you might go and look at like
7:17 what was it actually looking at at that
7:19 time to understand what went wrong
7:23 uh uh so we can just call this views
7:25 dump or whatever you know this is just
7:27 going to dump the view as it is but
7:29 we're going to do some uh changes to it
7:32 so we're going to take enable AI
7:33 automator type there's a views text this
7:36 is the one that we're going to use and
7:39 we're going to use then uh the laptop uh
7:44 latest laptops laptop
7:48 uh yeah this this is in 2.0 we probably
7:53 AI 2.0 Z, we probably will have a flag.
7:56 So, we can actually remove this because
7:58 in this case, base mode and base field
8:01 actually makes no sense. There's nothing
8:03 it can do there. Uh, I'm going to set 99
8:08 and batch because so this is the weight
8:10 of when it's running. We need one that
8:13 actually writes the newsletter that's
8:15 going to have 100. Batch means that
8:16 we're going to do it in JavaScript.
8:19 In theory if you if you want this
8:21 automated you can use ECA to trigger
8:24 this and then you can use direct for
8:25 instance uh we can use this also convert
8:28 HTML to markdown it's just so it creates
8:31 less token so it's going to look at this
8:33 HTML and it not using AI but in a
8:37 dependent manner create markdown from it
8:40 we're going to save this so there is a
8:42 bug here so where I have to save before
8:45 I see the Ajax I saw uh so After you
8:49 save, you get the argument expose
8:51 filter. I'm going to create a a
8:54 follow-up issue for this. Um, and in
8:57 this case, we're going to say that the
8:59 argument of the field tags target ID,
9:02 which maps to the first argument there,
9:04 it's going to be 17. So, the laptop ID,
9:07 right? So, this is a way where you can
9:09 actually
9:11 uh create a view that's reusable. But
9:14 not just this. This um also uses tokens
9:19 from the entity which means you can have
9:20 a automator that runs before this and
9:24 this can be based on actual uh um it can
9:27 be based on dynamical things. So it t
9:30 it's taking decisions on how you're
9:32 going to render the view. Right? So we
9:35 save this and then the next step is
9:38 create a formatted text formatted long
9:41 that is uh newsletter preview. So this
9:44 is the actual newsletter preview we want
9:46 to show.
9:48 Uh this should be of allowed text format
9:51 email but this we need to set on the
9:53 automator as well. So lm text simple.
9:56 Uh and in this case we take the base
9:58 mode to look at the view stump. So that
10:01 is what we're going to use as context.
10:03 I'm not going to sit here and write a
10:04 long prompt. And this is still a weak
10:06 prompt, right? Uh
10:08 [snorts and clears throat] and we're
10:09 working on getting context control
10:11 center in everywhere. So if you have a
10:14 context from context control center that
10:16 you know has your writing guide, you
10:18 should probably use that here also. How
10:20 do we write newsletters maybe? Uh but
10:23 the the most important thing is this
10:25 then the latest review laptops and that
10:28 you use raw context. Raw context make
10:30 sure that the HTML stays in there. Uh
10:33 because HTML matters in this case we
10:35 want the actual image links. We uh we
10:38 want the actual
10:40 uh um
10:42 links to the content as well, right?
10:45 We're going to extract the HTML. We're
10:47 going to use batch and 100 meaning this
10:48 runs after we have fetched the views
10:50 which is important. And we're going to
10:52 force the text format email.
10:55 Going to save this. Uh we can take in
10:58 manage displays
11:00 that we don't really want to show the
11:02 view stump.
11:05 Uh, I like to keep the forms in the
11:07 manage form display so we can actually
11:09 see how it worked after.
11:12 And this should basically be it. So if
11:15 we add a content newsletter preview, we
11:18 can just call this 21st 11 2025. And
11:22 these two should really be automatically
11:25 generated.
11:27 So what's happening now? It's going to
11:29 this views. It's adding the attribute
11:32 that we want to add.
11:35 um dumping this into the first field and
11:39 then there's a AI process that looks at
11:41 the first field which is the latest
11:43 laptops and writes a newsletter from
11:46 this into a HTML field
11:49 um that has the filter format email and
11:52 where we have said in the prompt that
11:53 you should use typical HTML that is
11:56 allowed in in the in a email which is
11:59 not the same as everywhere else. So here
12:01 you go. Looking for an X laptop
12:03 companion blah blah blah. It showcases
12:05 this creates uh um creates links
12:11 and as I said right now I I just used
12:14 something very weak and you can try to
12:16 create uh something more complex and you
12:20 can see it has used very you know it's
12:23 using inline styles it's using absolute
12:26 links to make sure that it works in a
12:29 newsletter.
12:30 Um yeah, so that is the end product.
12:34 It's this example might not help that
12:38 extremely much. I mean you can copy and
12:40 paste to chat GPT every week if you want
12:42 to write it. It just saves you maybe 5
12:45 minutes at tops. Uh but I wanted to show
12:48 the views automators because there are
12:50 so many use cases you can use this for.
12:54 Thank you for watching.
