{
  "name": "X (Twitter) Top Post Research and Rewriter",
  "nodes": [
    {
      "parameters": {
        "url": "=https://api.apify.com/v2/datasets/{{ $json.body.resource.defaultDatasetId }}/items",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "format",
              "value": "json"
            },
            {
              "name": "limit",
              "value": "100"
            },
            {
              "name": "clean",
              "value": "true"
            },
            {
              "name": "simplified",
              "value": "false"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set API Key Apify').item.json.apifyKey }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1500,
        -580
      ],
      "id": "ff2046a1-c29e-4f0f-96e2-6888bddfea96",
      "name": "Get Apify Dataset",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "resume": "webhook",
        "httpMethod": "POST",
        "options": {}
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1280,
        -580
      ],
      "id": "8d869e0e-db4e-4e90-936d-ab641ec9aff2",
      "name": "Wait Run Succeded",
      "webhookId": "9c5a3620-be93-4fd3-9a7a-7a6bd6da0808"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4-turbo",
          "mode": "list",
          "cachedResultName": "GPT-4-TURBO"
        },
        "messages": {
          "values": [
            {
              "content": "You're a helpful, intelligent writing assistant.",
              "role": "system"
            },
            {
              "content": "Rewrite each message in a way that encapsulates the original theme but uses different words."
            },
            {
              "content": "=Most small businesses don't have a lead problem. They have a follow-up problem.\n\nHalf of all enquiries never get a second touch.\n\nWould a thread on how to fix that be useful?"
            },
            {
              "content": "The real issue for most small businesses isn't finding leads, it's following up on them. Around half of enquiries never hear back a second time. Want a breakdown of how to fix it?",
              "role": "assistant"
            },
            {
              "content": "={{ $('Get Apify Dataset').item.json.full_text }}"
            }
          ]
        },
        "options": {
          "maxTokens": 4096
        }
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        1760,
        -580
      ],
      "id": "609a45ce-b565-4f8d-be93-ba83f2f1d0b7",
      "name": "Reword Tweets",
      "retryOnFail": true,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Tweets"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Copy Post": "={{ $json.message.content }}",
            "Original Post": "={{ $('Get Apify Dataset').item.json.full_text }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Original Post",
              "displayName": "Original Post",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Copy Post",
              "displayName": "Copy Post",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2120,
        -580
      ],
      "id": "9a60f6a1-965b-4c23-9398-09bd82cf9f9a",
      "name": "Add Tweets to Sheet"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        620,
        -580
      ],
      "id": "dfe4c901-5e5f-4f1e-82c8-0f6d1bd25105",
      "name": "When clicking ‘Test workflow’"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/quacker~twitter-scraper/runs",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "webhooks",
              "value": "={{ `[ { \"eventTypes\": [\"ACTOR.RUN.SUCCEEDED\"], \"requestUrl\": \"${$execution.resumeUrl}\" } ]`.base64Encode() }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "="
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"addUserInfo\": true,\n  \"handles\": [\n    \"example_creator\"\n  ],\n  \"proxyConfig\": {\n    \"useApifyProxy\": true\n  },\n  \"tweetsDesired\": 20\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1060,
        -580
      ],
      "id": "27d6cca7-f386-4372-bf4d-0780866504f6",
      "name": "Run Twitter Scrape Actor Apify"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1986c329-0c29-42e8-b594-a436dffb06c8",
              "name": "apifyKey",
              "value": "YOUR_APIFY_API_TOKEN",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        840,
        -580
      ],
      "id": "1f7b03b0-efeb-475a-99d6-cf8128c3be16",
      "name": "Set API Key Apify"
    }
  ],
  "connections": {
    "Wait Run Succeded": {
      "main": [
        [
          {
            "node": "Get Apify Dataset",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Apify Dataset": {
      "main": [
        [
          {
            "node": "Reword Tweets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reword Tweets": {
      "main": [
        [
          {
            "node": "Add Tweets to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Set API Key Apify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Twitter Scrape Actor Apify": {
      "main": [
        [
          {
            "node": "Wait Run Succeded",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set API Key Apify": {
      "main": [
        [
          {
            "node": "Run Twitter Scrape Actor Apify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
