I have done something similar using files to track sitemap changes - but it really gets very verbose (see below). I think this needs a dedicated node, @jan. Comparing previous and current execution is just a too common problem.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
270,
280
]
},
{
"parameters": {
"functionCode": "const urls_new = items[0].json.urls;\nconst urls_old = items[1].json.urls;\nconst difference = urls_new.filter(x => !urls_old.includes(x));\n\nreturn [{ json: {\n \"old\": urls_old,\n \"new\": urls_new,\n \"diff\": difference\n} }];"
},
"name": "Diff",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1150,
-150
]
},
{
"parameters": {
"url": "https://torstencurdt.com/tech/sitemap.xml",
"responseFormat": "string",
"options": {}
},
"name": "Get Sitemap",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
490,
-150
]
},
{
"parameters": {
"functionCode": "const urls = [];\n\nfor (const item of items) {\n for (const url of item.json.urlset.url) {\n urls.push(url.loc);\n }\n}\n\nreturn [ { json: { urls: urls }} ];\n"
},
"name": "Extract URLs",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
790,
-150
]
},
{
"parameters": {},
"name": "Old and New",
"type": "n8n-nodes-base.merge",
"typeVersion": 1,
"position": [
970,
-40
]
},
{
"parameters": {
"filePath": "old.json"
},
"name": "Read Old",
"type": "n8n-nodes-base.readBinaryFile",
"typeVersion": 1,
"position": [
490,
30
],
"continueOnFail": true
},
{
"parameters": {
"fileName": "old.json"
},
"name": "Write Old",
"type": "n8n-nodes-base.writeBinaryFile",
"typeVersion": 1,
"position": [
1470,
30
]
},
{
"parameters": {
"functionCode": "return [ items[0] ];"
},
"name": "Select New",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1150,
30
]
},
{
"parameters": {
"chatId": "-3111",
"text": "={{$node[\"Get Sitemap\"].parameter[\"url\"]}} has {{$node[\"Diff\"].data[\"diff\"].length}} new entries",
"additionalFields": {}
},
"name": "New Entry",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1,
"position": [
1470,
-170
],
"credentials": {
"telegramApi": "some_bot"
}
},
{
"parameters": {
"options": {}
},
"name": "XML to JSON",
"type": "n8n-nodes-base.xml",
"typeVersion": 1,
"position": [
640,
-150
]
},
{
"parameters": {
"options": {
"keepSource": false
}
},
"name": "Data to JSON",
"type": "n8n-nodes-base.moveBinaryData",
"typeVersion": 1,
"position": [
640,
30
]
},
{
"parameters": {
"mode": "jsonToBinary",
"options": {}
},
"name": "JSON to Data",
"type": "n8n-nodes-base.moveBinaryData",
"typeVersion": 1,
"position": [
1310,
30
]
},
{
"parameters": {
"triggerTimes": {
"item": [
{}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
280,
-150
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{$node[\"Diff\"].data[\"diff\"].length}}",
"operation": "larger"
}
]
}
},
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1310,
-150
]
},
{
"parameters": {
"fileName": "old.json"
},
"name": "Clear Old",
"type": "n8n-nodes-base.writeBinaryFile",
"typeVersion": 1,
"position": [
810,
280
]
},
{
"parameters": {
"functionCode": "items[0].json.urls = [];\nreturn items;"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
480,
280
]
},
{
"parameters": {
"mode": "jsonToBinary",
"options": {}
},
"name": "JSON to Data1",
"type": "n8n-nodes-base.moveBinaryData",
"typeVersion": 1,
"position": [
650,
280
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Get Sitemap",
"type": "main",
"index": 0
}
]
]
},
"Diff": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"Get Sitemap": {
"main": [
[
{
"node": "XML to JSON",
"type": "main",
"index": 0
}
]
]
},
"Extract URLs": {
"main": [
[
{
"node": "Old and New",
"type": "main",
"index": 0
}
]
]
},
"Old and New": {
"main": [
[
{
"node": "Diff",
"type": "main",
"index": 0
},
{
"node": "Select New",
"type": "main",
"index": 0
}
]
]
},
"Read Old": {
"main": [
[
{
"node": "Data to JSON",
"type": "main",
"index": 0
}
]
]
},
"Select New": {
"main": [
[
{
"node": "JSON to Data",
"type": "main",
"index": 0
}
]
]
},
"XML to JSON": {
"main": [
[
{
"node": "Extract URLs",
"type": "main",
"index": 0
}
]
]
},
"Data to JSON": {
"main": [
[
{
"node": "Old and New",
"type": "main",
"index": 1
}
]
]
},
"JSON to Data": {
"main": [
[
{
"node": "Write Old",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "Get Sitemap",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "New Entry",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "JSON to Data1",
"type": "main",
"index": 0
}
]
]
},
"JSON to Data1": {
"main": [
[
{
"node": "Clear Old",
"type": "main",
"index": 0
}
]
]
}
}
}