AutomationFlowsSocial Media › Generate Trending X, Facebook, and Threads Posts with Apify, Gemini, and Buffer

Generate Trending X, Facebook, and Threads Posts with Apify, Gemini, and Buffer

ByAfigo Sam @sampidia on n8n.io

This workflow automatically discovers trending topics, generates engaging social media content using AI, and publishes posts to X (Twitter) and Facebook via Buffer.

Cron / scheduled trigger★★★★★ complexityAI-powered37 nodesData TableGoogle GeminiMcp Client@Apify/N8N Nodes ApifyHTTP Request
Social Media Trigger: Cron / scheduled Nodes: 37 Complexity: ★★★★★ AI nodes: yes Added:
Generate Trending X, Facebook, and Threads Posts with Apify, Gemini, and Buffer — n8n workflow card showing Data Table, Google Gemini, Mcp Client integration

This workflow corresponds to n8n.io template #14961 — we link there as the canonical source.

This workflow follows the Datatable → HTTP Request recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "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": "a

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow automatically discovers trending topics, generates engaging social media content using AI, and publishes posts to X (Twitter) and Facebook via Buffer.

Source: https://n8n.io/workflows/14961/ — original creator credit. Request a take-down →

More Social Media workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Social Media

📺 Full walkthrough video: https://youtu.be/Me4d4BILvHk

Gmail, Data Table, HTTP Request
Social Media

Automatically upload your Instagram videos to YouTube with configurable time gaps between each upload, using n8n Tables for deduplication. Fetches recent Instagram posts via the Meta Graph API and fil

HTTP Request, Data Table, YouTube
Social Media

Meta long-lived user tokens typically expire after ~60 days. If a token expires, any workflows that rely on it start failing. Manual renewal is easy to forget and time consuming. This template monitor

Data Table, HTTP Request
Social Media

This n8n template acts as your automated social media data analyst. Instead of manually checking your analytics across different dashboards every week, this workflow scrapes your latest stats, calcula

HTTP Request, YouTube, Airtable +3