{ "name": "Telegram Command", "nodes": [ { "parameters": { "updates": [ "message" ], "additionalFields": {} }, "type": "n8n-nodes-base.telegramTrigger", "typeVersion": 1.2, "position": [ 0, 0 ], "id": "6a6751de-48cc-49e8-a0e0-dce88167a809", "name": "Telegram Trigger", "webhookId": "9c77ead0-c342-4fae-866d-d0d9247027e2", "credentials": { "telegramApi": { "id": "ADurvy9EKUDzbDdq", "name": "DK0_Server" } } }, { "parameters": { "jsCode": " var text = $input.first().json.message?.text ?? '';\n var chatId = $input.first().json.message?.chat?.id;\n var match;\n\n match = text.match(/\\/publishproject(\\d+)/);\n if (match) return [{ json: { action: 'publish', id: match[1], collection: 'projects', chatId: chatId } }];\n\n match = text.match(/\\/deleteproject(\\d+)/);\n if (match) return [{ json: { action: 'delete', id: match[1], collection: 'projects', chatId: chatId } }];\n\n match = text.match(/\\/publishbook(\\d+)/);\n if (match) return [{ json: { action: 'publish', id: match[1], collection: 'book_reviews', chatId: chatId } }];\n\n match = text.match(/\\/deletebook(\\d+)/);\n if (match) return [{ json: { action: 'delete', id: match[1], collection: 'book_reviews', chatId: chatId } }];\n\n match = text.match(/\\/deletereview(\\d+)/);\n if (match) return [{ json: { action: 'delete_review', id: match[1], chatId: chatId } }];\n\n if (text.startsWith('.review')) {\n var rest = text.replace('.review', '').trim();\n var firstSpace = rest.indexOf(' ');\n var secondSpace = rest.indexOf(' ', firstSpace + 1);\n var hcId = rest.substring(0, firstSpace);\n var rating = parseInt(rest.substring(firstSpace + 1, secondSpace)) || 3;\n var answers = rest.substring(secondSpace + 1);\n return [{ json: { action: 'create_review', hardcoverId: hcId, rating: rating, answers: answers, chatId: chatId } }];\n }\n\n return [{ json: { action: 'unknown', chatId: chatId, text: text } }];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 192, 16 ], "id": "31f87727-adce-4df2-a957-2ff4a13218d9", "name": "Code in JavaScript" }, { "parameters": { "rules": { "values": [ { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "leftValue": "={{ $json.action }}", "rightValue": "publishproject", "operator": { "type": "string", "operation": "contains" }, "id": "ce154df4-9dd0-441b-9df2-5700fcdb7c33" } ], "combinator": "and" }, "renameOutput": true, "outputKey": "Publish Project" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "aae406a7-311b-4c52-b6d2-afa40fecd0b9", "leftValue": "={{ $json.action }}", "rightValue": "deleteproject", "operator": { "type": "string", "operation": "contains" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "Delete Project" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "57d9f445-1a71-4385-b01c-718283864108", "leftValue": "={{ $json.action }}", "rightValue": "publishbook", "operator": { "type": "string", "operation": "contains" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "Publish Book" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "79fd4ff3-31bc-41d1-acb0-04577492d90a", "leftValue": "={{ $json.action }}", "rightValue": "deletebook", "operator": { "type": "string", "operation": "contains" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "Delete Book" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "9536178d-bcfa-4d0a-bf51-2f9521f5a55f", "leftValue": "={{ $json.action }}", "rightValue": "deletereview", "operator": { "type": "string", "operation": "contains" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "Delete Review" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "ce822e16-e8a1-45f3-b1dd-795d1d9fccd0", "leftValue": "={{ $json.action }}", "rightValue": ".review", "operator": { "type": "string", "operation": "contains" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "Review" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "5551fb2c-c25e-4123-b34c-f359eefc6fcd", "leftValue": "={{ $json.action }}", "rightValue": "unknown", "operator": { "type": "string", "operation": "contains" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "unknown" } ] }, "options": {} }, "type": "n8n-nodes-base.switch", "typeVersion": 3.4, "position": [ 400, 16 ], "id": "724ae93f-e1d6-4264-a6a0-6c5cce24e594", "name": "Switch" }, { "parameters": { "jsCode": "const { id, collection } = $input.first().json;\n\nconst response = await this.helpers.httpRequest({\n method: \"PATCH\",\n url: `https://cms.dk0.dev/items/${collection}/${id}`,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: \"Bearer RF2QytqhcLXuVy6FO3PzWlsoR-ysCTwB\",\n },\n body: { status: \"published\" },\n});\n\nreturn [{ json: { ...response, action: \"published\", id, collection } }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 640, -144 ], "id": "8409c223-d5f3-4f86-b1bc-639775a504c0", "name": "Code in JavaScript1" }, { "parameters": { "jsCode": "const { id, collection } = $input.first().json;\n\nawait this.helpers.httpRequest({\n method: \"DELETE\",\n url: `https://cms.dk0.dev/items/${collection}/${id}`,\n headers: {\n Authorization: \"Bearer RF2QytqhcLXuVy6FO3PzWlsoR-ysCTwB\",\n },\n});\n\nreturn [{ json: { id, collection } }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 640, 16 ], "id": "ec6d4201-d382-49ba-8754-1750286377eb", "name": "Code in JavaScript2" }, { "parameters": { "chatId": "145931600", "text": "={{ '🗑️ #' + $json.id + ' aus ' + $json.collection + ' gelöscht.' }}", "additionalFields": {} }, "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [ 848, 16 ], "id": "ef166bfe-d006-4231-a062-f031c663d034", "name": "Send a text message1", "webhookId": "7fa154b5-7382-489d-9ee9-066e156f58da", "credentials": { "telegramApi": { "id": "8iiaTtJHXgDIiVaa", "name": "Telegram" } } }, { "parameters": { "chatId": "145931600", "text": "={{ '✅ #' + $json.id + ' in ' + $json.collection + ' veröffentlicht!' }}", "additionalFields": {} }, "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [ 848, -144 ], "id": "c7ff73bb-22f2-4754-88a8-b91cf9743329", "name": "Send a text message", "webhookId": "2c95cd9d-1d1d-4249-8e64-299a46e8638e", "credentials": { "telegramApi": { "id": "8iiaTtJHXgDIiVaa", "name": "Telegram" } } }, { "parameters": { "chatId": "145931600145931600", "text": "={{ '❓ Unbekannter Command\\n\\nVerfügbar:\\n/publish_project_ID\\n/delete_project_ID\\n/publish_book_ID\\n/delete_book_ID' }}", "additionalFields": {} }, "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [ 624, 192 ], "id": "8d71429d-b006-4748-9e11-42e17039075b", "name": "Send a text message2", "webhookId": "8a211bf8-54ca-4779-9535-21d65b14a4f7", "credentials": { "telegramApi": { "id": "8iiaTtJHXgDIiVaa", "name": "Telegram" } } }, { "parameters": { "jsCode": " const d = $input.first().json;\n\n const check = await this.helpers.httpRequest({\n method: \"GET\",\n url: \"https://cms.dk0.dev/items/book_reviews?filter[hardcover_id][_eq]=\" + d.hardcoverId +\n \"&fields=id,book_title,book_author,book_image,finished_at&limit=1\",\n headers: { \"Authorization\": \"Bearer RF2QytqhcLXuVy6FO3PzWlsoR-ysCTwB\" }\n });\n\n const book = check.data?.[0];\n if (!book) return [{ json: { error: \"Buch nicht gefunden\", chatId: d.chatId } }];\n\n const parts = [];\n parts.push(\"Schreibe eine authentische Buchbewertung.\");\n parts.push(\"Buch: \" + book.book_title + \" von \" + book.book_author);\n parts.push(\"Rating: \" + d.rating + \"/5\");\n parts.push(\"Antworten des Lesers: \" + d.answers);\n parts.push(\"Schreibe Ich-Perspektive, 4-6 Saetze pro Sprache.\");\n parts.push(\"Antworte NUR als JSON:\");\n parts.push('{\"review_en\": \"English\", \"review_de\": \"Deutsch\"}');\n const prompt = parts.join(\" \");\n\n const aiResponse = await this.helpers.httpRequest({\n method: \"POST\",\n url: \"https://openrouter.ai/api/v1/chat/completions\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": \"Bearer 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\"\n },\n body: {\n model: \"google/gemini-2.0-flash-exp:free\",\n messages: [{ role: \"user\", content: prompt }]\n }\n });\n\n const aiText = aiResponse.choices?.[0]?.message?.content ?? \"{}\";\n const match = aiText.match(/\\{[\\s\\S]*\\}/);\n const ai = match ? JSON.parse(match[0]) : { review_en: d.answers, review_de: d.answers };\n\n const result = await this.helpers.httpRequest({\n method: \"PATCH\",\n url: \"https://cms.dk0.dev/items/book_reviews/\" + book.id,\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": \"Bearer RF2QytqhcLXuVy6FO3PzWlsoR-ysCTwB\"\n },\n body: {\n rating: d.rating,\n status: \"draft\",\n translations: {\n create: [\n { languages_code: \"en-US\", review: ai.review_en },\n { languages_code: \"de-DE\", review: ai.review_de }\n ]\n }\n }\n });\n\n return [{ json: { id: book.id, title: book.book_title, rating: d.rating, chatId: d.chatId } }];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 912, 160 ], "id": "ea82c02e-eeb8-4acd-a0e6-e4a9f8cb8bf9", "name": "Code in JavaScript3" }, { "parameters": { "chatId": "145931600", "text": "={{ '✅ Review fuer \"' + $json.title + '\" erstellt! ⭐' + $json.rating + '/5\\n\\n/publishbook' + $json.id + ' — Veroeffentlichen\\n/deletebook' + $json.id + ' — Loeschen' }}", "additionalFields": {} }, "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [ 1216, 160 ], "id": "c46f5182-a815-442d-ac72-c8694b982e74", "name": "Send a text message3", "webhookId": "3452ada6-a863-471d-89a1-31bf625ce559", "credentials": { "telegramApi": { "id": "8iiaTtJHXgDIiVaa", "name": "Telegram" } } } ], "pinData": {}, "connections": { "Telegram Trigger": { "main": [ [ { "node": "Code in JavaScript", "type": "main", "index": 0 } ] ] }, "Code in JavaScript": { "main": [ [ { "node": "Switch", "type": "main", "index": 0 } ] ] }, "Switch": { "main": [ [ { "node": "Code in JavaScript1", "type": "main", "index": 0 } ], [ { "node": "Code in JavaScript2", "type": "main", "index": 0 } ], [ { "node": "Code in JavaScript3", "type": "main", "index": 0 } ], [ { "node": "Send a text message2", "type": "main", "index": 0 } ], [], [], [] ] }, "Code in JavaScript1": { "main": [ [ { "node": "Send a text message", "type": "main", "index": 0 } ] ] }, "Code in JavaScript2": { "main": [ [ { "node": "Send a text message1", "type": "main", "index": 0 } ] ] }, "Code in JavaScript3": { "main": [ [ { "node": "Send a text message3", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1", "binaryMode": "separate", "availableInMCP": false }, "versionId": "a7449224-9a28-4aff-b4e2-26f1bcd4542f", "meta": { "templateCredsSetupCompleted": true, "instanceId": "cb28e4db755465d5826da179e87f69603d81f833414cc52c327be9183a217b8d" }, "id": "8mZbFdEsOeufWutD", "tags": [] }