Quote

1. goal

Define and describe the step-by-step process of creating and configuring automation that views the news feed 24/7, reads content, and posts to a Telegram group.

2. Scope of application

This solution is suitable for media companies, marketers and bloggers who want to automate the process of curating news, increase audience engagement and respond quickly to events.

3. Tools

The platform is used n8n (https://n8n.io).

4. Customization process

Add a node RSS Feed Trigger:

  • Click on the plus icon in the upper right corner
  • In the search, we find and choose RSS Feed Trigger.
  • In the parameters, enter a link to the RSS feed of a news portal (for example, IGN):
    FeedURL: https://feeds.ign.com/ign/all
  • Set up Poll Times so that the node checks new records every minute.

If (Filtering by Publication Date)

Find and add a node If to filter records:

  • Check that the post time ($JSON.isodate) is newer than the current time minus 24 hours.

Use the following expressions:

  • Left side: = {{new Date ($Json.isodate) .getTime ()}}
  • Right side: = {{new Date () .getTime () - 24 * 60 * 60 * 1000}}
  • Operator: greater than.

HTTP Request (Getting article content)

Add a node HTTP Request:

  • Choose the GET method
  • Enter {{$json.link}} in the URL to get the link from the previous block.
  • To transfer data to json.link or any other data in the further automation process, we recommend simply dragging blocks in mode Schema

Find the link block and hold the mouse on it by dragging it to the field you need and be sure to select the “Expression” filling option

  • We don't touch the rest

HTML (Content Extraction)

Add a node HTML:

  • Please select Extract HTML Content.

In the block itself:

  • Source Data - select JSON
  • IN JSON Property write data to process data correctly
  • IN Key we also specify data
  • Specify selectors for extracting the main content (article, div [class*="content "], p).
  • So that the answer comes back to you in text form in Return Value select Text
  • Check the option ReturnArrayso that the result is in the form of an array.

AI Agent (Text Cleanup)

Add a node AI Agent:

  • Select agent type - Tools Agent
  • IN Source for Prompt select Define Below to make the right prompt
  • Then set the prompt in text:
    Clean the text from garbage, correct grammar and complete the last sentences {{$json.data}} correctly and do not mention that you removed the links.

Next, you need to click on the plus button under Chat Model to add an AI assistant that will perform the task itself

Choose the OpenAI language model

Connect your OpenAI credentials first

How to do this - check out our instructions here here.

Then select the gtp-4o-mini model

OpenAI (Article summarization)

Add a block OpenAI - message an assistant:

  • Let's go and create an assistant on the OpenAI website, you can see how to do this here here.
  • Choose an assistant created by OpenAI
  • In Source for Prompt, choose Define below.
  • The input text is the result of the previous node (= {{$json.output}}).

OpenAI (Creating a post for Telegram)

Add a node OpenAI, that will create a post for Telegram

  • Create a new OpenAI assistant following the instructions mentioned above, and give it a prompt like: “Generate a telegram post based on the received text” and make sure that the post is no longer than 700 characters, otherwise it will not pass due to the size limit.
  • When creating an OpenAI block, choose text an assistant
  • Choose your created assistant
  • And now give him the summarized text {{$json.output}}

OpenAI (Creating a Prompt for an Image)

Add a node OpenAI, which will create a text prompt to generate an image.

  • Create a new OpenAI assistant again according to the instructions mentioned above, and give it a prompt like: “Generate a prompt for the image based on the received text.”
  • When creating an OpenAI block, choose text an assistant
  • Choose your created assistant
  • And now, just like in the last step, give him the text from the assistant block to summarize the article.

OpenAI (Image Generation)

Add a node OpenAI (Generate Image).

  • Resource: Image
  • Model: DALL-E 3
  • In the prompt section, transfer the generated prompt from the previous step: {{$json.output}}

Then comes the branching

Here, create a Telegram send photo message block and a merge block, to which you will connect the output data from the previous OpenAI block (generate image)

Telegram (Sending a post for evaluation)

Add a node Telegram (SendPhoto).

  • First you need to find your chat ID:

create a Telegram trigger block (on message)

And connect your credentials to it, namely the Telegram bot api key that you get when you create a bot in https://t.me/BotFather

Once connected, click Test node and send any message.

After the trigger is triggered, you will receive your chat ID and the Telegram trigger block can be removed.

Then reconnect your credentials to the right bot and fill in the Telegram block:

  • ChatID: Telegram chat ID.
  • Turn on the slider Binary file
  • Input Binary field: data
  • IN Additional Fields press Add Field and choose Caption
  • Caption: text from OpenAI (Creating a post for telegram) + confirmation buttons.
  • An example of buttons:
    <a href="{{ $execution.resumeUrl }}?answer=no">Please tap <a href="{{ $execution.resumeUrl }}?answer=go">Go</a> or No.</a>
  • Parse Mode: HTML.

Wait (Waiting for user response)

  • Add a node Wait.
  • Resume: On Webhook Call
  • HTTP Method select GET
  • Respond: Immediately.

If (User Response Verification)

  • Add a node If.
  • In the condition, check that {{$json.query.answer}} is go.

This is what the first branch should look like for you:

Now let's move on to the final stage

Merge (Data Merge)

  • Add a node Merge (CombineAll) to combine data.

Telegram (Final message sending)

  • Add after Merge one more block Telegram (SendPhoto) for the final post submission.

The result

This process allows you to automate the processing of RSS feeds, content filtering, summarization, image generation and the publication of posts on Telegram with the ability to be confirmed by the user.

Читайте также