first commit

This commit is contained in:
2025-11-14 09:58:21 +00:00
commit bf10598861
4 changed files with 816 additions and 0 deletions

324
tracker.json Normal file
View File

@@ -0,0 +1,324 @@
{
"name": "Telegram Location Tracker - Native (No DB)",
"nodes": [
{
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"id": "b7769320-830c-4a76-9086-ea4067969ad7",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"typeVersion": 1.1,
"position": [
0,
16
],
"webhookId": "telegram-location-webhook",
"credentials": {
"telegramApi": {
"id": "dRHgVQKqowQHIait",
"name": "Telegram account n8n-munich-bot"
}
}
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.message.location }}",
"operation": "isNotEmpty"
}
]
}
},
"id": "57f03b50-3184-4d1e-9d33-f628f93f466b",
"name": "Hat Location?",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
224,
16
]
},
{
"parameters": {
"jsCode": "// Extrahiere Location-Daten\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n const location = item.json.message.location;\n const from = item.json.message.from;\n const messageDate = item.json.message.date;\n \n const timestamp = new Date(messageDate * 1000).toISOString();\n const displayTime = new Date(messageDate * 1000).toLocaleString('de-DE');\n \n results.push({\n json: {\n latitude: location.latitude,\n longitude: location.longitude,\n timestamp: timestamp,\n user_id: from.id,\n first_name: from.first_name || '',\n last_name: from.last_name || '',\n username: from.username || '',\n marker_label: `${from.first_name || ''} ${from.last_name || ''}`.trim(),\n display_time: displayTime,\n chat_id: item.json.message.chat.id\n }\n });\n}\n\nreturn results;"
},
"id": "dafcade6-0563-47b9-bd0d-dff0f61d1dbb",
"name": "Location verarbeiten",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
448,
0
]
},
{
"parameters": {
"command": "cat /tmp/n8n-locations.json 2>/dev/null || echo '[]'"
},
"id": "d3b9945b-4d17-40c0-ae30-3d45801bae1e",
"name": "Lade existierende Daten",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [
672,
0
]
},
{
"parameters": {
"jsCode": "// Neue Location zu File hinzufügen\nconst newLocation = $('Location verarbeiten').first().json;\n\n// Lade bestehende Locations\nlet locations = [];\ntry {\n const fileContent = $input.first().json.stdout;\n locations = JSON.parse(fileContent);\n} catch (e) {\n locations = [];\n}\n\n// Füge neue Location hinzu\nlocations.unshift(newLocation); // Am Anfang einfügen (neueste zuerst)\n\n// Behalte nur die letzten 100 Einträge\nif (locations.length > 100) {\n locations = locations.slice(0, 100);\n}\n\nreturn [{\n json: {\n locations: locations,\n json_string: JSON.stringify(locations, null, 2),\n current: newLocation,\n total: locations.length\n }\n}];"
},
"id": "4fadae07-460f-4c29-800b-1fdbffe25991",
"name": "Merge mit History",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
880,
0
]
},
{
"parameters": {
"command": "=echo '{{ $json.json_string.replace(/'/g, \"'\\\\'''\") }}' > /tmp/n8n-locations.json"
},
"id": "c519118b-0626-4ace-befc-ee9859d73504",
"name": "Speichere in File",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [
1104,
0
]
},
{
"parameters": {
"chatId": "={{ $('Location verarbeiten').first().json.chat_id }}",
"text": "=✅ Standort gespeichert!\n\n📍 Koordinaten:\nLat: {{ $('Location verarbeiten').first().json.latitude }}\nLon: {{ $('Location verarbeiten').first().json.longitude }}\n\n🕐 Zeit: {{ $('Location verarbeiten').first().json.display_time }}\n\n🗺 Karte:\nhttps://web.unixweb.home64.de/tracker/index.html\n\n📊 Gespeicherte Punkte: {{ $json.total }}",
"additionalFields": {}
},
"id": "aa023c84-7664-4641-b3fc-cd30b9f69941",
"name": "Telegram Bestätigung",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.1,
"position": [
1328,
0
],
"webhookId": "9df3ad7d-315d-4782-b4ec-4fb154c0b46d",
"credentials": {
"telegramApi": {
"id": "dRHgVQKqowQHIait",
"name": "Telegram account n8n-munich-bot"
}
}
},
{
"parameters": {
"path": "location",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*"
}
},
"id": "b47e8370-3276-4f49-a2c5-25ef07b83ce8",
"name": "Webhook - Location API",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1.1,
"position": [
0,
208
],
"webhookId": "location-api-endpoint"
},
{
"parameters": {
"command": "cat /tmp/n8n-locations.json 2>/dev/null || echo '[]'"
},
"id": "200dbfff-2932-4e92-9e47-181ff706c0de",
"name": "Lade Daten für API",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [
224,
208
]
},
{
"parameters": {
"jsCode": "// Parse locations und baue API Response\nlet locations = [];\ntry {\n const fileContent = $input.first().json.stdout;\n locations = JSON.parse(fileContent);\n} catch (e) {\n locations = [];\n}\n\nconst current = locations.length > 0 ? locations[0] : null;\n\nreturn [{\n json: {\n success: true,\n current: current,\n history: locations,\n total_points: locations.length,\n last_updated: current ? current.timestamp : null\n }\n}];"
},
"id": "7c56b850-f1dd-4c51-ac8d-4313e199e6e7",
"name": "Format API Response",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
448,
208
]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ $json }}",
"options": {
"responseHeaders": {
"entries": [
{
"name": "Access-Control-Allow-Origin",
"value": "*"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
}
}
},
"id": "9b720b0b-b4f8-4599-9e2f-d6e8f67819ab",
"name": "JSON Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
672,
208
]
},
{
"parameters": {
"height": 544,
"width": 1632,
"color": 4
},
"type": "n8n-nodes-base.stickyNote",
"position": [
-80,
-112
],
"typeVersion": 1,
"id": "29506fa4-6cb3-403f-bd64-6a2f49a2eb85",
"name": "Sticky Note"
}
],
"pinData": {},
"connections": {
"Telegram Trigger": {
"main": [
[
{
"node": "Hat Location?",
"type": "main",
"index": 0
}
]
]
},
"Hat Location?": {
"main": [
[
{
"node": "Location verarbeiten",
"type": "main",
"index": 0
}
]
]
},
"Location verarbeiten": {
"main": [
[
{
"node": "Lade existierende Daten",
"type": "main",
"index": 0
}
]
]
},
"Lade existierende Daten": {
"main": [
[
{
"node": "Merge mit History",
"type": "main",
"index": 0
}
]
]
},
"Merge mit History": {
"main": [
[
{
"node": "Speichere in File",
"type": "main",
"index": 0
}
]
]
},
"Speichere in File": {
"main": [
[
{
"node": "Telegram Bestätigung",
"type": "main",
"index": 0
}
]
]
},
"Webhook - Location API": {
"main": [
[
{
"node": "Lade Daten für API",
"type": "main",
"index": 0
}
]
]
},
"Lade Daten für API": {
"main": [
[
{
"node": "Format API Response",
"type": "main",
"index": 0
}
]
]
},
"Format API Response": {
"main": [
[
{
"node": "JSON Response",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1",
"callerPolicy": "workflowsFromSameOwner",
"availableInMCP": false,
"errorWorkflow": "PhwIkaqyXRasTXDH"
},
"versionId": "b87a412a-4833-4f0d-aa33-0ba9074238d9",
"meta": {
"instanceId": "12d864c68e4fb5dfd100dc0c683b95f43cd55af7e9efa82e25407fac5a3824a5"
},
"id": "5dUTiJE61r7opoul",
"tags": []
}