{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ac7fa355-5fe2-462d-8687-fbefb2665210",
      "name": "Run weekly",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -32,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "4f263558-9c87-4bb4-9936-53842481a95f",
      "name": "Get dataset items",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        512,
        0
      ],
      "parameters": {
        "limit": 100,
        "resource": "Datasets",
        "datasetId": "={{ $json.defaultDatasetId }}"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b73e249e-7212-4795-b9fd-86b287130470",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        416,
        320
      ],
      "parameters": {
        "mode": "each",
        "options": {
          "format": false,
          "fileName": "={{ $json.postId }}.json"
        },
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "0cad6b86-5c0f-4be1-9a5f-c235fa4b26cd",
      "name": "Filter posts",
      "type": "n8n-nodes-base.filter",
      "position": [
        704,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7084d37d-8f7b-4ab4-bf0b-e8294e7d7a6d",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.type }}",
              "rightValue": "post"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "dc853687-f43a-42c8-89c5-cc9132bd8277",
      "name": "Extract comments",
      "type": "n8n-nodes-base.set",
      "position": [
        144,
        320
      ],
      "parameters": {
        "options": {
          "dotNotation": false
        },
        "assignments": {
          "assignments": [
            {
              "id": "09dca6cd-2cb2-42a1-b1e0-5c566f814f60",
              "name": "postId",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "09f85344-537c-4c32-83d8-c7faa7e9971c",
              "name": "postUrl",
              "type": "string",
              "value": "={{ $json.linkedinUrl }}"
            },
            {
              "id": "77b49be1-df83-465c-a087-de228d89db25",
              "name": "comments",
              "type": "array",
              "value": "={{\n  ($json.comments || []).map(c => ({\n    id: c.id,\n    commentUrl: c.linkedinUrl,\n    comment: c.commentary\n  }))\n}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9326ed62-1ee9-491d-9085-1582e366d9e0",
      "name": "Upload file",
      "type": "@pinecone-database/n8n-nodes-pinecone-assistant.pineconeAssistant",
      "position": [
        672,
        320
      ],
      "parameters": {
        "resource": "file",
        "operation": "uploadFile",
        "assistantData": "{\"name\":\"n8n-assistant\",\"host\":\"https://prod-1-data.ke.pinecone.io\"}",
        "externalFileId": "={{ $('Extract comments').item.json.postId }}",
        "additionalFields": {
          "metadata": {
            "metadataValues": [
              {
                "key": "postUrl",
                "value": "={{ $('Extract comments').item.json.postUrl }}"
              }
            ]
          },
          "sourceTag": "n8n:n8n_nodes_pinecone_assistant:extract_insights_from_linkedin_comments"
        }
      },
      "credentials": {
        "pineconeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "188f986b-a7c5-4430-8d8a-ce217ee79388",
      "name": "If has comments",
      "type": "n8n-nodes-base.if",
      "position": [
        880,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "48cc6f71-415c-4a2a-8d07-5309744efccf",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{$json.comments.length}}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f08adc5a-df36-4bc6-8295-a90029df5304",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        128,
        624
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.4
    },
    {
      "id": "b644f23f-899f-434a-b5f0-ab7599eca430",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        480,
        624
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a helpful LinkedIn social media assistant that makes recommendations for how to use LinkedIn and helps users analyze LinkedIn post comments. You have access to LinkedIn post comments and reference post and comment urls. When responding always include both urls as a citation."
        }
      },
      "typeVersion": 3
    },
    {
      "id": "ed74470b-7dce-4164-94a3-b5adbcdb4f60",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        400,
        864
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "d0ea2f2c-965c-4c4d-8004-7dfb94175fb9",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 1200,
        "height": 336,
        "content": "## Step 1: Scrape comments from LinkedIn and upload to Pinecone Assistant"
      },
      "typeVersion": 1
    },
    {
      "id": "55b7065f-3a14-4198-bbd7-e2e3d67df742",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 1200,
        "height": 512,
        "content": "## Step 3: Extract insights from LinkedIn comments through chat"
      },
      "typeVersion": 1
    },
    {
      "id": "6515b20f-95a2-4365-8949-a131f822fe6a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 1200,
        "height": 288,
        "content": "## Step 2: Extract comments to json file and upload to Pinecone Assistant"
      },
      "typeVersion": 1
    },
    {
      "id": "bd611285-6b27-4bdb-933a-fa88d1499caa",
      "name": "Run actor to scrape data",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        320,
        0
      ],
      "parameters": {
        "actorId": {
          "__rl": true,
          "mode": "list",
          "value": "A3cAPGpwBEG8RJwse",
          "cachedResultUrl": "",
          "cachedResultName": "LinkedIn Profile Posts Scraper (No Cookies)\u26a1$2 per 1k (harvestapi/linkedin-profile-posts)"
        },
        "customBody": "={\n    \"includeQuotePosts\": true,\n    \"includeReposts\": false,\n    \"maxComments\": 10,\n    \"maxPosts\": 15,\n    \"maxReactions\": 5,\n    \"postedLimit\": \"month\",\n    \"scrapeComments\": true,\n    \"scrapeReactions\": false,\n    \"targetUrls\": [\n        \"{{ $json.linkedInProfile }}\"\n    ]\n} ",
        "actorSource": "store"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "88e8a468-8ebd-4f40-91a9-bdffd037f066",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        -128
      ],
      "parameters": {
        "width": 620,
        "height": 1168,
        "content": "![Pinecone logo](https://www.pinecone.io/images/pinecone-logo-for-n8n-templates.png)\n\n\n## Try it out\n\nThis n8n workflow template lets you extract insights from comments on your LinkedIn posts using Pinecone Assistant, Apify, and OpenAI. It scrapes LinkedIn comments using Apify and then retrieves relevant context from this data using Pinecone Assistant and generates insights with OpenAI, all without the need to train your own LLM.\n\n### What is Pinecone Assistant?\n\n[Pinecone Assistant](https://docs.pinecone.io/guides/assistant/overview) allows you to build production-grade chat and agent-based applications quickly. It abstracts the complexities of implementing retrieval-augmented (RAG) systems by managing the chunking, embedding, storage, query planning, vector search, model orchestration, reranking for you.\n\n### Prerequisites\n\n* A [Pinecone account](https://app.pinecone.io/)\n* An [Open AI account](https://auth.openai.com/create-account) and [API key](https://platform.openai.com/settings/organization/api-keys)\n* An [Apify account](https://apify.com/) and [API token](https://console.apify.com/settings/integrations)\n\n### Setup\n\n1. Create a Pinecone Assistant named `n8n-assistant` in the Pinecone Console [here](https://app.pinecone.io/organizations/-/projects/-/assistant) \n2. Use the Connect to Pinecone button to authenticate to Pinecone or if you self-host n8n, create a Pinecone credential and add your [Pinecone API key](https://app.pinecone.io/organizations/-/projects/-/keys) directly\n3. Setup the Open AI and Apify credentials in n8n\n4. In the Set LinkedIn url node, enter your LinkedIn profile url, for a personal or company profile\n5. Select your Assistant Name in each of the Pinecone Assistant nodes, if it's not already\n6. Schedule or manually execute Step 1 and 2 to extract the LinkedIn comment data and upload to Pinecone Assistant\n7. Once the data is uploaded, ask a question in the chat: `Summarize the comments related to [SOME TOPIC YOU TALK ABOUT] and categorize into positive, neutral, and negative.`\n\n### Ideas for customizing this workflow\n\n- Connect to other social platforms to extract insights from Instagram, X/Twitter, etc. in addition to LinkedIn\n\n### Need help?\n\nYou can find help by asking in the [Pinecone Discord community](https://discord.gg/tJ8V62S3sH) or [filing an issue](https://github.com/pinecone-io/n8n-templates/issues/new/choose) on this repo."
      },
      "typeVersion": 1
    },
    {
      "id": "ab526e05-aa07-4179-86e1-e03834b33f60",
      "name": "Set LinkedIn url",
      "type": "n8n-nodes-base.set",
      "position": [
        144,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "df71d981-fb52-47c1-b5bf-4f46e727b721",
              "name": "linkedInProfile",
              "type": "string",
              "value": "full LinkedIn personal or company profile URL"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "15dbcefd-6458-4633-89b9-80326e9f0856",
      "name": "Pinecone Assistant tool",
      "type": "@pinecone-database/n8n-nodes-pinecone-assistant.pineconeAssistantTool",
      "position": [
        752,
        864
      ],
      "parameters": {
        "assistantData": "{\"name\":\"n8n-assistant\",\"host\":\"https://prod-1-data.ke.pinecone.io\"}",
        "additionalFields": {
          "sourceTag": "n8n:n8n_nodes_pinecone_assistant:extract_insights_from_linkedin_comments"
        }
      },
      "credentials": {
        "pineconeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "connections": {
    "Run weekly": {
      "main": [
        [
          {
            "node": "Set LinkedIn url",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter posts": {
      "main": [
        [
          {
            "node": "If has comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If has comments": {
      "main": [
        [
          {
            "node": "Extract comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract comments": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set LinkedIn url": {
      "main": [
        [
          {
            "node": "Run actor to scrape data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get dataset items": {
      "main": [
        [
          {
            "node": "Filter posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Assistant tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Run actor to scrape data": {
      "main": [
        [
          {
            "node": "Get dataset items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}