{
  "nodes": [
    {
      "id": "934a2de3-e7f0-4649-8df8-46125332089c",
      "name": "Influencer Audit Form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        608,
        240
      ],
      "parameters": {
        "options": {
          "appendAttribution": false
        },
        "formTitle": "Influencer Brand Safety Audit",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Instagram Username",
              "requiredField": true
            },
            {
              "fieldLabel": "Competitor Brand Names (optional, comma-separated)"
            }
          ]
        },
        "formDescription": "Enter influencer details to analyze engagement rates and content safety"
      },
      "typeVersion": 2.3
    },
    {
      "id": "2af101f2-b488-47ec-9583-14fb008f6dd7",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        832,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "apifyApiToken",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Your Apify API Token__>"
            },
            {
              "id": "id-2",
              "name": "resultsLimit",
              "type": "number",
              "value": 30
            },
            {
              "id": "id-3",
              "name": "engagementThresholdLow",
              "type": "number",
              "value": 1
            },
            {
              "id": "id-4",
              "name": "engagementThresholdHigh",
              "type": "number",
              "value": 10
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "0fa959ab-ea9a-48af-bbf7-ae4046164785",
      "name": "Store Audit Request",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1056,
        240
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "username"
          ]
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Audit Requests"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Google Sheet ID for Audit Requests__>"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "85651dbe-a89b-4548-8a1c-1d90b2e8401f",
      "name": "Apify Instagram Scraper",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1280,
        240
      ],
      "parameters": {
        "url": "=https://api.apify.com/v2/acts/apify~instagram-scraper/runs?token={{ $('Workflow Configuration').item.json.apifyApiToken }}&waitForFinish=300",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"directUrls\": [\"https://www.instagram.com/{{ $('Influencer Audit Form').item.json.username }}/\"],\n  \"resultsLimit\": {{ $('Workflow Configuration').item.json.resultsLimit }},\n  \"resultsType\": \"posts\",\n  \"searchType\": \"user\",\n  \"proxy\": {\n    \"useApifyProxy\": true\n  }\n}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.3
    },
    {
      "id": "db05de56-1a08-4589-a105-6698718b2baa",
      "name": "Calculate Engagement Rate",
      "type": "n8n-nodes-base.code",
      "position": [
        1536,
        240
      ],
      "parameters": {
        "jsCode": "const apifyResponse = $input.first().json;\nconst posts = apifyResponse.data?.items || [];\n\nif (posts.length === 0) {\n  return [{ json: { error: 'No posts found', username: $('Influencer Audit Form').item.json.username } }];\n}\n\n// Get profile info from first post\nconst firstPost = posts[0];\nconst followers = firstPost.ownerFollowersCount || 1;\nconst username = firstPost.ownerUsername || $('Influencer Audit Form').item.json.username;\n\n// Calculate total engagement\nlet totalEngagement = 0;\nposts.forEach(post => {\n  const likes = post.likesCount || 0;\n  const comments = post.commentsCount || 0;\n  totalEngagement += likes + comments;\n});\n\n// Calculate averages\nconst avgEngagement = Math.round(totalEngagement / posts.length);\nconst engagementRate = ((avgEngagement / followers) * 100).toFixed(2);\n\n// Determine health status based on thresholds\nconst lowThreshold = $('Workflow Configuration').item.json.engagementThresholdLow;\nconst highThreshold = $('Workflow Configuration').item.json.engagementThresholdHigh;\n\nlet status = 'Healthy';\nif (parseFloat(engagementRate) < lowThreshold) {\n  status = 'Suspicious (Low Engagement - Possible Fake Followers)';\n} else if (parseFloat(engagementRate) > highThreshold && followers > 10000) {\n  status = 'Suspicious (Unusually High - Possible Bot Activity)';\n}\n\n// Return aggregated data with all posts for next node\nreturn posts.map(post => ({\n  json: {\n    ...post,\n    username: username,\n    followers: followers,\n    engagementRate: engagementRate + '%',\n    avgEngagement: avgEngagement,\n    status: status,\n    totalPosts: posts.length\n  }\n}));"
      },
      "typeVersion": 2
    },
    {
      "id": "72872dba-feb1-48d7-ad3b-642b83fa8280",
      "name": "Aggregate Captions",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1744,
        240
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "caption"
            },
            {
              "fieldToAggregate": "displayUrl"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "36e02195-125d-44af-8705-5f303e7b693d",
      "name": "AI Content Safety Audit",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2000,
        240
      ],
      "parameters": {
        "operation": "message"
      },
      "typeVersion": 2
    },
    {
      "id": "594f9e24-a9aa-4878-8264-8eedc70932cf",
      "name": "Send Audit Report to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        2496,
        240
      ],
      "parameters": {
        "text": "=\ud83d\udee1\ufe0f **Influencer Brand Safety Audit Report**\n\n\ud83d\udc64 **Influencer:** @{{ $('Calculate Engagement Rate').item.json.username }}\n\n\ud83d\udcca **Numerical Analysis:**\n\u2022 Followers: {{ $('Calculate Engagement Rate').item.json.followers.toLocaleString() }}\n\u2022 Engagement Rate: {{ $('Calculate Engagement Rate').item.json.engagementRate }}\n\u2022 Average Engagement: {{ $('Calculate Engagement Rate').item.json.avgEngagement }}\n\u2022 Health Status: `{{ $('Calculate Engagement Rate').item.json.status }}`\n\n\ud83e\udd16 **AI Safety Assessment:**\n\u2022 Safety Score: *{{ $json.safety_score }}*\n\u2022 Risk Flags: {{ $json.risk_flags.length > 0 ? $json.risk_flags.join(\", \") : \"None detected\" }}\n\u2022 Competitor Mentions: {{ $json.competitor_check }}\n\u2022 Engagement Assessment: {{ $json.engagement_assessment }}\n\n\ud83d\udcdd **Content Summary:**\n{{ $json.content_summary }}\n\n\u2705 **Recommendation:** *{{ $json.recommendation }}*",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Slack Channel ID__>"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "16ce7ada-0ec0-4786-8a17-c6146e43a7ab",
      "name": "Store Audit Results",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2736,
        240
      ],
      "parameters": {
        "columns": {
          "value": null,
          "mappingMode": "autoMapInputData"
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Audit Results"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Google Sheet ID for Audit Results__>"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b0570020-03fd-43d5-be4b-f7eea676c7b0",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 496,
        "height": 320,
        "content": "## Overview\nProtect your brand reputation and budget by automatically vetting potential influencer partners. This workflow analyzes an Instagram profile to detect suspicious engagement patterns (indicating fake followers or bots) and uses AI to scan their content for brand safety risks, offensive language, or competitor mentions.\n\n## Who is this for?\n- **Influencer Marketing Managers:** To vet creators before sending offers.\n- **Agencies:** To perform due diligence for clients.\n- **Brand Managers:** To ensure brand alignment and safety."
      },
      "typeVersion": 1
    },
    {
      "id": "5da91188-5c71-43c2-9799-1dab4cda28c1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        112
      ],
      "parameters": {
        "color": 6,
        "width": 192,
        "height": 288,
        "content": "1.  **Input:** Takes an Instagram username and optional competitor names via an **n8n Form**."
      },
      "typeVersion": 1
    },
    {
      "id": "9667cbee-b93f-4b45-a655-3239d0997e1b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        112
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 288,
        "content": "2.  **Scraping:** Uses **Apify** to fetch the influencer's profile details and their most recent 30 posts."
      },
      "typeVersion": 1
    },
    {
      "id": "5c5064d8-4147-4d45-afd9-0d16ad11d235",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1472,
        48
      ],
      "parameters": {
        "color": 4,
        "width": 224,
        "height": 384,
        "content": "3.  ** engagement Analysis:** Calculates the average engagement rate. It flags the account as \"Suspicious\" if the rate is too low (potential fake followers) or unnaturally high (potential bot activity)."
      },
      "typeVersion": 1
    },
    {
      "id": "80288e29-d7b1-44b8-8377-284bc21e6299",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1888,
        64
      ],
      "parameters": {
        "color": 5,
        "width": 448,
        "height": 368,
        "content": "4.  **AI Safety Check:** Aggregates recent post captions and sends them to **OpenAI**. The AI evaluates the content for:\n    - Risk flags (controversy, offensive language).\n    - Competitor mentions.\n    - Overall content mood and safety score."
      },
      "typeVersion": 1
    },
    {
      "id": "6d7405a8-e166-4f65-b9e8-240ce5b874ed",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2416,
        144
      ],
      "parameters": {
        "color": 6,
        "width": 256,
        "height": 288,
        "content": "5.  **Reporting:** Sends a detailed audit report to **Slack** and logs the results in **Google Sheets**."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Aggregate Captions": {
      "main": [
        [
          {
            "node": "AI Content Safety Audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Audit Request": {
      "main": [
        [
          {
            "node": "Apify Instagram Scraper",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Influencer Audit Form": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Store Audit Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Content Safety Audit": {
      "main": [
        [
          {
            "node": "Send Audit Report to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apify Instagram Scraper": {
      "main": [
        [
          {
            "node": "Calculate Engagement Rate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Engagement Rate": {
      "main": [
        [
          {
            "node": "Aggregate Captions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Audit Report to Slack": {
      "main": [
        [
          {
            "node": "Store Audit Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}