{
  "id": "Deax1GMBbSZll9IS",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Gen_content_Trend",
  "tags": [],
  "nodes": [
    {
      "id": "9ed21af4-75ee-4552-aecf-4c7ef3675989",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -384,
        -112
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 20,
              "triggerAtMinute": 45
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "36436812-83f2-43ab-8d7b-99d32c1d1aa2",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1184,
        112
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "chatgpt-4o-latest",
          "cachedResultName": "chatgpt-4o-latest"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "41709e9e-f9ad-4d0b-a896-f45201f96983",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1392,
        112
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"title\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n      \"content\":{\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "f4580fb6-93c0-4a97-92d6-05cbb27f41e6",
      "name": "Create a post",
      "type": "n8n-nodes-base.wordpress",
      "position": [
        1520,
        -112
      ],
      "parameters": {
        "title": "={{ $json.output.title }}",
        "additionalFields": {
          "status": "draft",
          "content": "={{ $json.output.content }}"
        }
      },
      "credentials": {
        "wordpressApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7a97cd39-7279-4155-b3dd-3dd9d4fc6889",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        -960
      ],
      "parameters": {
        "width": 736,
        "height": 816,
        "content": "# Automated Blog Content Generation from Google Trends to WordPress\n\nThis n8n workflow automatically generates SEO-friendly blog content based on trending topics from Google Trends and publishes it to WordPress. Perfect for content creators, bloggers, and digital marketers who want to stay on top of trending topics with minimal manual effort.\n\nThe AI is specifically prompted to create engaging, SEO-optimized content without revealing the automated sources, ensuring natural-sounding blog posts.\n\n## How to set up\n\n1. **Install required community nodes**:\n   - `n8n-nodes-serpapi` for Google Trends and Search functionality\n\n2. **Configure credentials**:\n   - **SerpApi**: Sign up at serpapi.com and add your API key\n   - **OpenAI**: Add your OpenAI API key for GPT-4o access\n   - **WordPress**: Configure your WordPress site credentials\n\n3. **Customize the country code**: Change the \"Country\" field in the \"Edit Fields\" node (currently set to \"IR\" for Iran)\n\n4. **Adjust the schedule**: Modify the \"Schedule Trigger\" to run at your preferred time\n\n5. **Test the workflow**: Run it manually first to ensure all connections work properly\n\n## Requirements\n\n- **SerpApi account** (for Google Trends and Search data)\n- **OpenAI API access** (for content generation using GPT-4o)\n- **WordPress site** with API access enabled\n"
      },
      "typeVersion": 1
    },
    {
      "id": "0690742a-dc4b-4801-af92-304bdd72c141",
      "name": "Set Target Country",
      "type": "n8n-nodes-base.set",
      "position": [
        -176,
        -112
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fbf9220c-ae51-4926-b2c1-3a46d621f1de",
              "name": "Country",
              "type": "string",
              "value": "IR"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d5ac170a-08bc-468f-891c-5a27e8e151b3",
      "name": "Fetch Trending Topics",
      "type": "n8n-nodes-serpapi.serpApi",
      "position": [
        48,
        -112
      ],
      "parameters": {
        "geo": "={{ $json.Country }}",
        "operation": "google_trends_trending_now",
        "requestOptions": {},
        "additionalFields": {}
      },
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "281a59d5-31cd-4754-b73f-e2b80715b3bf",
      "name": "Extract Trending Searches",
      "type": "n8n-nodes-base.code",
      "position": [
        272,
        -112
      ],
      "parameters": {
        "jsCode": "return $input.first().json.trending_searches;"
      },
      "typeVersion": 2
    },
    {
      "id": "7e9bd949-872d-4af5-b73c-58bc841f0a37",
      "name": "Limit to Top 3 Trends",
      "type": "n8n-nodes-base.limit",
      "position": [
        496,
        -112
      ],
      "parameters": {
        "maxItems": 3
      },
      "typeVersion": 1
    },
    {
      "id": "d90c7941-d9c1-4dc8-82bf-c07bcfeb2ab6",
      "name": "Generate Blog Content with AI",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1168,
        -112
      ],
      "parameters": {
        "text": "=You are expert weblog writer.\nWrite a post about this content.\nThe information gathered from Google Trends and Google Search about a Trending topic.\nDon't mention the source of the information and the goal is to generate seo friendly content.\nUse the fact that exist in the search result.\n {{ $json.text }}",
        "batching": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "f6a9e1fd-70a3-4b41-8a09-f5c314734939",
      "name": "Format Search Results",
      "type": "n8n-nodes-base.code",
      "position": [
        944,
        -112
      ],
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  let text = `Google Search result for ${item.json.search_parameters.q}\\n`;\n  let i = 0;\n  for (const result of item.json.organic_results)\n    {\n      i++;\n  text += `Result ${i}\\n${result.title}\\n${result.snippet}\\n---`;    \n    }\n  item.json.text = text;\n  \n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "e96d2a99-e776-4db3-a05d-725d72db5f8a",
      "name": "Search Trend Details",
      "type": "n8n-nodes-serpapi.serpApi",
      "position": [
        720,
        -112
      ],
      "parameters": {
        "q": "={{ $json.query }}",
        "requestOptions": {},
        "additionalFields": {}
      },
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a7632715-1979-4f6b-9edf-04b241592911",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -224
      ],
      "parameters": {
        "color": 7,
        "height": 272,
        "content": "This node performs detailed Google searches for each trending topic to gather comprehensive information"
      },
      "typeVersion": 1
    },
    {
      "id": "b41f0bf4-20bf-4b5e-ae17-a180c6059ecd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 400,
        "content": "This code node processes and formats the Google search results into readable text for the AI:\n\nCombines all search results into a structured text format\nCreates a summary that includes: search query, result titles, and snippets\nFormats the data as: \"Google Search result for [topic]\\nResult 1\\n[title]\\n[snippet]\\n---\"\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "timezone": "Asia/Tehran",
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "versionId": "cbaf59f3-b72a-4361-8ed7-8d202b602a15",
  "connections": {
    "Create a post": {
      "main": [
        []
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set Target Country",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Blog Content with AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Target Country": {
      "main": [
        [
          {
            "node": "Fetch Trending Topics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Trend Details": {
      "main": [
        [
          {
            "node": "Format Search Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Trending Topics": {
      "main": [
        [
          {
            "node": "Extract Trending Searches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Search Results": {
      "main": [
        [
          {
            "node": "Generate Blog Content with AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit to Top 3 Trends": {
      "main": [
        [
          {
            "node": "Search Trend Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Generate Blog Content with AI",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Extract Trending Searches": {
      "main": [
        [
          {
            "node": "Limit to Top 3 Trends",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Blog Content with AI": {
      "main": [
        [
          {
            "node": "Create a post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}