{ "nodes": [ { "id": "b165115d-5505-4e03-bf41-c21320cb8b09", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "position": [ 80, 40 ], "parameters": { "color": 7, "width": 681.8337349708484, "height": 843.1482165886073, "content": "## Shortcut Text Transformer\nPOST JSON with type and content. Allowed types: spanish, english, grammar, shorter, longer (lowercase). Select OpenAI credentials on the five OpenAI nodes. One matching branch calls gpt-4o-mini and returns plain text. Unknown operations, empty text, or invalid model output fail the workflow. See README for the Apple Shortcut setup." }, "typeVersion": 1 }, { "id": "c45400b8-d3b8-47f7-81c6-d791bce4c266", "name": "Switch", "type": "n8n-nodes-base.switch", "position": [ 1020, 380 ], "parameters": { "rules": { "values": [ { "outputKey": "spanish", "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "operator": { "type": "string", "operation": "equals" }, "leftValue": "={{ $json.body.type }}", "rightValue": "spanish" } ] }, "renameOutput": true }, { "outputKey": "english", "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "bedb302f-646c-4dcd-8246-1fcfecfe3f2e", "operator": { "name": "filter.operator.equals", "type": "string", "operation": "equals" }, "leftValue": "={{ $json.body.type }}", "rightValue": "english" } ] }, "renameOutput": true }, { "outputKey": "grammar", "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "94e6cf7d-576d-4ad9-85b0-c6b945eb41b7", "operator": { "name": "filter.operator.equals", "type": "string", "operation": "equals" }, "leftValue": "={{ $json.body.type }}", "rightValue": "grammar" } ] }, "renameOutput": true }, { "outputKey": "shorter", "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "1ed0d1e1-2df0-4f8d-b102-4004a25919ed", "operator": { "name": "filter.operator.equals", "type": "string", "operation": "equals" }, "leftValue": "={{ $json.body.type }}", "rightValue": "shorter" } ] }, "renameOutput": true }, { "outputKey": "longer", "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "4756df03-7e7c-4e28-9b37-14684326b083", "operator": { "name": "filter.operator.equals", "type": "string", "operation": "equals" }, "leftValue": "={{ $json.body.type }}", "rightValue": "longer" } ] }, "renameOutput": true } ] }, "options": {} }, "typeVersion": 3.2 }, { "id": "48e0e58e-6293-4e11-a488-ca9943b53484", "name": "Respond to Shortcut", "type": "n8n-nodes-base.respondToWebhook", "position": [ 1840, 400 ], "parameters": { "respondWith": "text", "responseBody": "={{ $json.text }}", "options": { "responseCode": 200, "responseHeaders": { "entries": [ { "name": "Content-Type", "value": "text/plain; charset=utf-8" } ] } } }, "typeVersion": 1.1 }, { "id": "2655b782-9538-416c-ae65-35f8c77889c7", "name": "Webhook from Shortcut", "type": "n8n-nodes-base.webhook", "position": [ 840, 400 ], "parameters": { "path": "shortcut-text-transformer", "options": {}, "httpMethod": "POST", "responseMode": "responseNode" }, "typeVersion": 2 }, { "id": "880ed4a2-0756-4943-a51f-368678e22273", "name": "OpenAI - Make Shorter", "type": "@n8n/n8n-nodes-langchain.openAi", "position": [ 1300, 540 ], "parameters": { "modelId": { "__rl": true, "mode": "list", "value": "gpt-4o-mini", "cachedResultName": "GPT-4O-MINI" }, "options": {}, "messages": { "values": [ { "role": "system", "content": "Summarize this content a little bit (5% shorter)\nOutput a JSON with a single field: output" }, { "content": "={{ $json.body.content }}", "role": "user" } ] }, "jsonOutput": true, "resource": "text", "operation": "message", "simplify": true, "hideTools": "hide" }, "typeVersion": 1.4 }, { "id": "c6c6d988-7aab-4677-af1f-880d05691ec3", "name": "OpenAI - Make Longer", "type": "@n8n/n8n-nodes-langchain.openAi", "position": [ 1300, 680 ], "parameters": { "modelId": { "__rl": true, "mode": "list", "value": "gpt-4o-mini", "cachedResultName": "GPT-4O-MINI" }, "options": {}, "messages": { "values": [ { "role": "system", "content": "Make this content a little longer (5% longer)\nOutput a JSON with a single field: output" }, { "content": "={{ $json.body.content }}", "role": "user" } ] }, "jsonOutput": true, "resource": "text", "operation": "message", "simplify": true, "hideTools": "hide" }, "typeVersion": 1.4 }, { "id": "8e6de4b7-22c3-45c9-a8d7-d498cf829b6f", "name": "OpenAI - Correct Grammar", "type": "@n8n/n8n-nodes-langchain.openAi", "position": [ 1300, 400 ], "parameters": { "modelId": { "__rl": true, "mode": "list", "value": "gpt-4o-mini", "cachedResultName": "GPT-4O-MINI" }, "options": {}, "messages": { "values": [ { "role": "system", "content": "Correct grammar only, don't change the actual contents.\nOutput a JSON with a single field: output" }, { "content": "={{ $json.body.content }}", "role": "user" } ] }, "jsonOutput": true, "resource": "text", "operation": "message", "simplify": true, "hideTools": "hide" }, "typeVersion": 1.4 }, { "id": "bc006b36-5a96-4c3a-9a28-2778a6c49f10", "name": "OpenAI - To Spanish", "type": "@n8n/n8n-nodes-langchain.openAi", "position": [ 1300, 120 ], "parameters": { "modelId": { "__rl": true, "mode": "list", "value": "gpt-4o-mini", "cachedResultName": "GPT-4O-MINI" }, "options": {}, "messages": { "values": [ { "role": "system", "content": "Translate this message to Spanish.\nOutput a JSON with a single field: output" }, { "content": "={{ $json.body.content }}", "role": "user" } ] }, "jsonOutput": true, "resource": "text", "operation": "message", "simplify": true, "hideTools": "hide" }, "typeVersion": 1.4 }, { "id": "330d2e40-1e52-4517-94e0-ce96226697fa", "name": "OpenAI - To English", "type": "@n8n/n8n-nodes-langchain.openAi", "position": [ 1300, 260 ], "parameters": { "modelId": { "__rl": true, "mode": "list", "value": "gpt-4o-mini", "cachedResultName": "GPT-4O-MINI" }, "options": {}, "messages": { "values": [ { "role": "system", "content": "Translate this message to English.\nOutput a JSON with a single field: output" }, { "content": "={{ $json.body.content }}", "role": "user" } ] }, "jsonOutput": true, "resource": "text", "operation": "message", "simplify": true, "hideTools": "hide" }, "typeVersion": 1.4 }, { "id": "925e4b55-ac26-4c16-941f-66d17b6794ab", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "position": [ 80, 900 ], "parameters": { "color": 7, "width": 469.15174499329123, "height": 341.88919758842485, "content": "## Shortcut Text Transformer\nPOST JSON with type and content. Allowed types: spanish, english, grammar, shorter, longer (lowercase). Select OpenAI credentials on the five OpenAI nodes. One matching branch calls gpt-4o-mini and returns plain text. Unknown operations, empty text, or invalid model output fail the workflow. See README for the Apple Shortcut setup." }, "typeVersion": 1 }, { "id": "a5bb1d44-df91-4908-ae24-cc4ac4760dab", "name": "Validate text request", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -180, 380 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "const prompts = {\n spanish: 'Translate this message to Spanish.\\nOutput a JSON with a single field: output',\n english: 'Translate this message to English.\\nOutput a JSON with a single field: output',\n grammar: \"Correct grammar only, don't change the actual contents.\\nOutput a JSON with a single field: output\",\n shorter: 'Summarize this content a little bit (5% shorter)\\nOutput a JSON with a single field: output',\n longer: 'Make this content a little longer (5% longer)\\nOutput a JSON with a single field: output',\n};\n\nfunction prepareText({ body }) {\n const { type, content } = body;\n if (typeof type !== 'string' || !Object.hasOwn(prompts, type)) {\n throw new Error('Choose spanish, english, grammar, shorter, or longer.');\n }\n if (typeof content !== 'string' || !content.trim()) {\n throw new Error('content must be nonempty text.');\n }\n return { type, content, prompt: prompts[type] };\n}\n\nconst prepared=prepareText({body:$input.first().json.body ?? {}});\nreturn [{json:{body:{type:prepared.type,content:prepared.content}}}];\n" } }, { "id": "9d49abf2-e170-493c-9d4e-a6d9d1ff3427", "name": "Read transformed text", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 620, 380 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "function textResult({ result }) {\n if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.output !== 'string' || !result.output.trim()) {\n throw new Error('The model must return a nonempty output string.');\n }\n return { text: result.output };\n}\n\nreturn [{json:textResult({result:$input.first().json.message?.content})}];\n" } } ], "pinData": {}, "connections": { "Switch": { "main": [ [ { "node": "OpenAI - To Spanish", "type": "main", "index": 0 } ], [ { "node": "OpenAI - To English", "type": "main", "index": 0 } ], [ { "node": "OpenAI - Correct Grammar", "type": "main", "index": 0 } ], [ { "node": "OpenAI - Make Shorter", "type": "main", "index": 0 } ], [ { "node": "OpenAI - Make Longer", "type": "main", "index": 0 } ] ] }, "OpenAI - To English": { "main": [ [ { "node": "Read transformed text", "type": "main", "index": 0 } ] ] }, "OpenAI - To Spanish": { "main": [ [ { "node": "Read transformed text", "type": "main", "index": 0 } ] ] }, "OpenAI - Make Longer": { "main": [ [ { "node": "Read transformed text", "type": "main", "index": 0 } ] ] }, "OpenAI - Make Shorter": { "main": [ [ { "node": "Read transformed text", "type": "main", "index": 0 } ] ] }, "Webhook from Shortcut": { "main": [ [ { "node": "Validate text request", "type": "main", "index": 0 } ] ] }, "OpenAI - Correct Grammar": { "main": [ [ { "node": "Read transformed text", "type": "main", "index": 0 } ] ] }, "Validate text request": { "main": [ [ { "node": "Switch", "type": "main", "index": 0 } ] ] }, "Read transformed text": { "main": [ [ { "node": "Respond to Shortcut", "type": "main", "index": 0 } ] ] } }, "name": "Shortcut Text Transformer", "active": false }