{
  "name": "Arenza \u2014 Weekly GEO Digest to Slack",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1"
            }
          ]
        }
      },
      "id": "node-cron",
      "name": "Schedule: Mondays 9 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.arenza.ai/v1/brands",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "retry": {
            "maxRetries": 3,
            "waitBetweenRetries": 5000
          }
        }
      },
      "id": "node-list-brands",
      "name": "GET /v1/brands",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "id": "node-split-brands",
      "name": "Split Brands",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "url": "=https://api.arenza.ai/v1/brands/{{ $json.id }}/overview",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "retry": {
            "maxRetries": 3,
            "waitBetweenRetries": 5000
          }
        }
      },
      "id": "node-overview",
      "name": "GET /brands/:id/overview",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        220
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.arenza.ai/v1/brands/{{ $json.id }}/opportunities?limit=5&sort=lift_desc",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "retry": {
            "maxRetries": 3,
            "waitBetweenRetries": 5000
          }
        }
      },
      "id": "node-opportunities",
      "name": "GET /brands/:id/opportunities",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        380
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "id": "node-merge",
      "name": "Merge Overview + Opportunities",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1140,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Format an Arenza brand snapshot into a Slack Block Kit message.\n// Input: merged item with brand overview + top opportunities.\n// Output: { channel, blocks } per item.\n\nconst MAX_MESSAGE_LENGTH = 3500;\n\n// Map brand_id -> Slack channel. Edit for per-client channels.\nconst BRAND_CHANNEL_MAP = {\n  // 'brand-uuid-here': '#client-acme',\n};\nconst DEFAULT_CHANNEL = '#geo-digest';\n\nconst LLMS = ['ChatGPT', 'Claude', 'Gemini', 'Perplexity', 'Copilot', 'Grok'];\n\nreturn items.map(item => {\n  const data = item.json;\n  const brandName = data.name ?? 'unknown brand';\n  const sov = (data.share_of_voice ?? 0).toFixed(1);\n  const wrongClaims = data.wrong_claims ?? 0;\n  const opps = data.opportunities ?? [];\n  const perLLM = data.per_llm_mention_rate ?? {};\n  const channel = BRAND_CHANNEL_MAP[data.id] ?? DEFAULT_CHANNEL;\n\n  const llmRows = LLMS.map(llm => {\n    const rate = perLLM[llm.toLowerCase()] ?? 0;\n    return `\u2022 ${llm}: ${(rate * 100).toFixed(0)}%`;\n  }).join('\\n');\n\n  const oppRows = opps.slice(0, 5).map((o, i) =>\n    `${i + 1}. *${o.title}* \u2014 +${(o.estimated_lift ?? 0).toFixed(1)} SoV pts`\n  ).join('\\n') || '_No new opportunities this week._';\n\n  const blocks = [\n    {\n      type: 'header',\n      text: { type: 'plain_text', text: `${brandName} \u2014 Weekly GEO Digest` }\n    },\n    {\n      type: 'section',\n      fields: [\n        { type: 'mrkdwn', text: `*Share of Voice*\\n${sov}%` },\n        { type: 'mrkdwn', text: `*Wrong Claims (30d)*\\n${wrongClaims}` }\n      ]\n    },\n    {\n      type: 'section',\n      text: { type: 'mrkdwn', text: `*Mention rate per LLM*\\n${llmRows}` }\n    },\n    {\n      type: 'section',\n      text: { type: 'mrkdwn', text: `*Top opportunities*\\n${oppRows}` }\n    },\n    {\n      type: 'context',\n      elements: [\n        { type: 'mrkdwn', text: `<https://app.arenza.ai/brands/${data.id}|Open in Arenza dashboard> \u00b7 powered by arenza.ai` }\n      ]\n    }\n  ];\n\n  return { json: { channel, blocks } };\n});\n"
      },
      "id": "node-format",
      "name": "Format Slack Blocks",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1360,
        300
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": "={{ $json.channel }}",
        "blocksUi": "={{ JSON.stringify($json.blocks) }}",
        "otherOptions": {}
      },
      "id": "node-slack",
      "name": "Slack: chat.postMessage",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1580,
        300
      ],
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Schedule: Mondays 9 AM": {
      "main": [
        [
          {
            "node": "GET /v1/brands",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET /v1/brands": {
      "main": [
        [
          {
            "node": "Split Brands",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Brands": {
      "main": [
        [
          {
            "node": "GET /brands/:id/overview",
            "type": "main",
            "index": 0
          },
          {
            "node": "GET /brands/:id/opportunities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET /brands/:id/overview": {
      "main": [
        [
          {
            "node": "Merge Overview + Opportunities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET /brands/:id/opportunities": {
      "main": [
        [
          {
            "node": "Merge Overview + Opportunities",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Overview + Opportunities": {
      "main": [
        [
          {
            "node": "Format Slack Blocks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Slack Blocks": {
      "main": [
        [
          {
            "node": "Slack: chat.postMessage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    {
      "name": "arenza"
    },
    {
      "name": "geo"
    },
    {
      "name": "weekly-digest"
    }
  ]
}