{
  "id": "gjAupHx9V4vv002f",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Instagram Like & Comment Agent",
  "tags": [
    {
      "id": "nsnu26JIGNTBBzbF",
      "name": "data scraping",
      "createdAt": "2025-10-06T19:07:43.297Z",
      "updatedAt": "2025-10-06T19:07:43.297Z"
    },
    {
      "id": "uTPlt6kdv0BCVv9L",
      "name": "Lead Gen",
      "createdAt": "2026-07-06T09:24:16.073Z",
      "updatedAt": "2026-07-06T09:24:16.073Z"
    }
  ],
  "nodes": [
    {
      "id": "73c8935f-1f13-486f-8190-dd06822f2508",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        6384,
        1136
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "6d11f509-04ae-4128-98c8-324ab96decb5",
      "name": "Fetch_Influencer_Post",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        6592,
        1152
      ],
      "parameters": {
        "url": "=https://api30.unipile.com:16038/api/v1/users/{{ $json.username }}/posts",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "limit",
              "value": "5"
            },
            {
              "name": "account_id",
              "value": "NfVyBO1OTuS_aizQH9zsUw"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "14c4c6ce-d2a4-4d40-a9cb-fdf17b478ed4",
      "name": "format_Json",
      "type": "n8n-nodes-base.code",
      "position": [
        8544,
        1104
      ],
      "parameters": {
        "jsCode": "return [\n  {\n    json: $json.output[0].content[0].text\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "9ea7be4b-b93a-4ebf-9e7e-2ab108d2383a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5984,
        816
      ],
      "parameters": {
        "color": 4,
        "width": 964,
        "height": 752,
        "content": "## AI Social Engagement Agent Flow\n"
      },
      "typeVersion": 1
    },
    {
      "id": "82bd7387-9a83-4d50-8c13-abe5dadea459",
      "name": "send_Comment",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        9424,
        1312
      ],
      "parameters": {
        "url": "=https://api30.unipile.com:16038/api/v1/posts/{{ $json.post_id }}/comments",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "account_id",
              "value": "LqXuOhLHQwWhMGdB1Wvhdw"
            },
            {
              "name": "text",
              "value": "={{ $json.comment }}"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "a9818ff3-7006-4246-986c-07f81d299477",
      "name": "format_Relevancy",
      "type": "n8n-nodes-base.code",
      "position": [
        7808,
        1120
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// Both responses are inside the first input item\nconst data = items[0].json;\n\n// Extract image analysis\nconst imageDescription =\n  data[\"0\"]?.content?.[0]?.text || \"\";\n\n// Extract text analysis\nlet textData =\n  data.output?.[0]?.content?.[0]?.text || {};\n\n// If textData is a JSON string, parse it\nif (typeof textData === \"string\") {\n  try {\n    textData = JSON.parse(textData);\n  } catch (e) {\n    textData = {};\n  }\n}\n\nreturn [\n  {\n    json: {\n      image_description: imageDescription,\n      ...textData\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "970bfc8f-d535-438c-b48d-ec0cb44db5f1",
      "name": "check_relevancy",
      "type": "n8n-nodes-base.if",
      "position": [
        7952,
        1120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e7de2395-9bed-476e-ae15-288e7894fc33",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.engage }}",
              "rightValue": true
            },
            {
              "id": "b8fb4942-03a4-4776-afb0-7bf7e9193b4e",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.creator_relevance_score }}",
              "rightValue": 70
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b06fc74f-c258-4136-b82d-08d37c79583c",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        7632,
        1120
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "bdf5bae9-b91c-4c60-bdd7-3a596f1213f4",
      "name": "checkCommentExists",
      "type": "n8n-nodes-base.if",
      "position": [
        9152,
        1088
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b1d2bec3-1ad2-436f-8f09-de154819e2dd",
              "operator": {
                "type": "number",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.lastCommentedPostId }}",
              "rightValue": "={{ $json.post_id }}"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "cc77e053-dc85-49ab-94d4-3d6ecc0a4ab9",
      "name": "formatPost",
      "type": "n8n-nodes-base.code",
      "position": [
        6784,
        1152
      ],
      "parameters": {
        "jsCode": "let influencer;\n\ntry {\n  influencer = $('Loop Over Items3').item.json;\n} catch (e) {\n  influencer = $input.first().json;\n}\n\nconst post = $json.items?.[0];\n\nif (!post) {\n  return [{\n    json: {\n      influencerId: influencer.id,\n      influencerName: influencer.name,\n      providerId: influencer.influncrerProviderId,\n      username: influencer.username,\n      accountId: influencer.connectionAccountUnipile || 'e8SNXWPnT92sUstGK-eO0g',\n      hasPost: false,\n      isRecentPost: false,\n      skipReason: 'No latest post found'\n    }\n  }];\n}\n\nconst unipilePostId = post.social_id || post.id;\nconst instagramPostId = post.id;\n\nconst postDateRaw =\n  post.created_at ||\n  post.parsed_datetime ||\n  post.date;\n\nlet postDate = null;\n\nif (typeof postDateRaw === 'number') {\n  postDate = new Date(postDateRaw * 1000);\n} else if (postDateRaw) {\n  postDate = new Date(postDateRaw);\n}\n\nconst postAgeHours =\n  postDate && !Number.isNaN(postDate.getTime())\n    ? (Date.now() - postDate.getTime()) / (1000 * 60 * 60)\n    : null;\n\nconst isRecentPost = postAgeHours !== null && postAgeHours <= 48;\n\nconst alreadyCommented =\n  String(influencer.lastCommentedPostId || '') ===\n  String(unipilePostId);\n\nreturn [{\n  json: {\n    influencerId: influencer.id,\n    influencerName: influencer.name,\n\n    influencerProfileUrl:\n      influencer.accountUrl?.primaryLinkUrl ||\n      influencer.accountUrlPrimaryLinkUrl ||\n      \"\",\n\n    providerId: influencer.influncrerProviderId,\n    username: influencer.username,\n\n    accountId:\n      influencer.connectionAccountUnipile ||\n      'e8SNXWPnT92sUstGK-eO0g',\n\n    lastCommentedPostId:\n      influencer.lastCommentedPostId,\n\n    postId: unipilePostId,\n    unipilePostId,\n    instagramPostId,\n\n    postUrl:\n      post.url ||\n      post.share_url ||\n      \"\",\n\n    postText:\n      post.caption?.text ||\n      post.text ||\n      \"\",\n\n    postDate:\n      postDate\n        ? postDate.toISOString()\n        : null,\n\n    postAgeHours,\n    isRecentPost,\n\n    commentCount:\n      post.comment_count ??\n      post.comment_counter ??\n      0,\n\n    reactionCount:\n      post.like_count ??\n      post.reaction_counter ??\n      0,\n\n    repostCount:\n      post.repost_counter ?? 0,\n\n    canComment:\n      post.permissions?.can_post_comments ?? true,\n\n    canReact:\n      post.permissions?.can_react ?? true,\n\n    alreadyCommented,\n    hasPost: true,\n\n    rawPost: post\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "7c173ecf-1f40-49a0-8db2-c5fe5bacb5e0",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6976,
        816
      ],
      "parameters": {
        "color": 2,
        "width": 1172,
        "height": 752,
        "content": "## 2. Content Evaluation & Relevancy Checks\n\nTo ensure Tayana Academy only engages with high-quality, professional, and relevant content, every today's post undergoes dual-stage validation:\n\n- **Text Relevancy Node**: Analyzes post captions against core focus areas (AI, Tech, STEM, Employability, L&D, Digital Skills) and excludes personal/lifestyle/entertainment/cryptocurrency topics.\n- **Visual Relevancy Node**: Runs OCR and visual classification on the preview image URL to ensure there is educational context or a related visual subject.\n- **Merge & Filter**: Combines both analyses. Engagement only proceeds if the final relevance score is **>= 70** and `engage = true`.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d65dc0c2-48d2-4637-8653-82b7ea7bc623",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5392,
        816
      ],
      "parameters": {
        "width": 576,
        "height": 752,
        "content": "## AI SOCIAL ENGAGEMENT AGENT\n\nAutomated Instagram Content Monitoring, Relevancy Evaluation, Comment Drafting & Human-Approved Publishing.\n\nWORKFLOW OBJECTIVE\nAutomatically identify relevant Instagram posts and prepare meaningful engagement while maintaining human approval before publishing.\n\nMAIN PROCESS\n\n1. Get Instagram influencer data\n2. Process influencers one by one\n3. Fetch the latest Instagram post\n4. Validate post eligibility\n5. Analyze text and image relevance using AI\n6. Calculate final engagement eligibility\n7. Generate a professional comment\n8. Check for duplicate engagement\n9. Keep comment in Pending state for review\n10. Like and publish the approved comment\n11. Update the influencer record in the database\n\nIMPORTANT\n\u2022 AI performs analysis and comment generation.\n\u2022 Duplicate checks prevent repeated engagement.\n\u2022 Human approval is required before public engagement.\n\u2022 Database records are updated after successful processing."
      },
      "typeVersion": 1
    },
    {
      "id": "601c1831-5551-4e3a-9fae-efb190a40406",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        8176,
        816
      ],
      "parameters": {
        "width": 1152,
        "height": 752,
        "content": "## 3. Comment Drafting & Duplicate Prevention\n\nOnce a post is qualified, the system prepares the draft:\n\n- **Cohere Chat Agent**: Generates a context-aware, value-added comment (15\u201330 words) that sounds natural, professional, and is strictly non-promotional (no links, sales pitches, or hashtags).\n- **Duplicate Verification**: Checks the sheet database using the unique `post_id` to ensure we do not draft duplicate comments for the same post.\n- **Database Append**: Saves the post and draft comment to the `Post like & comment` sheet with the status `Pending` for human review.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "8f53d24d-5eae-4143-9f71-4e4d3b796397",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        9344,
        832
      ],
      "parameters": {
        "color": 3,
        "width": 736,
        "height": 752,
        "content": "## 4. Publishing Flow (Human-Approved)\n\nThis independent sequence publishes approved content:\n\n- **Fetch Approved**: Queries the `Post like & comment` sheet for entries where `approval_status = Approved`.\n- **Unipile HTTP Post**: Sends the approved comment text and publishes a \"Like\" reaction under the post.\n- **Publish Status Update**: Changes the sheet status from `Approved` to `Published` to ensure the post is not processed again on the next run.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "3040805b-69a8-4f3c-9e4f-dc9608ed1dd7",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        6016,
        1136
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 15,
              "triggerAtMinute": 10
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "7f043b60-dc96-4cbe-aff4-edc5ff8b23ed",
      "name": "hasTodayPost",
      "type": "n8n-nodes-base.if",
      "position": [
        7024,
        1152
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7b138104-be67-4ee4-a431-1fd754dedc32",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.hasPost }}",
              "rightValue": true
            },
            {
              "id": "83430d5b-5ee7-45f2-9d60-7225fb5684e5",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "leftValue": "={{ $json.alreadyCommented }}",
              "rightValue": ""
            },
            {
              "id": "a2a39b9a-88ec-4bfe-b9c6-afa7a6526dde",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.canComment }}",
              "rightValue": ""
            },
            {
              "id": "223b03a3-0822-4e5c-9787-9a293f715c7c",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.isRecentPost }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "09fcb144-d99c-4d8c-8c8b-eea2fe4cb9f5",
      "name": "send_Like",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        9424,
        1072
      ],
      "parameters": {
        "url": "https://api30.unipile.com:16038/api/v1/posts/reaction",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "post_id",
              "value": "={{ $json.post_id }}"
            },
            {
              "name": "account_id",
              "value": "LqXuOhLHQwWhMGdB1Wvhdw"
            },
            {
              "name": "reaction_type",
              "value": "like"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "72009b7d-05aa-430e-9948-1aa71f5edfed",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        9600,
        1072
      ],
      "parameters": {
        "amount": 20
      },
      "typeVersion": 1.1
    },
    {
      "id": "ff761208-c021-4fad-8777-5c433d648cc9",
      "name": "Parse data from the check comment status",
      "type": "n8n-nodes-base.code",
      "position": [
        9792,
        1072
      ],
      "parameters": {
        "jsCode": "return [\n  {\n    json: $(\"checkCommentExists\").first().json\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "99ae8813-33b3-4edc-b51f-8f155bf7d2f3",
      "name": "Parse data to send in nebula",
      "type": "n8n-nodes-base.code",
      "position": [
        9648,
        1312
      ],
      "parameters": {
        "jsCode": "return [\n  {\n    json: $(\"checkCommentExists\").first().json\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "432858fc-6874-4829-909c-7f08aaa5c35a",
      "name": "Execute a SQL query",
      "type": "n8n-nodes-base.postgres",
      "position": [
        9808,
        1312
      ],
      "parameters": {
        "query": "UPDATE \"workspace_13mbc2c4oiu70a17e1h9z0mxn\".\"_influencer\"\nSET\n    \"postUrlPrimaryLinkUrl\" = '{{ String($json.post_url || \"\").replace(/'/g, \"''\") }}',\n    \"lastCommentedPostId\" = '{{ String($json.post_id || \"\").replace(/'/g, \"''\") }}',\n    \"lastCommentedOn\" = NOW(),\n    \"updatedAt\" = NOW()\nWHERE \"id\" = '{{ String($json.id).replace(/'/g, \"''\") }}';",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "19221917-6580-4ad4-b201-bd8461aabdd1",
      "name": "Get id and last post id from nebula",
      "type": "n8n-nodes-base.postgres",
      "position": [
        8768,
        1024
      ],
      "parameters": {
        "query": "SELECT id, \"lastCommentedPostId\"\nFROM \"workspace_13mbc2c4oiu70a17e1h9z0mxn\".\"_influencer\"\nWHERE \"influncrerProviderId\" = '{{ $json.profile_id }}';",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "039a2e7a-32fd-4663-98e2-03229203f991",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        8976,
        1088
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "22938b73-f8bd-4837-8604-8dc640a6c3ad",
      "name": "Agent for Generating Comment",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        8256,
        1104
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gemma4:12b",
          "cachedResultName": "GEMMA4:12B"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=You are representing Tayana Academy.\n\n## TASK\n\nA previous AI agent has already determined that this Instagram post is relevant and approved for engagement.\n\nYour ONLY responsibility is to generate one high-quality, professional comment.\n\nDO NOT analyze whether the post is relevant.\nDO NOT change any metadata.\nDO NOT invent or modify any values.\n\n---\n\n## POST INFORMATION\n\nCaption:\n{{ $('Fetch_Influencer_Post').item.json.items[0].caption.text }}\n\nCategory:\n{{ $json.category }}\n\nPreview Image:\n{{ $('Fetch_Influencer_Post').item.json.items[0].preview_image.url }}\n\nPost ID:\n{{ $json.post_id }}\n\nProfile ID:\n{{ $json.profile_id }}\n\nOwner Username:\n{{ $json.owner_username }}\n\nPost URL:\n{{ $('Fetch_Influencer_Post').item.json.items[0].url }}\n\nSentiment:\n{{ $json.sentiment }}\n\n---\n\n## COMMENT REQUIREMENTS\n\nGenerate ONE comment that:\n\n- Sounds natural and human\n- Is professional\n- Adds value to the discussion\n- Demonstrates expertise\n- Is directly related to the caption and image\n- Encourages meaningful discussion\n- Is unique\n- Reads like it was written by a real professional\n\nThe comment must NOT:\n\n- Be generic\n- Sound promotional\n- Mention Tayana Academy\n- Mention courses\n- Mention enrollment\n- Mention products or services\n- Include links\n- Include hashtags\n- Include emojis\n- Sound like AI\n- Repeat the caption\n\n---\n\n## COMMENT LENGTH\n\nMinimum: 15 words\n\nMaximum: 30 words\n\n---\n\n## CRITICAL RULES\n\nThe following fields are IMMUTABLE.\n\nYou MUST copy them EXACTLY as provided.\n\nDO NOT:\n\n- change them\n- regenerate them\n- infer them\n- shorten them\n- format them differently\n- replace them\n- modify even a single character\n\nThese fields MUST remain identical:\n\n- post_id\n- profile_id\n- owner_username\n- post_url\n- category\n- sentiment\n\nThe ONLY field you are allowed to generate is:\n\n- comment\n\napproval_status MUST always be:\n\nPending\n\n---\n\n## OUTPUT FORMAT\n\nReturn ONLY valid JSON.\n\n{\n  \"post_id\": \"{{ $json.post_id }}\",\n  \"profile_id\": \"{{ $json.profile_id }}\",\n  \"owner_username\": \"{{ $json.owner_username }}\",\n  \"post_url\": \"{{ $('Fetch_Influencer_Post').item.json.items[0].url }}\",\n  \"comment\": \"\",\n  \"sentiment\": \"{{ $json.sentiment }}\",\n  \"category\": \"{{ $json.category }}\",\n  \"approval_status\": \"Pending\"\n}\n\n---\n\n## STRICT OUTPUT RULES\n\nReturn JSON only.\n\nNo markdown.\n\nNo explanations.\n\nNo code block.\n\nNo additional text.\n\nNo notes.\n\nNo reasoning.\n\nNo surrounding text.\n\nReturn exactly one valid JSON object."
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "636c8b3e-0263-40df-8cbb-02e83548bb76",
      "name": "checkPostRelevancyText",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        7248,
        1200
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gemma4:12b",
          "cachedResultName": "GEMMA4:12B"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=You are an AI content relevance evaluator for Tayana Academy.\n\nYOUR TASK\n\nAnalyze the provided Instagram post and determine whether Tayana Academy should engage with it.\n\nTAYANA ACADEMY FOCUS AREAS\n\n* Career Development\n* Workforce Development\n* Education\n* Technology\n* Artificial Intelligence\n* Leadership\n* Employability\n* Upskilling\n* Reskilling\n* Future of Work\n* Professional Development\n* STEM Careers\n* Learning & Development\n* Data Science\n* Analytics\n* Software Development\n* Programming\n* Digital Skills\n* Business Skills\n* Entrepreneurship\n* Productivity\n* Career Guidance\n* Interview Preparation\n* Job Search Strategies\n* Corporate Training\n\nDO NOT ENGAGE WITH CONTENT PRIMARILY ABOUT\n\n* Personal Life\n* Entertainment\n* Food\n* Travel\n* Fashion\n* Beauty\n* Lifestyle\n* Memes\n* Politics\n* Religion\n* Cryptocurrency\n* Sports\n* Gaming\n* Relationships\n* Celebrity News\n* Music\n* Movies\n* Viral Trends\n* Personal Vlogs\n\nPOST DATA\npost_id: \n{{ $json.postId }}\n\nprovider_id/profile_id: \n{{ $json.rawPost.owner.id }}\n\nCaption:\n{{ $json.postText }}\nUsername:\n{{ $json.rawPost.owner.username }}\n\nPreview image: \n{{ $json.rawPost.preview_image.url }}\n\nProfile Name:\n{{ $('Loop Over Items').item.json[\"Creator Name\"] || \"\" }}\n\nVerified:\n{{ $json.owner?.is_verified || false }}\n\nPrivate:\n{{ $json.owner?.is_private || false }}\n\nLikes:\n{{ $json.like_count || 0 }}\n\nComments:\n{{ $json.comment_count || 0 }}\n\nPost URL:\n{{ $json.url || \"\" }}\n\nDECISION RULES\n\n* If profile is private \u2192 engage=false\n* If caption is empty or unavailable \u2192 engage=false\n* If caption is not primarily written in English \u2192 engage=false\n* If creator content appears primarily targeted at non-English audiences \u2192 engage=false\n* If content is unrelated to Tayana Academy focus areas \u2192 engage=false\n* If content is primarily promotional, entertainment, lifestyle, or personal branding without educational value \u2192 engage=false\n* If creator_relevance_score < 70 \u2192 engage=false\n* If content is clearly relevant to Tayana Academy focus areas \u2192 engage=true\n\nLANGUAGE RULES\n\n* Tayana Academy engages only with English-language content.\n* If the caption is predominantly written in Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Punjabi, Malayalam, Kannada, Urdu, or any other non-English language \u2192 engage=false.\n* If more than 30% of the caption is written in a non-English language \u2192 engage=false.\n* English captions containing a few non-English words are acceptable.\n* If the language cannot be confidently determined \u2192 engage=false.\n\nSCORING GUIDELINES\n\n100 = Perfect fit for Tayana Academy\n\n90-99\n\n* AI tutorials\n* Technology education\n* Career growth\n* Workforce development\n* Leadership insights\n* Professional learning\n\n80-89\n\n* Educational content\n* Data science\n* Programming\n* STEM\n* Upskilling\n* Business learning\n\n70-79\n\n* General professional development\n* Productivity\n* Entrepreneurship\n* Career advice\n\n60-69\n\n* Borderline relevance\n* Generic motivational content\n* Personal branding with some educational value\n\n40-59\n\n* Low relevance\n* Mostly personal content\n* Limited educational value\n\n0-39\n\n* Not relevant\n* Entertainment\n* Lifestyle\n* Personal life\n* Non-English content\n* Travel\n* Food\n* Fashion\n* Politics\n* Religion\n* Sports\n* Cryptocurrency\n\nCATEGORY OPTIONS\n\n* Artificial Intelligence\n* Technology\n* Education\n* Career Development\n* Leadership\n* Workforce Development\n* Employability\n* Upskilling\n* Reskilling\n* Future of Work\n* Professional Development\n* Data Science\n* Programming\n* Entrepreneurship\n* Productivity\n* Learning & Development\n* Not Relevant\n\nSENTIMENT OPTIONS\n\n* Positive\n* Neutral\n* Negative\n\nOUTPUT REQUIREMENTS\n\nReturn ONLY valid JSON.\n\n{\n\"post_id\": \"{{ $json.postId }}\",\n\"profile_id\": \"{{ $json.rawPost.owner.id }}\",\n\"owner_username\": \"{{ $json.rawPost.owner.username }}\",\n\"creator_relevance_score\": 0,\n\"engage\": false,\n\"reason\": \"\",\n\"sentiment\": \"\",\n\"category\": \"\",\n\"language\": \"\",\n\"language_eligible\": false\n}\n\nRESPONSE RULES\n\n* Return only valid JSON.\n* Do not include markdown.\n* Do not include explanations.\n* Do not include additional text.\n* Do not include code blocks.\n* Always populate every field.\n* If engage=false, clearly explain why in the reason field.\n* Base the score on both topic relevance and language eligibility.\n* Non-English content should normally score below 40.\n* Content must be both English and relevant to achieve a score of 70 or above."
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "466617b5-e9d9-420b-bc4c-77a858370b84",
      "name": "CheckImageRelevancy",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        7424,
        1040
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "openai/gpt-4-turbo",
          "cachedResultName": "OPENAI/GPT-4-TURBO"
        },
        "options": {},
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "57712598-5a40-40d6-95f7-8e685d39428a",
      "name": "GetImage",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        7216,
        1040
      ],
      "parameters": {
        "url": "={{ $json.rawPost.preview_image.url }}",
        "options": {}
      },
      "typeVersion": 4.4
    },
    {
      "id": "2870dd96-726b-46ea-8ef8-a77c92d7049d",
      "name": "Get Influencer Data",
      "type": "n8n-nodes-base.postgres",
      "position": [
        6192,
        1136
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "_influencer",
          "cachedResultName": "_influencer"
        },
        "where": {
          "values": [
            {
              "value": "INSTAGRAM",
              "column": "sourcePlatform"
            },
            {
              "value": "INSTAGRAM",
              "column": "connectionPlatform"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "workspace_13mbc2c4oiu70a17e1h9z0mxn",
          "cachedResultName": "workspace_13mbc2c4oiu70a17e1h9z0mxn"
        },
        "options": {},
        "operation": "select",
        "returnAll": true
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "ee77a7a5-a9ec-46f0-9207-a6aede1afd1a",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6000,
        80
      ],
      "parameters": {
        "color": 3,
        "width": 384,
        "height": 704,
        "content": "## 1. WORKFLOW OVERVIEW & ARCHITECTURE\n\nPURPOSE\nCollect Instagram influencer data and identify the latest post that can be evaluated for engagement.\n\nFLOW\n\nSchedule Trigger\n\u2193\nGet Influencer Data\n\u2193\nLoop Over Items\n\u2193\nFetch Influencer Post\n\u2193\nFormat Post\n\u2193\nPost Eligibility Check"
      },
      "typeVersion": 1
    },
    {
      "id": "6f93810c-4b75-4ec8-a7a5-2f255c876ce2",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6384,
        80
      ],
      "parameters": {
        "color": 3,
        "width": 576,
        "height": 704,
        "content": "## CODE RESPONSIBILITIES\n\n1. Schedule Trigger\n\u2022 Starts the workflow automatically according to the configured schedule.\n\n2. Get Influencer Data\n\u2022 Retrieves Instagram influencer records from the database.\n\u2022 Provides the profile/username/account information required for API calls.\n\n3. Loop Over Items\n\u2022 Processes one influencer at a time.\n\u2022 Ensures each influencer is handled independently.\n\u2022 Skipped/processed influencers return to the loop.\n\n4. Fetch_Influencer_Post\n\u2022 Uses the Instagram/Unipile integration to retrieve recent posts.\n\u2022 Retrieves the post information required for analysis.\n\n5. formatPost\n\u2022 Normalizes the API response into a standard structure.\n\u2022 Prepares fields such as:\n  - post_id\n  - post_url\n  - caption\n  - post date\n  - influencer/profile information\n  - engagement information\n\n6. hasTodayPost\n\u2022 Performs the first eligibility check.\n\u2022 Verifies that a usable and recent post exists.\n\u2022 Prevents processing of already-commented/ineligible posts.\n\nOUTPUT\nOnly eligible posts continue to AI content evaluation."
      },
      "typeVersion": 1
    },
    {
      "id": "7db9f555-b702-44ee-ba32-eb0c923194fe",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6992,
        80
      ],
      "parameters": {
        "color": 6,
        "width": 1184,
        "height": 704,
        "content": "2. CONTENT EVALUATION & RELEVANCY CHECKS\n\nPURPOSE\nDetermine whether the Instagram post is relevant and appropriate for professional engagement.\n\nThe workflow performs TWO AI evaluations:\n\nA. TEXT RELEVANCY\nB. IMAGE RELEVANCY\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\nA. TEXT RELEVANCY\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\nNode: checkPostRelevancyText\n\nAI evaluates:\n\u2022 Caption/content\n\u2022 Topic\n\u2022 Category\n\u2022 Sentiment\n\u2022 Language\n\u2022 Professional relevance\n\u2022 Educational relevance\n\nPREFERRED TOPICS\n\n\u2713 AI & Technology\n\u2713 Education\n\u2713 Career Development\n\u2713 Leadership\n\u2713 Employability\n\u2713 Upskilling / Reskilling\n\u2713 Future of Work\n\u2713 Programming\n\u2713 Data Science\n\u2713 Digital Skills\n\u2713 Business / Entrepreneurship\n\u2713 Professional Development\n"
      },
      "typeVersion": 1
    },
    {
      "id": "de086078-b2f8-4f76-8617-130b888d68d7",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7664,
        80
      ],
      "parameters": {
        "color": 6,
        "width": 576,
        "height": 704,
        "content": "\nGENERALLY EXCLUDED\n\n\u2717 Personal content\n\u2717 Entertainment\n\u2717 Food / Travel\n\u2717 Fashion / Lifestyle\n\u2717 Politics / Religion\n\u2717 Sports / Gaming\n\u2717 Celebrity / Music / Movies\n\u2717 Relationships\n\u2717 Irrelevant promotional content\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\nB. IMAGE RELEVANCY\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\nNode: GetImage\n\u2022 Retrieves the post image.\n\nNode: CheckImageRelevancy\n\u2022 Uses AI vision analysis.\n\u2022 Determines whether the image supports the post's professional/relevant context.\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\nC. MERGE RESULTS\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\nNode: Merge\n\u2022 Combines text and image analysis results.\n\nNode: format_Relevancy\n\u2022 Converts AI output into structured fields.\n\nNode: check_relevancy\n\u2022 Makes the final engagement decision.\n\nPOST CONTINUES ONLY IF:\n\n\u2713 Content is relevant\n\u2713 AI recommends engagement\n\u2713 Relevance score meets the configured threshold\n\u2713 Language/content is eligible\n\nIF NOT ELIGIBLE\n\u2192 Skip post\n\u2192 Return to Loop Over Items\n\nIF ELIGIBLE\n\u2192 Generate comment"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "timezone": "Asia/Kolkata",
    "binaryMode": "separate",
    "callerPolicy": "workflowsFromSameOwner",
    "timeSavedMode": "fixed",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "cf886280-c043-4cdd-9e68-40f22cb343af",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Parse data from the check comment status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "format_Relevancy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "checkCommentExists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetImage": {
      "main": [
        [
          {
            "node": "CheckImageRelevancy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "send_Like": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "formatPost": {
      "main": [
        [
          {
            "node": "hasTodayPost",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "format_Json": {
      "main": [
        [
          {
            "node": "Get id and last post id from nebula",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "hasTodayPost": {
      "main": [
        [
          {
            "node": "checkPostRelevancyText",
            "type": "main",
            "index": 0
          },
          {
            "node": "GetImage",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "send_Comment": {
      "main": [
        [
          {
            "node": "Parse data to send in nebula",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Fetch_Influencer_Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check_relevancy": {
      "main": [
        [
          {
            "node": "Agent for Generating Comment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Influencer Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "format_Relevancy": {
      "main": [
        [
          {
            "node": "check_relevancy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "checkCommentExists": {
      "main": [
        [
          {
            "node": "send_Like",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CheckImageRelevancy": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute a SQL query": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Influencer Data": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch_Influencer_Post": {
      "main": [
        [
          {
            "node": "formatPost",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "checkPostRelevancyText": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Agent for Generating Comment": {
      "main": [
        [
          {
            "node": "format_Json",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse data to send in nebula": {
      "main": [
        [
          {
            "node": "Execute a SQL query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get id and last post id from nebula": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse data from the check comment status": {
      "main": [
        [
          {
            "node": "send_Comment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}