Skip to content

Instantly share code, notes, and snippets.

@cypris75
Created December 23, 2024 17:23
Show Gist options
  • Save cypris75/462aa421d9f41e0ba4dd072d1aa5dc3a to your computer and use it in GitHub Desktop.
Save cypris75/462aa421d9f41e0ba4dd072d1aa5dc3a to your computer and use it in GitHub Desktop.
n8n automation to summarize Hacker News and send summary to Mattermost
{
"name": "Mattermost: Hacker News Summary",
"nodes": [
{
"parameters": {
"url": "https://hacker-news.firebaseio.com/v0/newstories.json",
"options": {}
},
"name": "Fetch Story IDs1",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
-40,
0
],
"id": "6fd64e85-2af3-4b1a-a1af-9f3c6a991f14"
},
{
"parameters": {
"promptType": "define",
"text": "=Filter the following Hacker News articles to show those related to the following topics:\n\n LIST YOUR INTERESTS HERE\n\nUse this as a filter to identify articles that align closely with these focus areas, prioritizing those that dive deep into specific case studies, tools, or techniques.\n\nHere ist the list of articles in JSON format:\n\n```\n{{ JSON.stringify($json.titles) }}\n```\n\nPlease list the relevant answers in Markdown in the following format (example):\n\n1. [Cramming Scrapscript into Msgpack](https://taylor.town/flat-scraps-000) | [Comments](https://news.ycombinator.com/item?id=42493896)\n2. [Perl+OpenMP Saved Christmas](https://perladvent.org/2024/2024-12-21.html) | [Comments](https://news.ycombinator.com/item?id=42485795)\n3. [Building Effective AI Agents Cookbook](https://github.com/anthropics/anthropic-cookbook/tree/main/patterns/agents) | [Comments](https://news.ycombinator.com/item?id=42487775)\n...\n\nThe \"Comments\" link uses the id which can be found in the JSON result. \n\nThe format to build this link is https://news.ycombinator.com/item?id={id}\n\nOnly list the relevant articles. Do not add any (sub)headlines. Just the list of relevant articles."
},
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"typeVersion": 1.5,
"position": [
880,
0
],
"id": "0dde1068-1bf4-4e78-84bc-f6ad5fc516c1",
"name": "Basic LLM Chain"
},
{
"parameters": {
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1,
"position": [
900,
180
],
"id": "765e86a2-5bbe-490d-9f21-42b1f1670155",
"name": "OpenAI Chat Model",
"credentials": {
"openAiApi": {
"id": "xxx",
"name": "OpenAi account"
}
}
},
{
"parameters": {
"channelId": "qtdijwm48jg7bnkoh98ux5as3r",
"message": "=### New stories on Hacker news\n{{ $json.text }}",
"attachments": [],
"otherOptions": {}
},
"type": "n8n-nodes-base.mattermost",
"typeVersion": 1,
"position": [
1240,
0
],
"id": "40927b66-65f5-4aed-9b26-27473cb9a63b",
"name": "Mattermost",
"credentials": {
"mattermostApi": {
"id": "xxx",
"name": "Mattermost account"
}
}
},
{
"parameters": {
"rule": {
"interval": [
{
"field": "hours",
"hoursInterval": 4
}
]
}
},
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
-260,
0
],
"id": "2ebcf1de-ed6f-439c-addd-9018ec8e1654",
"name": "Schedule Trigger"
},
{
"parameters": {
"url": "=https://hacker-news.firebaseio.com/v0/item/{{ $json[\"id\"] }}.json",
"options": {}
},
"name": "Fetch Story Details",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
420,
0
],
"id": "38262d85-aef5-4fbc-badf-78a6b40512bb"
},
{
"parameters": {
"functionCode": "const titles = items.map((item) => ({\n title: item.json.title,\n id: item.json.id,\n url: item.json.url,\n}));\nreturn [{ json: { titles } }];\n"
},
"name": "Extract Titles and IDs",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
660,
0
],
"id": "c4f1d011-105b-4f9e-9e8e-89886c956a43"
},
{
"parameters": {
"functionCode": "return items[0].json.slice(0, 50).map(id => ({ json: { id } }));"
},
"name": "Get First 50 IDs",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
180,
0
],
"id": "1e725532-f13b-4964-99e9-494722b8091b"
}
],
"pinData": {
"Schedule Trigger": [
{
"json": {
"timestamp": "2024-12-23T08:00:55.024-05:00",
"Readable date": "December 23rd 2024, 8:00:55 am",
"Readable time": "8:00:55 am",
"Day of week": "Monday",
"Year": "2024",
"Month": "December",
"Day of month": "23",
"Hour": "08",
"Minute": "00",
"Second": "55",
"Timezone": "America/New_York (UTC-05:00)"
}
}
]
},
"connections": {
"Fetch Story IDs1": {
"main": [
[
{
"node": "Get First 50 IDs",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Basic LLM Chain": {
"main": [
[
{
"node": "Mattermost",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Fetch Story IDs1",
"type": "main",
"index": 0
}
]
]
},
"Fetch Story Details": {
"main": [
[
{
"node": "Extract Titles and IDs",
"type": "main",
"index": 0
}
]
]
},
"Extract Titles and IDs": {
"main": [
[
{
"node": "Basic LLM Chain",
"type": "main",
"index": 0
}
]
]
},
"Get First 50 IDs": {
"main": [
[
{
"node": "Fetch Story Details",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1"
},
"versionId": "07c6eb56-dc61-4689-afd3-1e5f7b25c58d",
"meta": {
"instanceId": "bd88de33a2cb3472b737c34c86d3ec9582c092e4b445fb3bcfe8b84c34230e84"
},
"id": "62u7iyYyR4PGt1o5",
"tags": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment