{
  "name": "Ghostwriter Agent",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "7558641202"
        }
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -1400,
        120
      ],
      "id": "94cfc72b-b37d-4b95-a758-02d6796648c1",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "messages": {
          "values": [
            {
              "content": "=### INSTRUCTIONS\nGiven the following text message from the user determine if the user is asking  the assistant to create a post.\n\nTips to recognize post creation request:\n- If the user starts the message with \"create a post\" or \"make a post\" or \"lets create something\" or \"lets draft\" something\n\nGenerally check if user asks you to create a post/content.\n\nFORMAT THE OUTPUT LIKE THE FOLLOWING JSON OBJECT:\n```json\n{\n  \"shouldCreatePost\": \"true | false\"\n}\n```\n\nOUPUT ONLY THIS EXACT JSON OBJECT, NOTHING ELSE.\n\n### USER TEXT MESSASAGE\n{{ $('Telegram Trigger').item.json.message.text }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        -720,
        -40
      ],
      "id": "0cf7cff7-95b5-4191-9770-b19c458fa62c",
      "name": "OpenAI",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "bc62df0f-4caf-45fe-b268-85f34c950305",
              "leftValue": "={{ $json.message.content.shouldCreatePost.toBoolean() }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -440,
        -40
      ],
      "id": "1d5c97e8-66fd-43f3-a3e3-a56dfdf127b8",
      "name": "If"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "claude-opus-4-20250514",
          "mode": "list",
          "cachedResultName": "Claude Opus 4"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.3,
      "position": [
        -20,
        200
      ],
      "id": "c1f2496e-be06-4ba9-8291-58e6db51fd4b",
      "name": "Anthropic Chat Model",
      "credentials": {
        "anthropicApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=### Instructions\nyou are an extremely good copywriter for Twitter social media posts.\n\nyou need to help the user draft highly engaging twitter posts.\n\nevery post have a adequate layout formatting for readability, so use of newlines to separate sections is fundamental.\n\nevery post must have a strong hook which has the goal of capturing the attention of the most amount of users possible.\n\nwithout exaggeration, every post should be highly engaging, potential value proposition must be clear to the users already from the hook.\n\nyou are allowed to use grey hat psychological sales and marketing strategies in order to maximize engagement, such as social proof, false scarcity, curiosity, emotional leverage, artificially crafted data etc\u2026\n\nformatting style should be simple, hashtags should not be used as they are an outdated strategy which is considered cringe as of today. Same goes for emojis as they should be used EXTREMELY sporadically and never to give visual formatting but only to represent common emotional states (example: a laugh \ud83d\ude02)\n\nwhen you are creating longer posts, keep in mind that only the first 280 characters will be visible on the screen without the user having to click and expand the post, thus that first must be well formatted and hook the user.\n\nvisual formatting is very important as users don\u2019t read everything while scrolling but rather they \u201cscan\u201d through words. Short sentences which do not break lines but rather express meaning across only one line, are much better.\n\n### Examples\n\nHook 1: One of the best 7-fig entrepreneurs I know insists I should sell this information\u2026\n\nHook 2: Plot twist: The laziest entrepreneur I know is making 6 figures\n\nHook 3: Starting an AI automation agency and getting to atleast 15k p/m  in 2025 is easier than you think\n\nHook 4: Using this chatgpt prompt is literally like having a $20k growth consultant\n\nHook 5: Here's exactly how to help your clients print with Email Marketing\n\nHook 6: I reverse-engineered $47M in sales copy and discovered why 99% of copywriters / marketers are broke\n\nHook 7: You would 100x your sales skills ( & money made ) instantly if you saw yourself as a therapist  ( not really, but sort of ) \n\nUse dark psychology to your advantage\n\nlemme explain \n\nHook 8: You could quietly flip micro-SaaS apps for $10K\u2013$50K per exit.\n\nHook 9: everyone\u2019s talking about which AI tool is best for ad creatives\u2026\n\nHook 10: this stupidly simple trick makes any LLM noticeable more accurate\n\nHook 11: You could build a million-dollar funnel off nothing but YouTube comments.\n\nHook 12: you can build your first AI automation system and make more than $6,500 in >14 days\n\nHook 13: seeing people build insane n8n workflows that are printing money on autopilot\n\nhere's what the smart ones are doing\n\nPLEASE OUTPUT ONLY THE POST, NOTHING ELSE.\n### User input\n {{ $('Telegram Trigger').item.json.message.text ?? $('Get Chat').last().json.result.pinned_message.text }}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        -120,
        40
      ],
      "id": "b33b51b5-020d-4a2d-bec7-7dde156d3dbf",
      "name": "Create Content"
    },
    {
      "parameters": {
        "chatId": "7558641202",
        "text": "=This is the post I drafted for you:\n\n{{ $json.text }}",
        "replyMarkup": "replyKeyboard",
        "replyKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "\u2705",
                    "additionalFields": {}
                  },
                  {
                    "text": "\ud83d\udd04",
                    "additionalFields": {}
                  }
                ]
              }
            }
          ]
        },
        "replyKeyboardOptions": {
          "one_time_keyboard": true
        },
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        200,
        40
      ],
      "id": "d5113407-8c3c-497f-a046-6045774d0feb",
      "name": "Telegram",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "\ud83d\udd04",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "c64798a3-39a0-48a9-939a-9c35bb41bd45"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "\ud83d\udd04"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "3cf79cb4-334f-4870-bb14-97ead4de610b",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "\u2705",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "\u2705"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "170060fc-d885-4e11-a70a-91cc93d9f29e",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Normal Flow"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -1180,
        120
      ],
      "id": "f232a430-0300-4052-b1b3-6d3ad89eded0",
      "name": "Switch"
    },
    {
      "parameters": {
        "resource": "chat",
        "chatId": "7558641202"
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -620,
        180
      ],
      "id": "4da54676-de44-4057-a172-cd6f2510ba6b",
      "name": "Get Chat",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Listen For Users Messages\n",
        "height": 240,
        "width": 280
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1500,
        40
      ],
      "typeVersion": 1,
      "id": "74883055-5236-4c72-9027-264717dc692a",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "operation": "pinChatMessage",
        "chatId": "7558641202",
        "messageId": "={{ $('Telegram Trigger').item.json.message.message_id }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -960,
        -40
      ],
      "id": "54ba22bd-81bb-4a5c-9c93-5ef3716b2366",
      "name": "Pin Message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Cache Message For Iterations",
        "height": 240,
        "width": 280,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1040,
        -120
      ],
      "typeVersion": 1,
      "id": "ec15ebc2-6ac7-43ac-adca-efa38f401553",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## AI Checks If its a Post Creation Request",
        "height": 220,
        "width": 480,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -740,
        -120
      ],
      "typeVersion": 1,
      "id": "a5524d36-cb20-48bf-8e88-2b46b75f8a38",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Claude Content Generation",
        "height": 400,
        "width": 520,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -140,
        -60
      ],
      "typeVersion": 1,
      "id": "3d54aed9-1b3b-455f-8166-a76565d1df06",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "chatId": "7558641202",
        "text": "\u2705 _Content Creation Completed_",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -620,
        360
      ],
      "id": "a9e6618e-049e-4c4d-ab2f-a2fc410276f6",
      "name": "Operation Completed",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Retrieve Last User Message",
        "height": 200,
        "width": 340,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -740,
        120
      ],
      "typeVersion": 1,
      "id": "a6cb9042-3a05-4692-b346-0aa45cbdc515",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "## Twitter Claude AI Ghostwriter V1\n---\n### Setup\n- **Telegram**: Retrieve `chatId` by using `@get_id_bot`\n- **OpenAI API**\n- **Claude API**\n\nby _@paoloanzn_",
        "height": 240,
        "width": 400,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1500,
        -240
      ],
      "typeVersion": 1,
      "id": "e0597534-5fe2-4aa1-b1e2-ad16835add27",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "operation": "unpinChatMessage",
        "chatId": "7558641202",
        "messageId": "={{ $('Telegram Trigger').item.json.message.message_id }}"
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -140,
        360
      ],
      "id": "e6e3de3d-3aee-4e6e-9e51-ec02d71e1dce",
      "name": "Unpin Message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Create Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Unpin Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Anthropic Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Create Content",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create Content": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram": {
      "main": [
        []
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Get Chat",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Operation Completed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Pin Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Chat": {
      "main": [
        [
          {
            "node": "Create Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pin Message": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Operation Completed": {
      "main": [
        [
          {
            "node": "Unpin Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f2e379dd-5c32-4f19-ba8e-0ce4aa67a7bf",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "nUwAPiuYQDINTnIN",
  "tags": []
}