{
  "id": "2SlK5ydfZ8QhfxSX",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Generate Instagram Carousels from Telegram Prompts using OpenAI & Kie AI",
  "tags": [],
  "nodes": [
    {
      "id": "cc04075a-78be-427c-9aaf-13bb2fd3830c",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -488,
        56
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"prompts\": [\n    \"{{prompt1}}\",\n    \"{{prompt2}}\",\n    \"{{prompt3}}\",\n    \"{{prompt4}}\",\n    \"{{prompt5}}\"\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "79a5745e-9eda-4734-ad96-e1b74248aba0",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -616,
        56
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {},
        "responsesApiEnabled": false
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "6fc2ea05-05f8-41df-9558-7c88b4c18fad",
      "name": "Start on Telegram Message",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1296,
        -168
      ],
      "parameters": {
        "updates": [
          "channel_post",
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b121b44c-9350-49ce-8b30-b8d489e1f707",
      "name": "Set Brand Style",
      "type": "n8n-nodes-base.set",
      "position": [
        -848,
        -168
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "be3f528a-d477-4d80-9b4c-5aa655fd4a97",
              "name": "style",
              "type": "string",
              "value": "Dark Mode, Electric Teal & White accents, Modern Minimalist Tech aesthetic, Bold Sans-serif typography, High contrast & Sleek vibe, aspect ratio 4:5, edges need to be black with smooth gradation"
            },
            {
              "id": "77d00f2c-738a-46f1-8c8b-4a7f2eba412e",
              "name": "topic",
              "type": "string",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7a7ed391-4f8a-4afe-abfd-9d3f90254d21",
      "name": "Generate Carousel Content",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -624,
        -168
      ],
      "parameters": {
        "text": "=make carousel image",
        "options": {
          "systemMessage": "=You are a Senior Content Strategist & Copywriter. Your expertise is taking a raw idea (a short brief) and developing it into a highly detailed, actionable, and viral 5-slide educational Instagram Carousel with a 4:5 aspect ratio.\\n\\n## DATA INPUT:\\n1. Topic & Brief: {{$json.topic}}\\n2. Brand/Visual Style: {{$json.style}}\\n*(If the style input is empty, use the default: Minimalist, Bold Typography, Professional)*\\n\\n## CONTENT DEVELOPMENT TASK (IMPORTANT):\\nThe input you receive is only a title and a summary. YOUR TASK is to:\\n1. **Extrapolate the Idea:** Develop the brief into concrete/tactical steps.\\n2. **Simulate Details:** If the brief mentions a \\\"case study\\\", create a plausible and specific example scenario.\\n3. **Writing:** Write engaging, no-fluff, and to-the-point copy for each slide.\\n\\n## CAROUSEL STRUCTURE (5 SLIDES):\\n- Slide 1 (The Hook): A bombastic title + a sub-headline that promises a solution/result.\\n- Slide 2 (The Problem/Start): The initial step or problem validation (based on the brief).\\n- Slide 3 (The Process): The core strategy/main execution.\\n- Slide 4 (The Result/Insight): Real results or important lessons (aha moment).\\n- Slide 5 (The CTA): A one-sentence conclusion + a call to follow this account.\\n\\n## VISUAL INSTRUCTIONS:\\nAnalyze the 'Brand/Visual Style' variable. Apply the mood, color, and font style to the image prompt to ensure the visuals are consistent and premium.\\n\\n## OUTPUT RULE (JSON):\\nReturn ONLY the following valid JSON format.\\nEnsure the \\\"prompts\\\" field contains image instructions in ENGLISH that include a description of the visual background AND the overlay text (the content you have developed)."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "d461fe6b-8fc2-40b4-b931-a99099f9396c",
      "name": "Generate Caption",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -272,
        -64
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "GPT-4.1"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=Prompt 1: {{ $json.output.prompts[0] }}\nPrompt 2: {{ $json.output.prompts[1] }}\nPrompt 3: {{ $json.output.prompts[2] }}\nPrompt 4: {{ $json.output.prompts[3] }}\nPrompt 5: {{ $json.output.prompts[4] }}"
            },
            {
              "role": "system",
              "content": "=You are an Instagram Copywriter Specialist. Your task is to create a captivating caption based on the provided carousel image prompt.\\n\\nAdhere to the following criteria:\\n1. **Killer Hook:** The first sentence MUST grab attention (stop-scrolling effect) and arouse curiosity.\\n2. **SEO Friendly:** Naturally insert relevant keywords into the sentences to make the content easily discoverable.\\n3. **Engagement:** Use a flexible/familiar writing style. End with a clear CTA (e.g., a call to Save, Share, or a question).\\n4. **Neat Format:** Use short paragraphs and line breaks (spaces between lines) for comfortable reading on mobile.\\n5. **Hashtags:** Include a combination of trending and niche (specific) hashtags at the very bottom.\\n\\n**OUTPUT RULE:**\\nOnly provide the ready-to-post caption under 450 characters. DO NOT provide explanations, intros, or any other text outside the caption."
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "fdb916fe-4d68-4630-a0a7-ab52efa1438b",
      "name": "Generate Carousel Images",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        80,
        -264
      ],
      "parameters": {
        "url": "https://api.kie.ai/api/v1/jobs/createTask",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"nano-banana-pro\",\n  \"input\": {\n    \"prompt\": {{ JSON.stringify($json['output.prompts']) }},\n    \"aspect_ratio\": \"4:5\",\n    \"resolution\": \"1K\",\n    \"output_format\": \"png\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "e85a4264-b1c0-47c4-ab82-e1033b2500c5",
      "name": "Retrieve Carousel Images",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        528,
        -336
      ],
      "parameters": {
        "url": "https://api.kie.ai/api/v1/jobs/recordInfo",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "taskId",
              "value": "={{ $json.data.taskId }}"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "58a821d5-f940-485a-8239-328df4abf4c3",
      "name": "Send Images to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1200,
        -264
      ],
      "parameters": {
        "chatId": "<YOURCHATID>",
        "operation": "sendPhoto",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "290cb5c6-4cf2-4b17-afba-7d0aee80f5dd",
      "name": "Download Images",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        976,
        -264
      ],
      "parameters": {
        "url": "={{ JSON.parse($json.data.resultJson).resultUrls[0] }}",
        "options": {}
      },
      "typeVersion": 4.3
    },
    {
      "id": "1ec7e19f-b266-4f9e-a217-ff21543bc034",
      "name": "Send Caption to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1200,
        -64
      ],
      "parameters": {
        "text": "={{ $json.output[0].content[0].text }}",
        "chatId": "<YOURCHATID>",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "187fc879-8a2f-49a9-be03-693bfb6d5bf6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1792,
        -352
      ],
      "parameters": {
        "width": 368,
        "height": 544,
        "content": "## How it works\nThis workflow transforms a Telegram text prompt into a 5-slide Instagram carousel. An AI Agent plans the content and visual concepts, while a separate model writes an SEO-friendly caption. Images are generated via Kie AI and sent back to you on Telegram, ready to post.\n\n## Setup steps\n1. **Telegram:** Create a bot via BotFather. Add the Token to credentials and your Chat ID to the 'Verify User ID' node.\n2. **OpenAI:** Connect your OpenAI API Key.\n3. **Kie AI:** Sign up for Kie AI and add the API Key to the HTTP Request nodes.\n4. **Branding:** Edit the \"Set Brand Style\" node to define your preferred colors, fonts, and aesthetic."
      },
      "typeVersion": 1
    },
    {
      "id": "85d509ac-f9d9-48ca-93d1-40b161fe0480",
      "name": "Check Image Generation Status",
      "type": "n8n-nodes-base.if",
      "position": [
        752,
        -264
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e9b0731b-09d7-44f6-a67c-f26665ae4a9b",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.data.state }}",
              "rightValue": "success"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "e87be366-7fc6-4ea6-9f99-e734f7254170",
      "name": "Wait for Image Generation",
      "type": "n8n-nodes-base.wait",
      "position": [
        304,
        -264
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "65a622f2-2569-4542-9018-3a6d4c406e4b",
      "name": "Split Prompts",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -208,
        -264
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output.prompts"
      },
      "typeVersion": 1
    },
    {
      "id": "08a1ea7c-8bee-45aa-a7f3-8149b5d7c2dc",
      "name": "Verify User ID",
      "type": "n8n-nodes-base.if",
      "position": [
        -1072,
        -168
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "74bcf947-56e5-40ca-8100-190a1418d486",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $json.message.chat.id }}",
              "rightValue": 12345667
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "e334cc8a-f4e7-4084-a519-2324f2c578a4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1376,
        -352
      ],
      "parameters": {
        "color": 5,
        "width": 688,
        "height": 544,
        "content": "## Step 1: Receive & Verify Input"
      },
      "typeVersion": 1
    },
    {
      "id": "87dee421-841b-4d12-a177-0cbcec15aa45",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -656,
        -352
      ],
      "parameters": {
        "color": 4,
        "width": 672,
        "height": 544,
        "content": "## Step 2: Generate Content & Prompts"
      },
      "typeVersion": 1
    },
    {
      "id": "8a5df199-61e5-403b-af84-73fd1f1aef36",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        -352
      ],
      "parameters": {
        "color": 3,
        "width": 1056,
        "height": 544,
        "content": "## Step 3: Create Visuals"
      },
      "typeVersion": 1
    },
    {
      "id": "924656d2-cd87-4ec2-9c79-e2b38f018ff3",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        -352
      ],
      "parameters": {
        "color": 6,
        "width": 272,
        "height": 544,
        "content": "## Step 4: Deliver Results"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "aa31fb42-3b76-48ba-a58b-1b3e6d6b046a",
  "connections": {
    "Split Prompts": {
      "main": [
        [
          {
            "node": "Generate Carousel Images",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify User ID": {
      "main": [
        [
          {
            "node": "Set Brand Style",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Images": {
      "main": [
        [
          {
            "node": "Send Images to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Brand Style": {
      "main": [
        [
          {
            "node": "Generate Carousel Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Caption": {
      "main": [
        [
          {
            "node": "Send Caption to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Carousel Content",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate Carousel Images": {
      "main": [
        [
          {
            "node": "Wait for Image Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Carousel Images": {
      "main": [
        [
          {
            "node": "Check Image Generation Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Generate Carousel Content",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Generate Carousel Content": {
      "main": [
        [
          {
            "node": "Generate Caption",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Prompts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start on Telegram Message": {
      "main": [
        [
          {
            "node": "Verify User ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Image Generation": {
      "main": [
        [
          {
            "node": "Retrieve Carousel Images",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Image Generation Status": {
      "main": [
        [
          {
            "node": "Download Images",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for Image Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}