{ "name": "[n8n Template] AI Content Generator", "nodes": [ { "parameters": { "httpMethod": "POST", "path": "generate-content", "responseMode": "responseNode", "options": {} }, "id": "c3d4e5f6-0001-0001-0001-c3d4e5f60001", "name": "Trigger Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 200, 300 ] }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const business = function contentPrompt({ body }) {\n if (body === null || typeof body !== 'object' || Array.isArray(body)) throw new Error('Request body must be an object');\n for (const field of ['topic', 'type', 'language', 'tone']) {\n if (body[field] != null && typeof body[field] !== 'string') throw new Error(field + ' must be a string');\n }\n const topic = body.topic || 'AI automation trends';\n const contentType = ['blog', 'newsletter', 'social'].includes(body.type) ? body.type : 'blog';\n const language = body.language || 'English';\n const tone = body.tone || 'professional but approachable';\n const prompts = {\n blog: `Write a complete blog post about: \"${topic}\"\\n\\nRequirements:\\n- Title (H1)\\n- Introduction (2-3 sentences)\\n- 3 main sections with H2 headers\\n- Practical examples in each section\\n- Conclusion with call to action\\n- Tone: ${tone}\\n- Language: ${language}\\n- Length: ~600 words`,\n newsletter: `Write a newsletter issue about: \"${topic}\"\\n\\nRequirements:\\n- Catchy subject line\\n- Opening hook (1-2 sentences)\\n- 3 key insights with brief explanations\\n- One actionable tip\\n- Sign-off\\n- Tone: ${tone}\\n- Language: ${language}\\n- Length: ~300 words`,\n social: `Write 3 social media posts about: \"${topic}\"\\n\\nFor each post:\\n- Platform variant (Twitter/X, LinkedIn, Instagram)\\n- Different angle for each\\n- Relevant hashtags\\n- Tone: ${tone}\\n- Language: ${language}`,\n };\n return { topic, contentType, language, prompt: prompts[contentType] };\n}\n\nreturn $input.all().map((item, index) => { const result = business({body:item.json.body}); return {json: result, pairedItem: {item: index}}; });\n" }, "id": "c3d4e5f6-0002-0002-0002-c3d4e5f60002", "name": "Build Prompt", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 420, 300 ] }, { "parameters": { "method": "POST", "url": "https://api.anthropic.com/v1/messages", "authentication": "predefinedCredentialType", "nodeCredentialType": "anthropicApi", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "anthropic-version", "value": "2023-06-01" }, { "name": "content-type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({model:'claude-sonnet-4-6',max_tokens:2000,system:\"You are an expert content writer. Produce high-quality, engaging content that provides real value to readers.\",messages:[{role:'user',content:$json.prompt}]}) }}", "options": {} }, "id": "c3d4e5f6-0003-0003-0003-c3d4e5f60003", "name": "Generate Content", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4, "position": [ 640, 300 ] }, { "parameters": { "resource": "message", "operation": "post", "select": "channel", "channelId": { "__rl": true, "mode": "id", "value": "YOUR_SLACK_CHANNEL_ID" }, "messageType": "block", "blocksUi": "={{ JSON.stringify({blocks:$json.blocks}) }}", "text": "={{ $json.text }}", "otherOptions": { "includeLinkToWorkflow": false } }, "id": "c3d4e5f6-0004-0004-0004-c3d4e5f60004", "name": "Notify via Slack", "type": "n8n-nodes-base.slack", "typeVersion": 2.2, "position": [ 1080, 300 ] }, { "parameters": { "respondWith": "json", "responseBody": "={{ $('Prepare content delivery').item.json.response }}", "options": {} }, "id": "c3d4e5f6-0005-0005-0005-c3d4e5f60005", "name": "Return Content", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [ 1300, 300 ] }, { "id": "format-content-delivery", "name": "Prepare content delivery", "position": [ 860, 300 ], "type": "n8n-nodes-base.code", "typeVersion": 2, "parameters": { "mode": "runOnceForAllItems", "jsCode": "const business = function contentResult({ topic, contentType, content }) {\n if (typeof content !== 'string' || !content.trim()) throw new Error('The model returned no content');\n const escape = (text) => text.replace(/&/g, '&').replace(//g, '>');\n const displayTopic = escape(topic.slice(0, 200));\n return {\n text: `✍️ New content generated for topic: *${displayTopic}*`,\n blocks: [\n { type: 'section', text: { type: 'mrkdwn', text: `✍️ *Content Ready*\\nTopic: ${displayTopic}\\nType: ${contentType}` } },\n { type: 'section', text: { type: 'mrkdwn', text: escape(content.slice(0, 500)) + '...' } },\n ],\n response: { status: 'success', topic, contentType, content },\n };\n}\n\nreturn $input.all().map((item, index) => { const result = business({topic:$('Build Prompt').itemMatching(index).json.topic,contentType:$('Build Prompt').itemMatching(index).json.contentType,content:item.json.content?.[0]?.text}); return {json: result, pairedItem: {item: index}}; });\n" } } ], "connections": { "Trigger Webhook": { "main": [ [ { "node": "Build Prompt", "type": "main", "index": 0 } ] ] }, "Build Prompt": { "main": [ [ { "node": "Generate Content", "type": "main", "index": 0 } ] ] }, "Generate Content": { "main": [ [ { "node": "Prepare content delivery", "type": "main", "index": 0 } ] ] }, "Prepare content delivery": { "main": [ [ { "node": "Notify via Slack", "type": "main", "index": 0 } ] ] }, "Notify via Slack": { "main": [ [ { "node": "Return Content", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1", "timezone": "UTC" }, "pinData": {} }