Advertisement
Guest User

n8n automation to filter Hacker News for topics of interests and post to Mattermost

a guest
Dec 23rd, 2024
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 6.66 KB | Source Code | 0 0
  1. {
  2.   "name": "Mattermost: Hacker News Summary",
  3.   "nodes": [
  4.     {
  5.       "parameters": {
  6.         "url": "https://hacker-news.firebaseio.com/v0/newstories.json",
  7.         "options": {}
  8.       },
  9.       "name": "Fetch Story IDs1",
  10.       "type": "n8n-nodes-base.httpRequest",
  11.       "typeVersion": 1,
  12.       "position": [
  13.         -40,
  14.         0
  15.       ],
  16.       "id": "6fd64e85-2af3-4b1a-a1af-9f3c6a991f14"
  17.     },
  18.     {
  19.       "parameters": {
  20.         "promptType": "define",
  21.         "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."
  22.       },
  23.       "type": "@n8n/n8n-nodes-langchain.chainLlm",
  24.       "typeVersion": 1.5,
  25.       "position": [
  26.         880,
  27.         0
  28.       ],
  29.       "id": "0dde1068-1bf4-4e78-84bc-f6ad5fc516c1",
  30.       "name": "Basic LLM Chain"
  31.     },
  32.     {
  33.       "parameters": {
  34.         "options": {}
  35.       },
  36.       "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
  37.       "typeVersion": 1,
  38.       "position": [
  39.         900,
  40.         180
  41.       ],
  42.       "id": "765e86a2-5bbe-490d-9f21-42b1f1670155",
  43.       "name": "OpenAI Chat Model",
  44.       "credentials": {
  45.         "openAiApi": {
  46.           "id": "xxx",
  47.           "name": "OpenAi account"
  48.         }
  49.       }
  50.     },
  51.     {
  52.       "parameters": {
  53.         "channelId": "qtdijwm48jg7bnkoh98ux5as3r",
  54.         "message": "=### New stories on Hacker news\n{{ $json.text }}",
  55.         "attachments": [],
  56.         "otherOptions": {}
  57.       },
  58.       "type": "n8n-nodes-base.mattermost",
  59.       "typeVersion": 1,
  60.       "position": [
  61.         1240,
  62.         0
  63.       ],
  64.       "id": "40927b66-65f5-4aed-9b26-27473cb9a63b",
  65.       "name": "Mattermost",
  66.       "credentials": {
  67.         "mattermostApi": {
  68.           "id": "xxx",
  69.           "name": "Mattermost account"
  70.         }
  71.       }
  72.     },
  73.     {
  74.       "parameters": {
  75.         "rule": {
  76.           "interval": [
  77.             {
  78.               "field": "hours",
  79.               "hoursInterval": 4
  80.             }
  81.           ]
  82.         }
  83.       },
  84.       "type": "n8n-nodes-base.scheduleTrigger",
  85.       "typeVersion": 1.2,
  86.       "position": [
  87.         -260,
  88.         0
  89.       ],
  90.       "id": "2ebcf1de-ed6f-439c-addd-9018ec8e1654",
  91.       "name": "Schedule Trigger"
  92.     },
  93.     {
  94.       "parameters": {
  95.         "url": "=https://hacker-news.firebaseio.com/v0/item/{{ $json[\"id\"] }}.json",
  96.         "options": {}
  97.       },
  98.       "name": "Fetch Story Details",
  99.       "type": "n8n-nodes-base.httpRequest",
  100.       "typeVersion": 1,
  101.       "position": [
  102.         420,
  103.         0
  104.       ],
  105.       "id": "38262d85-aef5-4fbc-badf-78a6b40512bb"
  106.     },
  107.     {
  108.       "parameters": {
  109.         "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"
  110.       },
  111.       "name": "Extract Titles and IDs",
  112.       "type": "n8n-nodes-base.function",
  113.       "typeVersion": 1,
  114.       "position": [
  115.         660,
  116.         0
  117.       ],
  118.       "id": "c4f1d011-105b-4f9e-9e8e-89886c956a43"
  119.     },
  120.     {
  121.       "parameters": {
  122.         "functionCode": "return items[0].json.slice(0, 50).map(id => ({ json: { id } }));"
  123.       },
  124.       "name": "Get First 50 IDs",
  125.       "type": "n8n-nodes-base.function",
  126.       "typeVersion": 1,
  127.       "position": [
  128.         180,
  129.         0
  130.       ],
  131.       "id": "1e725532-f13b-4964-99e9-494722b8091b"
  132.     }
  133.   ],
  134.   "pinData": {
  135.     "Schedule Trigger": [
  136.       {
  137.         "json": {
  138.           "timestamp": "2024-12-23T08:00:55.024-05:00",
  139.           "Readable date": "December 23rd 2024, 8:00:55 am",
  140.           "Readable time": "8:00:55 am",
  141.           "Day of week": "Monday",
  142.           "Year": "2024",
  143.           "Month": "December",
  144.           "Day of month": "23",
  145.           "Hour": "08",
  146.           "Minute": "00",
  147.           "Second": "55",
  148.           "Timezone": "America/New_York (UTC-05:00)"
  149.         }
  150.       }
  151.     ]
  152.   },
  153.   "connections": {
  154.     "Fetch Story IDs1": {
  155.       "main": [
  156.         [
  157.           {
  158.             "node": "Get First 50 IDs",
  159.             "type": "main",
  160.             "index": 0
  161.           }
  162.         ]
  163.       ]
  164.     },
  165.     "OpenAI Chat Model": {
  166.       "ai_languageModel": [
  167.         [
  168.           {
  169.             "node": "Basic LLM Chain",
  170.             "type": "ai_languageModel",
  171.             "index": 0
  172.           }
  173.         ]
  174.       ]
  175.     },
  176.     "Basic LLM Chain": {
  177.       "main": [
  178.         [
  179.           {
  180.             "node": "Mattermost",
  181.             "type": "main",
  182.             "index": 0
  183.           }
  184.         ]
  185.       ]
  186.     },
  187.     "Schedule Trigger": {
  188.       "main": [
  189.         [
  190.           {
  191.             "node": "Fetch Story IDs1",
  192.             "type": "main",
  193.             "index": 0
  194.           }
  195.         ]
  196.       ]
  197.     },
  198.     "Fetch Story Details": {
  199.       "main": [
  200.         [
  201.           {
  202.             "node": "Extract Titles and IDs",
  203.             "type": "main",
  204.             "index": 0
  205.           }
  206.         ]
  207.       ]
  208.     },
  209.     "Extract Titles and IDs": {
  210.       "main": [
  211.         [
  212.           {
  213.             "node": "Basic LLM Chain",
  214.             "type": "main",
  215.             "index": 0
  216.           }
  217.         ]
  218.       ]
  219.     },
  220.     "Get First 50 IDs": {
  221.       "main": [
  222.         [
  223.           {
  224.             "node": "Fetch Story Details",
  225.             "type": "main",
  226.             "index": 0
  227.           }
  228.         ]
  229.       ]
  230.     }
  231.   },
  232.   "active": true,
  233.   "settings": {
  234.     "executionOrder": "v1"
  235.   },
  236.   "versionId": "07c6eb56-dc61-4689-afd3-1e5f7b25c58d",
  237.   "meta": {
  238.     "instanceId": "bd88de33a2cb3472b737c34c86d3ec9582c092e4b445fb3bcfe8b84c34230e84"
  239.   },
  240.   "id": "62u7iyYyR4PGt1o5",
  241.   "tags": []
  242. }
Tags: n8n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement