{
  "name": "TrendTrack — Competitor Email Watch → Slack",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 11
            }
          ]
        }
      },
      "id": "e040ec64-f4d0-4a5d-82f4-2e326ca45c4e",
      "name": "Every Day at 11am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [240, 304]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "folderName",
              "value": "Demo",
              "type": "string"
            },
            {
              "id": "2",
              "name": "slackChannelId",
              "value": "C0123456789",
              "type": "string"
            },
            {
              "id": "3",
              "name": "maxBrandsPerRun",
              "value": 50,
              "type": "number"
            },
            {
              "id": "4",
              "name": "maxEmailsPerBrand",
              "value": 20,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "579f5b43-2719-487e-988d-3266be088162",
      "name": "Set Parameters",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [464, 304]
    },
    {
      "parameters": {
        "jsCode": "const data = $getWorkflowStaticData('global');\nconst params = $('Set Parameters').first().json;\nconst sentAfter = data.lastEmailCheckAt || $now.minus({ hours: 24 }).toISO();\ndata.lastEmailCheckAt = $now.toISO();\nreturn [{ json: { sentAfter, folderName: params.folderName, slackChannelId: params.slackChannelId, maxBrandsPerRun: params.maxBrandsPerRun, maxEmailsPerBrand: params.maxEmailsPerBrand } }];"
      },
      "id": "911ab818-0dc6-4aee-89ff-87fbc4820949",
      "name": "Read & Update Cursor",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [688, 304],
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "url": "https://api.trendtrack.io/v1/brandtrackers",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "folderNames",
              "value": "={{ $json.folderName }}"
            },
            {
              "name": "limit",
              "value": "={{ $json.maxBrandsPerRun }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.TRENDTRACK_API_KEY }}"
            }
          ]
        },
        "options": {
          "queryParameterArrays": "repeat"
        }
      },
      "id": "dfc85778-7882-48aa-a7de-107735a90c1a",
      "name": "Fetch Brandtrackers In Folder",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [912, 304]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "id": "720808e2-c24d-425e-8b54-f33d00dfa37f",
      "name": "Split Brandtrackers",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [1120, 304]
    },
    {
      "parameters": {
        "url": "https://api.trendtrack.io/v1/lookup/facebook-shop",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "facebookPageId",
              "value": "={{ $json.facebookPageId }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.TRENDTRACK_API_KEY }}"
            }
          ]
        },
        "options": {}
      },
      "id": "7398b3ba-0aff-4d77-aee7-a8febcd121af",
      "name": "Resolve Shop From BT",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [1344, 304],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "shopId",
              "value": "={{ $json.data?.primaryShop?.id || \"\" }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "shopDomain",
              "value": "={{ $json.data?.primaryShop?.domain || \"\" }}",
              "type": "string"
            },
            {
              "id": "3",
              "name": "brandName",
              "value": "={{ $('Split Brandtrackers').item.json.name || \"\" }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "2e55666b-a184-4a52-b70f-e37a71be8cd3",
      "name": "Extract ShopId",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1568, 304],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "combinator": "and",
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "1",
              "leftValue": "={{ $json.shopId }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            }
          ]
        },
        "options": {}
      },
      "id": "0e965d74-0266-4403-9c39-e27e053f8073",
      "name": "Has ShopId",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.3,
      "position": [1792, 304]
    },
    {
      "parameters": {
        "url": "={{ 'https://api.trendtrack.io/v1/shops/' + $json.shopId + '/emails' }}",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "sentAfter",
              "value": "={{ $('Read & Update Cursor').first().json.sentAfter }}"
            },
            {
              "name": "sortBy",
              "value": "newest"
            },
            {
              "name": "limit",
              "value": "={{ $('Read & Update Cursor').first().json.maxEmailsPerBrand }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.TRENDTRACK_API_KEY }}"
            }
          ]
        },
        "options": {}
      },
      "id": "06508263-5919-47f9-a022-23379a355433",
      "name": "Fetch Recent Emails",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [2000, 304]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "id": "b524cc3d-33f4-43a2-a934-54f6d9d7403c",
      "name": "Split Emails",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [2224, 304]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const e = $input.item.json;\nconst params = $('Read & Update Cursor').first().json;\nconst shopName = e.shop?.name || 'Unknown';\nconst subject = e.content?.subject || '(no subject)';\nconst preheader = e.content?.preheader || '';\nconst sentAt = e.sentAt || '';\nconst campaignType = e.campaignType || 'unknown';\nconst screenshotUrl = e.content?.screenshotUrl;\nconst blocks = [\n  { type: 'header', text: { type: 'plain_text', text: '📧 New email — ' + shopName } },\n  { type: 'section', text: { type: 'mrkdwn', text: '*' + subject + '*\\n_' + preheader + '_\\nSent ' + sentAt + ' · type: ' + campaignType } },\n];\nif (screenshotUrl) blocks.push({ type: 'image', image_url: screenshotUrl, alt_text: 'Email screenshot' });\nreturn { json: { _slackBlocks: blocks, _slackText: '📧 New email from ' + shopName + ': ' + subject, _slackChannelId: params.slackChannelId } };"
      },
      "id": "dd6cc22a-2419-4454-944b-f56f2afc2dfe",
      "name": "Build Slack Blocks",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [2448, 304],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json._slackChannelId }}"
        },
        "messageType": "block",
        "blocksUi": "={{ JSON.stringify({ blocks: $json._slackBlocks }) }}",
        "text": "={{ $json._slackText }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "id": "e1532337-e522-4043-8bc9-088bea601bbf",
      "name": "Post Email to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.4,
      "position": [2672, 304]
    }
  ],
  "connections": {
    "Every Day at 11am": {
      "main": [
        [
          {
            "node": "Set Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Parameters": {
      "main": [
        [
          {
            "node": "Read & Update Cursor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read & Update Cursor": {
      "main": [
        [
          {
            "node": "Fetch Brandtrackers In Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Brandtrackers In Folder": {
      "main": [
        [
          {
            "node": "Split Brandtrackers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Brandtrackers": {
      "main": [
        [
          {
            "node": "Resolve Shop From BT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolve Shop From BT": {
      "main": [
        [
          {
            "node": "Extract ShopId",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract ShopId": {
      "main": [
        [
          {
            "node": "Has ShopId",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has ShopId": {
      "main": [
        [
          {
            "node": "Fetch Recent Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Recent Emails": {
      "main": [
        [
          {
            "node": "Split Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Emails": {
      "main": [
        [
          {
            "node": "Build Slack Blocks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Slack Blocks": {
      "main": [
        [
          {
            "node": "Post Email to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": true
  },
  "tags": []
}
