{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "380fa486-1998-4141-a15e-dd4bb35a7873",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        4384,
        1360
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e43a8c91-c360-4302-84cf-33fa46e28ef8",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        5104,
        1152
      ],
      "parameters": {},
      "typeVersion": 3.1
    },
    {
      "id": "1ae8a25d-15e1-4875-9c1c-b543877ceca1",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        5120,
        1360
      ],
      "parameters": {
        "model": "llama-3.3-70b-versatile",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "ad7184ac-fcf0-46f1-88cb-d4c35e1ff989",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        5616,
        1440
      ],
      "parameters": {
        "sendTo": "={{ $('Loop Over Contacts').item.json.properties.email.value }}",
        "message": "=<html>\n<body>\n<div style=\"font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 80%; margin: auto;\">\n\n  <h2 style=\"color:#2c3e50;\">Personalized Marketing Campaign Strategy</h2>\n\n  <p>Hello,</p>\n\n  <p>\n    We analyzed your company website and generated a personalized advertising campaign strategy\n    that could help attract more qualified leads and customers.\n  </p>\n\n  <hr>\n\n  <div style=\"background:#f7f9fc; padding:20px; border-radius:8px;\">\n\n    <h3 style=\"color:#34495e;\">Campaign Strategy</h3>\n\n    <p style=\"white-space: pre-line;\">\n      {{$json.campaign}}\n    </p>\n\n  </div>\n\n  <br>\n\n  <div style=\"background:#eef3ff; padding:15px; border-radius:6px;\">\n    <p style=\"margin:0;\">\n      If you'd like, we would be happy to discuss how this campaign could be implemented for your business.\n    </p>\n  </div>\n\n  <br>\n\n  <p>\n    Best regards,<br>\n    <strong>Marketing Strategy Team</strong>\n  </p>\n\n  <hr>\n\n\n</div>\n</body>\n</html>",
        "options": {},
        "subject": "=Your Personalized Marketing Campaign for {{ $('Loop Over Contacts').item.json.properties.company.value }}"
      },
      "typeVersion": 2.2
    },
    {
      "id": "79ac6576-dc25-4a59-965e-582ce8e26dc7",
      "name": "Loop Over Contacts",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        4864,
        1360
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3,
      "alwaysOutputData": false
    },
    {
      "id": "846e91dc-8fbc-4fa8-9e35-35d084d9a873",
      "name": "Format AI's output",
      "type": "n8n-nodes-base.code",
      "position": [
        5424,
        1152
      ],
      "parameters": {
        "jsCode": "let text =$input.first().json.output ;\n\n// convert escaped newline characters to real HTML line breaks\ntext = text.replace(/\\\\n/g, \"<br><br>\");\n\nreturn [\n  {\n    json: {\n      campaign: text\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "dad86144-67bf-4d18-a3f5-f69b1273846f",
      "name": "Search contacts",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        4608,
        1360
      ],
      "parameters": {
        "operation": "search",
        "authentication": "appToken",
        "filterGroupsUi": {
          "filterGroupsValues": [
            {
              "filtersUi": {
                "filterValues": [
                  {
                    "value": "={{ new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString() }}",
                    "operator": "=GTE",
                    "propertyName": "createdate|datetime"
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {}
      },
      "typeVersion": 2.2
    },
    {
      "id": "090b1870-69ec-4e20-9e04-c49ab9a9c8be",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3648,
        848
      ],
      "parameters": {
        "width": 608,
        "height": 800,
        "content": "# Hyper-Personalized Ad Campaign Generator\n\nThis workflow automatically generates AI-powered advertising campaign strategies for newly created CRM contacts and sends them via email.\n\n## How it works\nThe workflow runs on a schedule and retrieves contacts created in the last 24 hours from the CRM. Each contact is processed individually through a loop. Company details such as name and website are sent to an AI agent, which analyzes the business and generates a structured advertising campaign strategy. The output is formatted into a readable format and delivered via email to the contact.\n\n## Setup steps\n1. Connect your HubSpot credentials.\n2. Configure your AI model (Groq) credentials.\n3. Connect your Gmail or SMTP account.\n4. Review and customize the AI prompt if needed.\n5. Activate the workflow.\n\n## Customization tips\n- Adjust the schedule timing based on your needs.\n- Modify the AI prompt for different industries or campaign styles.\n- Customize the email template for branding or personalization."
      },
      "typeVersion": 1
    },
    {
      "id": "344b7f8c-5fa1-4610-a63d-0865c84ab0f4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4288,
        848
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 800,
        "content": "## Fetch New Contacts\n\nRuns on schedule and retrieves contacts created in the last 24 hours from HubSpot."
      },
      "typeVersion": 1
    },
    {
      "id": "620a9e05-9a1b-4a7d-b97e-37d41ca7670d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4784,
        848
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 800,
        "content": "## Generate Campaign & Send Email\n\nAI creates campaign strategy \u2192 format output \u2192 send personalized email."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Send a message": {
      "main": [
        [
          {
            "node": "Loop Over Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search contacts": {
      "main": [
        [
          {
            "node": "Loop Over Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Search contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format AI's output": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}