How I Built an Custom AI News Listener

Steps by step guide

1. Create a Free Account on N8N 1:13

generated-image-at-00:01:13
  • Go to the N8N website.
  • Sign up for a free account.

2. Set Up Automation Trigger 1:38

generated-image-at-00:01:38
  • Create a new automation in N8N.
  • Import a trigger note to run the automation weekly.
  • Set the trigger to execute every Friday at 6 a.m.

3. Connect to Tavaly 1:59

generated-image-at-00:01:59
  • Create a free account on Tavaly.
  • Connect Tavaly to N8N following the provided instructions.

4. Configure News Search in Tavaly 2:34

generated-image-at-00:02:34
  • In Tavaly, set up a search query for news.
  • Specify the search to find the top 10 news articles from the last week in the United States.

5. Pass Data to OpenAI Agent 3:04

generated-image-at-00:03:04
  • Use the AI agent (OpenAI) to process the news data from Tavaly.
  • Instruct the AI to classify the news articles on a scale of 1 to 10 for relevance to coaching and consulting.

User Message (Prompt) code:

{{ 
$json.results
.map((item, i) =>
`Article ${i + 1}: ${item.url || ''}\n` +
`Title: ${(item.title || '').replace(/[\n\r]+/g, ' ')}\n` +
`Content: ${(item.content || '').replace(/[\n\r]+/g, ' ').slice(0, 2000)}`
)
.join('\n\n')
}}

System Message:

You will be given 10 news from the week. Your job is to classify how interested they are to B2B Coaches and Consultants in scale of 1 to 10, and a very short paragraph with a TLDR summary.

6. Format AI Output 3:36

generated-image-at-00:03:36
  • Specify the desired output format for the AI:
    • Title of the news article
    • Embedded link to the article
    • Relevance score
    • Short summary of the article.

Structured Output Parser Code:

{
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "The title of the news article."
},
"url": {
"type": "string",
"description": "The URL of the article."
},
"score": {
"type": "number",
"minimum": 1,
"maximum": 10,
"description": "Relevance score to B2B Coaches and Consultants (1 = not relevant, 10 = highly relevant)."
},
"summary": {
"type": "string",
"description": "A short TLDR summary (1–3 sentences) of the article."
}
},
"required": ["title", "url", "score", "summary"]
}
}

7. Transform Data to HTML 4:09

Code I used:

// Find where the array is stored
let articles =
Array.isArray($json) ? $json :
Array.isArray($json.data) ? $json.data :
Array.isArray($json.output) ? $json.output :
Array.isArray($json.parsed) ? $json.parsed :
Array.isArray($json.results) ? $json.results :
[];

// Safety check
if (articles.length === 0) {
// If no array found, wrap single object as array
articles = [$json];
}

// Build HTML
let html = `
<div style="font-family: Arial, sans-serif; color: #333;">
<h2 style="color: #0073aa;">🗞 Weekly News Summary for B2B Coaches & Consultants</h2>
<p>Here’s your weekly roundup of relevant industry articles, rated by AI for relevance (1–10).</p>
<hr>
`;

for (const article of articles) {
html += `
<div style="margin-bottom: 20px;">
<h3 style="margin: 5px 0;">
<a href="${article.url || '#'}" style="color: #0073aa; text-decoration: none;">
${article.title || '(Untitled)'}
</a>
</h3>
<p><strong>Relevance Score:</strong> ${article.score ?? 'N/A'}/10</p>
<p>${article.summary || ''}</p>
</div>
<hr>
`;
}

html += `
<p style="font-size: 12px; color: #999;">This summary was auto-generated by n8n AI workflow.</p>
</div>
`;

return [{ html }];
generated-image-at-00:04:09
  • Use a piece of code to convert the AI output into HTML format.
  • Set it up to send the formatted data to your Gmail account.

8. Review Weekly Email 4:17

generated-image-at-00:04:17
  • Check your Gmail every Friday after 6 a.m. for the weekly news summary.

Writen by
Hugo Sanchez

Founder, MoonDesk Media

Hugo Sanchez is the founder of MoonDesk Media, a Digital Marketing Agency specialized in serving B2B Professional Services. Hugo has background in Management Consulting, and 5 year of experience in Digital Marketing.
Join a community of top-notch coaches who are revolutionizing their business with our newsletter.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram