{
  "id": "t8oEobLfpjA17NYw",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Auto-Generate Trending X, Facebook & Thread Posts (Apify + Gemini + Buffer)",
  "tags": [],
  "nodes": [
    {
      "id": "b107a109-eeb2-4c63-a990-5da265d284f5",
      "name": "Create a data table",
      "type": "n8n-nodes-base.dataTable",
      "onError": "continueRegularOutput",
      "disabled": true,
      "position": [
        672,
        -1840
      ],
      "parameters": {
        "columns": {
          "column": [
            {
              "name": "trend"
            },
            {
              "name": "date"
            }
          ]
        },
        "options": {},
        "resource": "table",
        "operation": "create",
        "tableName": "trend_table"
      },
      "executeOnce": false,
      "typeVersion": 1.1
    },
    {
      "id": "dc4e83a2-073e-4565-9a2a-464d5c51a1b0",
      "name": "Filter Last 24h",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        1168,
        -1840
      ],
      "parameters": {
        "jsCode": "const allTrends = $input.all();\n\n// Get used trends from Get Used Trends (deduplicate by id)\nlet usedTrendsItems = [];\ntry {\n  const raw = $node[\"Get Used Trends\"].all();\n  // Deduplicate by id - keeps only first occurrence of each id\n  const seen = new Set();\n  usedTrendsItems = raw.filter(item => {\n    const id = item.json.id;\n    if (seen.has(id)) return false;\n    seen.add(id);\n    return true;\n  });\n} catch (e) {\n  usedTrendsItems = [];\n}\n\nconst oneDay = 24 * 60 * 60 * 1000;\nconst now = new Date();\n\nconst recentUsed = usedTrendsItems\n  .filter(item => {\n    if (!item.json.date) return false;\n    const d = new Date(item.json.date);\n    if (isNaN(d.getTime())) return false;\n    return (now - d) < oneDay;\n  })\n  .map(item => (item.json.trend || \"\").trim().toLowerCase());\n\nconst availableTrends = allTrends.filter(item => {\n  const trend = (item.json.trend || \"\").trim().toLowerCase();\n  return !recentUsed.includes(trend);\n});\n\nreturn availableTrends.map(item => ({ json: { trend: item.json.trend } }));"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "d1dafc4d-8f13-4941-893b-4bfc7a6752ad",
      "name": "Remove Used Trends",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        1472,
        -1840
      ],
      "parameters": {
        "jsCode": "// Get used trends from previous node\nconst used = $input.all().map(i => i.json.trend || \"\");\n\n// Get current trends from \"Split Trend\" node\nconst current = $items(\"Split Trend1\") || []; // Make sure node name matches\n\n// Filter out used ones\nconst filtered = current.filter(item => !used.includes(item.json.trend));\n\n// Return empty array if none left\nreturn filtered.length > 0 ? filtered : [];"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "626494c5-a8fd-4a71-9055-e8b03ad776f2",
      "name": "Pick Trend",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        1808,
        -1840
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// Pick the first 2 trends from the list\nconst picked = items.slice(0, 1);\n\nreturn picked.map(item => ({\n  json: {\n    trend: item.json?.trend?.json?.trend || item.json?.trend\n  }\n}));"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "d338fd0a-f497-4d8a-9936-bd1225b5bf7f",
      "name": "trend ",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "onError": "continueErrorOutput",
      "position": [
        2736,
        -1760
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "= generate a short tweet base on this x.com trend: {{ $json.trend }} . The generated tweet must be base on live events, react to the contextuse pidgin + casual tone. only one otion, no **\\n, maximum of 275 characters."
            }
          ]
        },
        "builtInTools": {
          "googleSearch": true
        }
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "ef11a0be-c621-467c-bcc6-8e2029d50ac2",
      "name": "Post only tweets",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "notes": "Twiiter Auto post",
      "position": [
        3824,
        -1520
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "create_post",
          "cachedResultName": "create_post"
        },
        "options": {},
        "parameters": {
          "value": {
            "text": "={{ $('Extract Tweet Text').item.json.tweet }}",
            "channelId": "69ce9bddaf47dacb6980757d",
            "schedulingType": "automatic"
          },
          "schema": [
            {
              "id": "channelId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "channelId",
              "defaultMatch": false
            },
            {
              "id": "schedulingType",
              "type": "options",
              "display": true,
              "options": [
                {
                  "name": "notification",
                  "value": "notification"
                },
                {
                  "name": "automatic",
                  "value": "automatic"
                }
              ],
              "removed": false,
              "required": true,
              "displayName": "schedulingType",
              "defaultMatch": false
            },
            {
              "id": "mode",
              "type": "options",
              "display": true,
              "options": [
                {
                  "name": "addToQueue",
                  "value": "addToQueue"
                },
                {
                  "name": "shareNow",
                  "value": "shareNow"
                },
                {
                  "name": "shareNext",
                  "value": "shareNext"
                },
                {
                  "name": "customScheduled",
                  "value": "customScheduled"
                },
                {
                  "name": "recommendedTime",
                  "value": "recommendedTime"
                }
              ],
              "removed": true,
              "required": false,
              "displayName": "mode",
              "defaultMatch": false
            },
            {
              "id": "text",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "text",
              "defaultMatch": false
            },
            {
              "id": "dueAt",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dueAt",
              "defaultMatch": false
            },
            {
              "id": "tagIds",
              "type": "array",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "tagIds",
              "defaultMatch": false,
              "defaultValue": "[\n  \"string\"\n]"
            },
            {
              "id": "assets",
              "type": "object",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "assets",
              "defaultMatch": false,
              "defaultValue": "{\n  \"images\": [\n    {\n      \"url\": \"string\",\n      \"thumbnailUrl\": \"string\",\n      \"metadata\": {\n        \"altText\": \"string\",\n        \"animatedThumbnail\": \"string\",\n        \"userTags\": [\n          {\n            \"handle\": \"string\",\n            \"x\": 0,\n            \"y\": 0\n          }\n        ],\n        \"dimensions\": {\n          \"width\": 0,\n          \"height\": 0\n        }\n      }\n    }\n  ],\n  \"videos\": [\n    {\n      \"url\": \"string\",\n      \"thumbnailUrl\": \"string\",\n      \"metadata\": {\n        \"thumbnailOffset\": 0,\n        \"title\": \"string\"\n      }\n    }\n  ],\n  \"documents\": [\n    {\n      \"url\": \"string\",\n      \"title\": \"string\",\n      \"thumbnailUrl\": \"string\"\n    }\n  ],\n  \"link\": {\n    \"url\": \"string\",\n    \"title\": \"string\",\n    \"description\": \"string\",\n    \"thumbnailUrl\": \"string\"\n  }\n}"
            },
            {
              "id": "metadata",
              "type": "object",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "metadata",
              "defaultMatch": false,
              "defaultValue": "{\n  \"instagram\": {\n    \"type\": \"story\",\n    \"link\": \"string\",\n    \"geolocation\": {\n      \"id\": \"string\",\n      \"text\": \"string\"\n    },\n    \"shouldShareToFeed\": false,\n    \"stickerFields\": {\n      \"text\": \"string\"\n    }\n  },\n  \"facebook\": {\n    \"type\": \"post\",\n    \"annotations\": [\n      {\n        \"content\": \"string\",\n        \"indices\": [\n          0\n        ],\n        \"text\": \"string\",\n        \"url\": \"string\"\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"linkedin\": {\n    \"annotations\": [\n      {\n        \"id\": \"string\",\n        \"link\": \"string\",\n        \"entity\": \"string\",\n        \"vanityName\": \"string\",\n        \"localizedName\": \"string\",\n        \"start\": 0,\n        \"length\": 0\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"twitter\": {\n    \"retweet\": {\n      \"id\": \"string\"\n    },\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ]\n  },\n  \"pinterest\": {\n    \"title\": \"string\",\n    \"url\": \"string\",\n    \"boardServiceId\": \"string\"\n  },\n  \"google\": {\n    \"type\": \"event\",\n    \"title\": \"string\",\n    \"detailsOffer\": {\n      \"title\": \"string\",\n      \"startDate\": \"string\",\n      \"endDate\": \"string\",\n      \"code\": \"string\",\n      \"link\": \"string\",\n      \"terms\": \"string\"\n    },\n    \"detailsEvent\": {\n      \"title\": \"string\",\n      \"startDate\": \"string\",\n      \"endDate\": \"string\",\n      \"isFullDayEvent\": false,\n      \"button\": \"none\",\n      \"link\": \"string\"\n    },\n    \"detailsWhatsNew\": {\n      \"button\": \"none\",\n      \"link\": \"string\"\n    }\n  },\n  \"youtube\": {\n    \"title\": \"string\",\n    \"categoryId\": \"string\",\n    \"privacy\": \"public\",\n    \"license\": \"youtube\",\n    \"notifySubscribers\": false,\n    \"embeddable\": false,\n    \"madeForKids\": false\n  },\n  \"mastodon\": {\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"spoilerText\": \"string\"\n  },\n  \"startPage\": {\n    \"link\": \"string\"\n  },\n  \"threads\": {\n    \"type\": \"post\",\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    },\n    \"topic\": \"string\",\n    \"locationId\": \"string\",\n    \"locationName\": \"string\"\n  },\n  \"bluesky\": {\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"tiktok\": {\n    \"title\": \"string\"\n  }\n}"
            },
            {
              "id": "saveToDraft",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "saveToDraft",
              "defaultMatch": false
            },
            {
              "id": "ideaId",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "ideaId",
              "defaultMatch": false
            },
            {
              "id": "draftId",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "draftId",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.buffer.com/mcp",
        "authentication": "bearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8fb3c429-59bc-4cbe-bc99-35dfe2e73088",
      "name": "Get Used Trends",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        896,
        -1840
      ],
      "parameters": {
        "operation": "get",
        "returnAll": true,
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "yJnzJvRdKazvvCuY",
          "cachedResultUrl": "/projects/vXqhDNlXbSeCxe2L/datatables/yJnzJvRdKazvvCuY",
          "cachedResultName": "trend_table"
        }
      },
      "typeVersion": 1.1,
      "alwaysOutputData": true
    },
    {
      "id": "b14475e9-6542-4ca7-95c2-c45bd09989d6",
      "name": "Insert row",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        4192,
        -1520
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ $json.usedAt }}",
            "trend": "={{ $json.trend }}"
          },
          "schema": [
            {
              "id": "trend",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "trend",
              "defaultMatch": false
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "date",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "yJnzJvRdKazvvCuY",
          "cachedResultUrl": "/projects/vXqhDNlXbSeCxe2L/datatables/yJnzJvRdKazvvCuY",
          "cachedResultName": "trend_table"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "1e08bfc3-d2d4-4e6f-a930-f9e4b7e77413",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2432,
        -1840
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "d17261f1-4db9-4dbf-83c7-f4a0622faa26",
      "name": "Run an Actor and get dataset1",
      "type": "@apify/n8n-nodes-apify.apify",
      "onError": "continueRegularOutput",
      "position": [
        -1936,
        -1824
      ],
      "parameters": {
        "actorId": {
          "__rl": true,
          "mode": "list",
          "value": "VPeCKacMZL2Lgem5t",
          "cachedResultUrl": "https://console.apify.com/actors/VPeCKacMZL2Lgem5t/input",
          "cachedResultName": "Twitter Trending Topics Scraper \ud83c\udf0e (easyapi/twitter-trending-topics-scraper)"
        },
        "timeout": {},
        "operation": "Run actor and get dataset",
        "customBody": "{\n    \"country\": \"nigeria\",\n    \"proxyConfiguration\": {\n        \"useApifyProxy\": false\n    }\n}"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "89290157-aa85-4e8c-be76-ae7059c4a63d",
      "name": "Schedule Trigger1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -3056,
        -1984
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "=0 8,12,16 * * *"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e83f48f4-72cd-4f6d-9a8b-a7e93c3634c1",
      "name": "Get Daily x trends1",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "onError": "continueErrorOutput",
      "position": [
        -944,
        -1696
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "pull today Nigeria specific trends of https://x.com/explore from to various third party trend tracking sites on search. Only output the trend words or phrases themselves, one per line. \n- Do NOT include descriptions, explanations, hashtags about other things, or any extra text. \n- Include both hashtags and plain words if trending, if none for x.com trends, get trends of other social media or google search or google trending. \n- Output format example:\n\nTrend1\nTrend2\nTrend3\n..."
            }
          ]
        },
        "builtInTools": {
          "urlContext": false,
          "googleSearch": true
        }
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1,
      "alwaysOutputData": true
    },
    {
      "id": "a7910585-766e-44ee-bc83-4a53f58e86e4",
      "name": "Run an Actor and get dataset2",
      "type": "@apify/n8n-nodes-apify.apify",
      "onError": "continueRegularOutput",
      "position": [
        -2816,
        -1984
      ],
      "parameters": {
        "actorId": {
          "__rl": true,
          "mode": "list",
          "value": "VPeCKacMZL2Lgem5t",
          "cachedResultUrl": "https://console.apify.com/actors/VPeCKacMZL2Lgem5t/input",
          "cachedResultName": "Twitter Trending Topics Scraper \ud83c\udf0e (easyapi/twitter-trending-topics-scraper)"
        },
        "timeout": {},
        "operation": "Run actor and get dataset",
        "customBody": "{\n    \"country\": \"nigeria\",\n    \"proxyConfiguration\": {\n        \"useApifyProxy\": false\n    }\n}"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "29943589-0da1-41cc-a25a-aa82c66ed1c9",
      "name": "Extract Trends3",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        -2576,
        -1984
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// Check for Apify error\nconst firstItem = items[0]?.json;\nif (!firstItem || firstItem.error) {\n  return [{ json: { success: false, error: firstItem?.error || \"No data received\" } }];\n}\n\nconst trends = items.flatMap(item => {\n  const data = item.json;\n  const records = Array.isArray(data) ? data : [data];\n  return records.map(record => ({\n    json: { trend: record.title }\n  }));\n});\n\n// Check if trends are actually empty or titles are missing\nif (trends.length === 0 || trends.every(t => !t.json.trend)) {\n  return [{ json: { success: false, error: \"No valid trend data found\" } }];\n}\n\nreturn [{ json: { success: true, trends } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "d16ce625-5e2e-468b-8171-14a8aded9eb2",
      "name": "If3",
      "type": "n8n-nodes-base.if",
      "position": [
        -2288,
        -1984
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "163328ab-270c-4abe-a261-1c5acce7acb8",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.success }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "d8b5220d-1fa0-41fc-b305-7a0583baf917",
      "name": "Extract Trends4",
      "type": "n8n-nodes-base.code",
      "position": [
        -288,
        -1648
      ],
      "parameters": {
        "jsCode": "// Get the text from AI node\nconst text = $json[\"content\"]?.parts?.[0]?.text;\n\nif (!text) {\n    throw new Error(\"AI output not found. Check the node name or output structure.\");\n}\n\n// Split by newlines, trim each line, and remove empty lines\nconst trends = text\n    .split('\\n')\n    .map(t => t.trim())\n    .filter(Boolean);\n\n// Return as a single item\nreturn [{ json: { trends } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "ad183f7f-e735-4b63-9aa3-a6bb429a36bb",
      "name": "Extract Trends5",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        -1552,
        -1824
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// Check for Apify error\nconst firstItem = items[0]?.json;\nif (!firstItem || firstItem.error) {\n  return [{ json: { success: false, error: firstItem?.error || \"No data received\" } }];\n}\n\nconst trends = items.flatMap(item => {\n  const data = item.json;\n  const records = Array.isArray(data) ? data : [data];\n  return records.map(record => ({\n    json: { trend: record.title }\n  }));\n});\n\n// Check if trends are actually empty or titles are missing\nif (trends.length === 0 || trends.every(t => !t.json.trend)) {\n  return [{ json: { success: false, error: \"No valid trend data found\" } }];\n}\n\nreturn [{ json: { success: true, trends } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "e4e56b6c-22e4-47f1-aa04-d1279b194ad3",
      "name": "If4",
      "type": "n8n-nodes-base.if",
      "position": [
        -1136,
        -1824
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "163328ab-270c-4abe-a261-1c5acce7acb8",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.success }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "9591ce41-2b93-47e2-b182-197839b96baf",
      "name": "Split Trend",
      "type": "n8n-nodes-base.code",
      "position": [
        -128,
        -1648
      ],
      "parameters": {
        "jsCode": "const trends = $json.trends;\n\nreturn trends.map(trend => ({\n  json: { trend }\n}));"
      },
      "typeVersion": 2
    },
    {
      "id": "2624f48b-6358-4639-98e2-a8e99c56bf0e",
      "name": "Split Trend Apify",
      "type": "n8n-nodes-base.code",
      "position": [
        -368,
        -2000
      ],
      "parameters": {
        "jsCode": "const trends = $json.trends;\n\nreturn trends.map(trend => ({\n  json: { trend }\n}));"
      },
      "typeVersion": 2
    },
    {
      "id": "508308fc-ba02-4297-98f7-efe1ae1800c1",
      "name": "Split Trend1",
      "type": "n8n-nodes-base.merge",
      "position": [
        192,
        -1664
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "ee0dcb80-70d0-4158-bf83-a94ad0df2a21",
      "name": "facebook post",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "notes": "Twiiter Auto post",
      "position": [
        3824,
        -1712
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "create_post",
          "cachedResultName": "create_post"
        },
        "options": {},
        "parameters": {
          "value": {
            "text": "={{ $('Extract Tweet Text').item.json.tweet }}",
            "metadata": "{\n \n  \"facebook\": {\n    \"type\": \"post\"\n  }\n}",
            "channelId": "690c55cb5bd637c1835edc4d",
            "schedulingType": "automatic"
          },
          "schema": [
            {
              "id": "channelId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "channelId",
              "defaultMatch": false
            },
            {
              "id": "schedulingType",
              "type": "options",
              "display": true,
              "options": [
                {
                  "name": "notification",
                  "value": "notification"
                },
                {
                  "name": "automatic",
                  "value": "automatic"
                }
              ],
              "removed": false,
              "required": true,
              "displayName": "schedulingType",
              "defaultMatch": false
            },
            {
              "id": "mode",
              "type": "options",
              "display": true,
              "options": [
                {
                  "name": "addToQueue",
                  "value": "addToQueue"
                },
                {
                  "name": "shareNow",
                  "value": "shareNow"
                },
                {
                  "name": "shareNext",
                  "value": "shareNext"
                },
                {
                  "name": "customScheduled",
                  "value": "customScheduled"
                },
                {
                  "name": "recommendedTime",
                  "value": "recommendedTime"
                }
              ],
              "removed": true,
              "required": false,
              "displayName": "mode",
              "defaultMatch": false
            },
            {
              "id": "text",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "text",
              "defaultMatch": false
            },
            {
              "id": "dueAt",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dueAt",
              "defaultMatch": false
            },
            {
              "id": "tagIds",
              "type": "array",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "tagIds",
              "defaultMatch": false,
              "defaultValue": "[\n  \"string\"\n]"
            },
            {
              "id": "assets",
              "type": "object",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "assets",
              "defaultMatch": false,
              "defaultValue": "{\n  \"images\": [\n    {\n      \"url\": \"string\",\n      \"thumbnailUrl\": \"string\",\n      \"metadata\": {\n        \"altText\": \"string\",\n        \"animatedThumbnail\": \"string\",\n        \"userTags\": [\n          {\n            \"handle\": \"string\",\n            \"x\": 0,\n            \"y\": 0\n          }\n        ],\n        \"dimensions\": {\n          \"width\": 0,\n          \"height\": 0\n        }\n      }\n    }\n  ],\n  \"videos\": [\n    {\n      \"url\": \"string\",\n      \"thumbnailUrl\": \"string\",\n      \"metadata\": {\n        \"thumbnailOffset\": 0,\n        \"title\": \"string\"\n      }\n    }\n  ],\n  \"documents\": [\n    {\n      \"url\": \"string\",\n      \"title\": \"string\",\n      \"thumbnailUrl\": \"string\"\n    }\n  ],\n  \"link\": {\n    \"url\": \"string\",\n    \"title\": \"string\",\n    \"description\": \"string\",\n    \"thumbnailUrl\": \"string\"\n  }\n}"
            },
            {
              "id": "metadata",
              "type": "object",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "metadata",
              "defaultMatch": false,
              "defaultValue": "{\n  \"instagram\": {\n    \"type\": \"story\",\n    \"link\": \"string\",\n    \"geolocation\": {\n      \"id\": \"string\",\n      \"text\": \"string\"\n    },\n    \"shouldShareToFeed\": false,\n    \"stickerFields\": {\n      \"text\": \"string\"\n    }\n  },\n  \"facebook\": {\n    \"type\": \"post\",\n    \"annotations\": [\n      {\n        \"content\": \"string\",\n        \"indices\": [\n          0\n        ],\n        \"text\": \"string\",\n        \"url\": \"string\"\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"linkedin\": {\n    \"annotations\": [\n      {\n        \"id\": \"string\",\n        \"link\": \"string\",\n        \"entity\": \"string\",\n        \"vanityName\": \"string\",\n        \"localizedName\": \"string\",\n        \"start\": 0,\n        \"length\": 0\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"twitter\": {\n    \"retweet\": {\n      \"id\": \"string\"\n    },\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ]\n  },\n  \"pinterest\": {\n    \"title\": \"string\",\n    \"url\": \"string\",\n    \"boardServiceId\": \"string\"\n  },\n  \"google\": {\n    \"type\": \"event\",\n    \"title\": \"string\",\n    \"detailsOffer\": {\n      \"title\": \"string\",\n      \"startDate\": \"string\",\n      \"endDate\": \"string\",\n      \"code\": \"string\",\n      \"link\": \"string\",\n      \"terms\": \"string\"\n    },\n    \"detailsEvent\": {\n      \"title\": \"string\",\n      \"startDate\": \"string\",\n      \"endDate\": \"string\",\n      \"isFullDayEvent\": false,\n      \"button\": \"none\",\n      \"link\": \"string\"\n    },\n    \"detailsWhatsNew\": {\n      \"button\": \"none\",\n      \"link\": \"string\"\n    }\n  },\n  \"youtube\": {\n    \"title\": \"string\",\n    \"categoryId\": \"string\",\n    \"privacy\": \"public\",\n    \"license\": \"youtube\",\n    \"notifySubscribers\": false,\n    \"embeddable\": false,\n    \"madeForKids\": false\n  },\n  \"mastodon\": {\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"spoilerText\": \"string\"\n  },\n  \"startPage\": {\n    \"link\": \"string\"\n  },\n  \"threads\": {\n    \"type\": \"post\",\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    },\n    \"topic\": \"string\",\n    \"locationId\": \"string\",\n    \"locationName\": \"string\"\n  },\n  \"bluesky\": {\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"tiktok\": {\n    \"title\": \"string\"\n  }\n}"
            },
            {
              "id": "saveToDraft",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "saveToDraft",
              "defaultMatch": false
            },
            {
              "id": "ideaId",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "ideaId",
              "defaultMatch": false
            },
            {
              "id": "draftId",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "draftId",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.buffer.com/mcp",
        "authentication": "bearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "80137244-c643-428b-a370-844362f87f18",
      "name": "Thread post",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "notes": "Twiiter Auto post",
      "position": [
        3824,
        -1936
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "create_post",
          "cachedResultName": "create_post"
        },
        "options": {},
        "parameters": {
          "value": {
            "text": "={{ $('Extract Tweet Text').item.json.tweet }}",
            "channelId": "69d3b3f4031bfa423cd55a9f",
            "schedulingType": "automatic"
          },
          "schema": [
            {
              "id": "channelId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "channelId",
              "defaultMatch": false
            },
            {
              "id": "schedulingType",
              "type": "options",
              "display": true,
              "options": [
                {
                  "name": "notification",
                  "value": "notification"
                },
                {
                  "name": "automatic",
                  "value": "automatic"
                }
              ],
              "removed": false,
              "required": true,
              "displayName": "schedulingType",
              "defaultMatch": false
            },
            {
              "id": "mode",
              "type": "options",
              "display": true,
              "options": [
                {
                  "name": "addToQueue",
                  "value": "addToQueue"
                },
                {
                  "name": "shareNow",
                  "value": "shareNow"
                },
                {
                  "name": "shareNext",
                  "value": "shareNext"
                },
                {
                  "name": "customScheduled",
                  "value": "customScheduled"
                },
                {
                  "name": "recommendedTime",
                  "value": "recommendedTime"
                }
              ],
              "removed": true,
              "required": false,
              "displayName": "mode",
              "defaultMatch": false
            },
            {
              "id": "text",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "text",
              "defaultMatch": false
            },
            {
              "id": "dueAt",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dueAt",
              "defaultMatch": false
            },
            {
              "id": "tagIds",
              "type": "array",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "tagIds",
              "defaultMatch": false,
              "defaultValue": "[\n  \"string\"\n]"
            },
            {
              "id": "assets",
              "type": "object",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "assets",
              "defaultMatch": false,
              "defaultValue": "{\n  \"images\": [\n    {\n      \"url\": \"string\",\n      \"thumbnailUrl\": \"string\",\n      \"metadata\": {\n        \"altText\": \"string\",\n        \"animatedThumbnail\": \"string\",\n        \"userTags\": [\n          {\n            \"handle\": \"string\",\n            \"x\": 0,\n            \"y\": 0\n          }\n        ],\n        \"dimensions\": {\n          \"width\": 0,\n          \"height\": 0\n        }\n      }\n    }\n  ],\n  \"videos\": [\n    {\n      \"url\": \"string\",\n      \"thumbnailUrl\": \"string\",\n      \"metadata\": {\n        \"thumbnailOffset\": 0,\n        \"title\": \"string\"\n      }\n    }\n  ],\n  \"documents\": [\n    {\n      \"url\": \"string\",\n      \"title\": \"string\",\n      \"thumbnailUrl\": \"string\"\n    }\n  ],\n  \"link\": {\n    \"url\": \"string\",\n    \"title\": \"string\",\n    \"description\": \"string\",\n    \"thumbnailUrl\": \"string\"\n  }\n}"
            },
            {
              "id": "metadata",
              "type": "object",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "metadata",
              "defaultMatch": false,
              "defaultValue": "{\n  \"instagram\": {\n    \"type\": \"story\",\n    \"link\": \"string\",\n    \"geolocation\": {\n      \"id\": \"string\",\n      \"text\": \"string\"\n    },\n    \"shouldShareToFeed\": false,\n    \"stickerFields\": {\n      \"text\": \"string\"\n    }\n  },\n  \"facebook\": {\n    \"type\": \"post\",\n    \"annotations\": [\n      {\n        \"content\": \"string\",\n        \"indices\": [\n          0\n        ],\n        \"text\": \"string\",\n        \"url\": \"string\"\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"linkedin\": {\n    \"annotations\": [\n      {\n        \"id\": \"string\",\n        \"link\": \"string\",\n        \"entity\": \"string\",\n        \"vanityName\": \"string\",\n        \"localizedName\": \"string\",\n        \"start\": 0,\n        \"length\": 0\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"twitter\": {\n    \"retweet\": {\n      \"id\": \"string\"\n    },\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ]\n  },\n  \"pinterest\": {\n    \"title\": \"string\",\n    \"url\": \"string\",\n    \"boardServiceId\": \"string\"\n  },\n  \"google\": {\n    \"type\": \"event\",\n    \"title\": \"string\",\n    \"detailsOffer\": {\n      \"title\": \"string\",\n      \"startDate\": \"string\",\n      \"endDate\": \"string\",\n      \"code\": \"string\",\n      \"link\": \"string\",\n      \"terms\": \"string\"\n    },\n    \"detailsEvent\": {\n      \"title\": \"string\",\n      \"startDate\": \"string\",\n      \"endDate\": \"string\",\n      \"isFullDayEvent\": false,\n      \"button\": \"none\",\n      \"link\": \"string\"\n    },\n    \"detailsWhatsNew\": {\n      \"button\": \"none\",\n      \"link\": \"string\"\n    }\n  },\n  \"youtube\": {\n    \"title\": \"string\",\n    \"categoryId\": \"string\",\n    \"privacy\": \"public\",\n    \"license\": \"youtube\",\n    \"notifySubscribers\": false,\n    \"embeddable\": false,\n    \"madeForKids\": false\n  },\n  \"mastodon\": {\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"spoilerText\": \"string\"\n  },\n  \"startPage\": {\n    \"link\": \"string\"\n  },\n  \"threads\": {\n    \"type\": \"post\",\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    },\n    \"topic\": \"string\",\n    \"locationId\": \"string\",\n    \"locationName\": \"string\"\n  },\n  \"bluesky\": {\n    \"thread\": [\n      {\n        \"text\": \"string\",\n        \"assets\": {\n          \"images\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"altText\": \"string\",\n                \"animatedThumbnail\": \"string\",\n                \"userTags\": [\n                  {\n                    \"handle\": \"string\",\n                    \"x\": 0,\n                    \"y\": 0\n                  }\n                ],\n                \"dimensions\": {\n                  \"width\": 0,\n                  \"height\": 0\n                }\n              }\n            }\n          ],\n          \"videos\": [\n            {\n              \"url\": \"string\",\n              \"thumbnailUrl\": \"string\",\n              \"metadata\": {\n                \"thumbnailOffset\": 0,\n                \"title\": \"string\"\n              }\n            }\n          ],\n          \"documents\": [\n            {\n              \"url\": \"string\",\n              \"title\": \"string\",\n              \"thumbnailUrl\": \"string\"\n            }\n          ],\n          \"link\": {\n            \"url\": \"string\",\n            \"title\": \"string\",\n            \"description\": \"string\",\n            \"thumbnailUrl\": \"string\"\n          }\n        }\n      }\n    ],\n    \"linkAttachment\": {\n      \"url\": \"string\"\n    }\n  },\n  \"tiktok\": {\n    \"title\": \"string\"\n  }\n}"
            },
            {
              "id": "saveToDraft",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "saveToDraft",
              "defaultMatch": false
            },
            {
              "id": "ideaId",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "ideaId",
              "defaultMatch": false
            },
            {
              "id": "draftId",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "draftId",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.buffer.com/mcp",
        "authentication": "bearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b29a84a4-438d-4430-acd3-7b4dbe2a447e",
      "name": "Extract Tweet Text",
      "type": "n8n-nodes-base.code",
      "position": [
        3424,
        -1872
      ],
      "parameters": {
        "jsCode": "const content = $json.content;\n\n// Handle direct text response\nif (content?.parts?.[0]?.text) {\n  return [{ json: { tweet: content.parts[0].text } }];\n}\n\n// Handle when Gemini used a tool/function call - text may be in a different part\nif (Array.isArray(content?.parts)) {\n  const textPart = content.parts.find(p => p.text);\n  if (textPart) {\n    return [{ json: { tweet: textPart.text } }];\n  }\n}\n\n// Fallback: check candidates structure (some Gemini versions return this)\nif ($json.candidates?.[0]?.content?.parts?.[0]?.text) {\n  return [{ json: { tweet: $json.candidates[0].content.parts[0].text } }];\n}\n\nthrow new Error('Could not extract tweet text from Gemini response. Raw: ' + JSON.stringify($json).slice(0, 300));"
      },
      "typeVersion": 2
    },
    {
      "id": "1d8d3e58-f5b9-43e3-ba15-c5030b430cf4",
      "name": "Generate Tweet (HTTP Fallback)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3280,
        -1696
      ],
      "parameters": {
        "url": "=https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"=Based on what you know about the current real-world context of this trending topic: '{{ $json.trend }}', generate a complete, ready-to-post tweet. Use pidgin + casual tone, react to recent events around the trend. Rules: only one tweet, no **, no newlines, no incomplete sentences, must be a complete thought, maximum 275 characters. Output only the tweet text, nothing else.\"\n        }\n      ]\n    }\n  ],\n  \"generationConfig\": {\n    \"maxOutputTokens\": 1024,\n    \"stopSequences\": []\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "googlePalmApi"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "e3695a90-e841-4e34-9617-1d9417eb409e",
      "name": "Gemini Success",
      "type": "n8n-nodes-base.if",
      "position": [
        3120,
        -1856
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cc9b1349-c799-4ad9-94b8-55f2c31135a4",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "=={{ $json.content.parts[0].text }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "bafe9db4-a8b6-4505-8593-6718078ce0f3",
      "name": "Generate Tweet (HTTP Fallback)1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -464,
        -1376
      ],
      "parameters": {
        "url": "=https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"pull today or recent Nigeria specific trends of https://x.com/ from to various trend tracking sites on google search, if none search for other trending trends of other social media or google trending.List ONLY current or recent Nigeria trending topics.\\n\\nRules:\\n- Output ONLY the trend words or phrases.\\n- One trend per line.\\n- No explanations, no numbering, no bullets, no extra text.\\n- Do not add anything before or after the list.\\n- Include hashtags if they are part of the trend.\\n- If no Nigeria trends are found, return general global trends.\\n\\nOutput example:\\nTrend1\\nTrend2\\nTrend3\"\n        }\n      ]\n    }\n  ],\n  \"generationConfig\": {\n    \"maxOutputTokens\": 512,\n    \"temperature\": 0.2,\n    \"stopSequences\": [\"\\n\\n\"]\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "googlePalmApi"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "63d55a1b-fa33-4fdd-b71d-2d00613239fc",
      "name": "Gemini Success1",
      "type": "n8n-nodes-base.if",
      "position": [
        -512,
        -1632
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cc9b1349-c799-4ad9-94b8-55f2c31135a4",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{$json[\"content\"][\"parts\"][0][\"text\"]}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "1c9ad680-1fb2-4f17-bdef-915d1958733c",
      "name": "\ud83d\udccb Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3936,
        -2208
      ],
      "parameters": {
        "color": 4,
        "width": 780,
        "height": 1080,
        "content": "## Auto-Generate Trending X, Facebook & Thread Posts (Apify + Gemini + Buffer)\n\n**What this workflow does:**\nEvery day at 8:00am, 12:30pm, and 4:30pm it:\n1. Scrapes Nigeria's trending X topics via Apify\n2. Falls back to Gemini AI search if Apify fails\n3. Filters out trends used in the last 24h (deduplication)\n4. Picks the top 2 unused trends\n5. Generates a pidgin-language tweet per trend using Gemini 2.5 Flash\n6. Posts tweet to X and posts to thread and facebook via Buffer MCP\n\n---\n### \ud83d\udd27 Setup Required\n- **Apify** \u2013 Connect your Apify API credential\n- **Google Gemini** \u2013 Connect your Google AI (Gemini) credential\n- **Buffer** \u2013 Connect your Buffer Bearer Token credential and set your Channel ID in the `Post to X, thread, and facebook via Buffer` node\n- **Data Table** \u2013 The `trend_table` Data Table must exist in your n8n project (run `Create a data table` once manually, then disable it)\n\n---\n### \u2699\ufe0f Customization\n- Change the `country` in the Apify nodes to scrape trends for a different country\n- Edit the tweet prompt in `Generate Tweet with Gemini` to change tone/language/style\n-  Adjust the schedule in `Schedule Trigger` (currently 3x/day)"
      },
      "typeVersion": 1
    },
    {
      "id": "880950a5-960e-4078-b78b-fd86f97c18f7",
      "name": "Section: Trend Fetching",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3088,
        -2208
      ],
      "parameters": {
        "color": 7,
        "width": 3492,
        "height": 1068,
        "content": "### 1\ufe0f\u20e3 Fetch Nigeria Trends\nApify scrapes X trending topics for Nigeria.\nIf both Apify fails or returns no data, falls back to Gemini AI search.\nBoth paths merge at `Split Trend1`"
      },
      "typeVersion": 1
    },
    {
      "id": "5d4074a8-4d9a-4a1b-9bc0-e4b6c6f31ce6",
      "name": "Section: Deduplication",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        -2208
      ],
      "parameters": {
        "color": 7,
        "width": 1500,
        "height": 1076,
        "content": "### 2\ufe0f\u20e3 Deduplication\nReads already-used trends from the `trend_table` Data Table.\nFilters out any trend used in the **last 24 hours**.\nThen picks top 2  trends from what's left."
      },
      "typeVersion": 1
    },
    {
      "id": "0d4c29be-ef03-4e5d-a711-c99194446098",
      "name": "Data Table Setup Tip",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1008,
        -2192
      ],
      "parameters": {
        "color": 5,
        "width": 380,
        "height": 140,
        "content": "\ud83d\udee0\ufe0f **One-time setup:**\nRun `Create a data table` manually once to create the `trend_table`.\nThen **disable** that node \u2014 it only needs to run once."
      },
      "typeVersion": 1
    },
    {
      "id": "8f8276ce-39f3-40cf-ab4b-1c68cdb92fe2",
      "name": "Data Table Setup Tip1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1472,
        -2192
      ],
      "parameters": {
        "color": 5,
        "width": 380,
        "height": 140,
        "content": "\ud83d\udee0\ufe0f **Numbers of tweets per cycle setup :**\nAt Pick Trend Node. At \"const picked = items.slice(0, 1);\n\nChange 1 to the number of tweets you want per cycle **i.e if you want 5 tweets per cycle, change 1 to 5**."
      },
      "typeVersion": 1
    },
    {
      "id": "8a5e9a26-91ab-4ac7-a23d-378f81fa01c2",
      "name": "Section: Generation & Posting",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2176,
        -2208
      ],
      "parameters": {
        "color": 7,
        "width": 2756,
        "height": 1092,
        "content": "### 3\ufe0f\u20e3 Generate Tweet or Post loops per trend\nFor each picked trend:\n- Gemini generates a pidgin-English tweet (\u2264275 chars)\n- Tweet or post are posted to X or facebook or thread or all via Buffer MCP\n- Trend saved to `trend_table` to prevent reuse"
      },
      "typeVersion": 1
    },
    {
      "id": "c19ecdbe-caba-43db-a326-c3b47c82e115",
      "name": "\u26a0\ufe0f HuggingFace Setup1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2768,
        -2192
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "content": "\u26a0\ufe0f **Gemini Credential Required**\nCreate a new **Google PaLM API** credential in n8n with your Gemini API token and select it in Generate Tweet with Gemini and  Generate Tweet (HTTP Fallback) node.\n\nDo NOT paste the token directly in node parameters."
      },
      "typeVersion": 1
    },
    {
      "id": "9185328a-fa93-4969-b8b2-b9d528a2d88b",
      "name": "\u26a0\ufe0f Buffer Channel ID",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3200,
        -2192
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "content": "\ud83d\udccc **Buffer Setup**\nCreate a new **Bearer AuthI** credential in n8n with your Buffer API token and Replace `YOUR_BUFFER_CHANNEL_ID` in this node with your actual Buffer channel ID for your X (Twitter) account.\n\nFind it in your Buffer dashboard \u2192 Channel Settings."
      },
      "typeVersion": 1
    },
    {
      "id": "0146a270-3383-4c1e-8100-dcefdfb27df9",
      "name": "Prepare Trend Record",
      "type": "n8n-nodes-base.code",
      "position": [
        4032,
        -1520
      ],
      "parameters": {
        "jsCode": "// Get the current trend from the loop (passed through Loop Over Items)\nconst currentTrend = $('Loop Over Items').item.json.trend;\n\nreturn [{\n  json: {\n    trend: currentTrend,\n    tweet: $input.first().json.content[0].text.text,\n    usedAt: new Date().toISOString()\n  }\n}];"
      },
      "typeVersion": 2
    }
  ],
  "active": true,
  "settings": {
    "timezone": "Africa/Lagos",
    "binaryMode": "separate",
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": "D46DQsXHQKUYniLC",
    "timeSavedMode": "fixed",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "cce54a6e-ff9e-40c2-a2fd-73b3d40d1647",
  "connections": {
    "If3": {
      "main": [
        [
          {
            "node": "Split Trend Apify",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Run an Actor and get dataset1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If4": {
      "main": [
        [
          {
            "node": "Split Trend Apify",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Daily x trends1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "trend ": {
      "main": [
        [
          {
            "node": "Gemini Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Tweet (HTTP Fallback)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick Trend": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Trend": {
      "main": [
        [
          {
            "node": "Split Trend1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Split Trend1": {
      "main": [
        [
          {
            "node": "Create a data table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Success": {
      "main": [
        [
          {
            "node": "Extract Tweet Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Tweet (HTTP Fallback)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Trends3": {
      "main": [
        [
          {
            "node": "If3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Trends4": {
      "main": [
        [
          {
            "node": "Split Trend",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Trends5": {
      "main": [
        [
          {
            "node": "If4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Last 24h": {
      "main": [
        [
          {
            "node": "Remove Used Trends",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Success1": {
      "main": [
        [
          {
            "node": "Extract Trends4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Tweet (HTTP Fallback)1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Used Trends": {
      "main": [
        [
          {
            "node": "Filter Last 24h",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "trend ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post only tweets": {
      "main": [
        [
          {
            "node": "Prepare Trend Record",
            "type": "main",
            "index": 0
          },
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "Run an Actor and get dataset2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Trend Apify": {
      "main": [
        [
          {
            "node": "Split Trend1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Tweet Text": {
      "main": [
        [
          {
            "node": "Thread post",
            "type": "main",
            "index": 0
          },
          {
            "node": "facebook post",
            "type": "main",
            "index": 0
          },
          {
            "node": "Post only tweets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Used Trends": {
      "main": [
        [
          {
            "node": "Pick Trend",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a data table": {
      "main": [
        [
          {
            "node": "Get Used Trends",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Daily x trends1": {
      "main": [
        [
          {
            "node": "Gemini Success1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Tweet (HTTP Fallback)1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Trend Record": {
      "main": [
        [
          {
            "node": "Insert row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run an Actor and get dataset1": {
      "main": [
        [
          {
            "node": "Extract Trends5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run an Actor and get dataset2": {
      "main": [
        [
          {
            "node": "Extract Trends3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Tweet (HTTP Fallback)": {
      "main": [
        [
          {
            "node": "Extract Tweet Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Tweet (HTTP Fallback)1": {
      "main": [
        [
          {
            "node": "Extract Trends4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}