{
  "nodes": [
    {
      "parameters": {
        "triggerEvents": [
          "contact.creation"
        ]
      },
      "name": "HubSpot Trigger",
      "type": "n8n-nodes-base.hubspotTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ],
      "credentials": {
        "hubspotApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "get",
        "contactId": "={{$json[\"objectId\"]}}"
      },
      "name": "Get Contact",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "credentials": {
        "hubspotApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "url": "https://api.hubapi.com/owners/v2/owners/{{ $node[\"Get Contact\"].json[\"properties\"][\"owner_id\"] }}?hapikey={{your_hubspot_api_key}}",
        "method": "GET",
        "options": {},
        "headers": []
      },
      "name": "Get Contact Owner",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "followUpCount",
              "value": "0"
            }
          ]
        },
        "options": {}
      },
      "name": "Initialize Counter",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        450
      ]
    },
    {
      "parameters": {
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
        "messages": [
          {
            "role": "system",
            "content": "You are an expert marketer writing partnership outreach emails for incenti.me."
          },
          {
            "role": "user",
            "content": "Generate an initial outreach email exploring a partnership with incenti.me. Use the contact\u2019s first and last name in the greeting ({{$node[\"Get Contact\"].json[\"properties\"][\"firstname\"]}} {{$node[\"Get Contact\"].json[\"properties\"][\"lastname\"]}}), include a subject, an email stamp at the top, and append the signature:\n--\nBest regards,\nYour Name\nincenti.me\n\nOutput JSON with keys: subject, body."
          }
        ]
      },
      "name": "Generate Initial Email",
      "type": "n8n-nodes-base.openai",
      "typeVersion": 2,
      "position": [
        850,
        300
      ],
      "credentials": {
        "openAIApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "functionCode": "const email = JSON.parse(items[0].json.choices[0].message.content);\nreturn [{ json: email }];"
      },
      "name": "Parse Initial Email",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{$node[\"Get Contact Owner\"].json[\"email\"]}}",
        "toEmail": "={{$node[\"Get Contact\"].json[\"properties\"][\"email\"]}}",
        "subject": "={{$json[\"subject\"]}}",
        "text": "={{$json[\"body\"]}}"
      },
      "name": "Send Initial Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        1250,
        300
      ],
      "credentials": {
        "gmailOAuth2Api": "<your credential>"
      }
    },
    {
      "parameters": {
        "mode": "delay",
        "delay": 3,
        "unit": "days"
      },
      "name": "Wait 3 Days",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1450,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "followUpCount",
              "value": "1"
            }
          ]
        },
        "options": {
          "keepOnlySet": false
        }
      },
      "name": "Set FollowUp 1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1650,
        200
      ]
    },
    {
      "parameters": {
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
        "messages": [
          {
            "role": "system",
            "content": "You are an expert marketer writing follow-up emails for incenti.me."
          },
          {
            "role": "user",
            "content": "Follow-up #{{$json[\"followUpCount\"]}}: Write a polite follow-up email referencing the previous outreach. Explore a partnership with incenti.me, address {{$node[\"Get Contact\"].json[\"properties\"][\"firstname\"]}} by name, and output JSON with subject and body."
          }
        ]
      },
      "name": "Generate FollowUp Email 1",
      "type": "n8n-nodes-base.openai",
      "typeVersion": 2,
      "position": [
        1850,
        200
      ],
      "credentials": {
        "openAIApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "functionCode": "const email = JSON.parse(items[0].json.choices[0].message.content);\nreturn [{ json: email }];"
      },
      "name": "Parse FollowUp Email 1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        2050,
        200
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{$node[\"Get Contact Owner\"].json[\"email\"]}}",
        "toEmail": "={{$node[\"Get Contact\"].json[\"properties\"][\"email\"]}}",
        "subject": "={{$json[\"subject\"]}}",
        "text": "={{$json[\"body\"]}}"
      },
      "name": "Send FollowUp 1",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        2250,
        200
      ],
      "credentials": {
        "gmailOAuth2Api": "<your credential>"
      }
    },
    {
      "parameters": {
        "mode": "delay",
        "delay": 3,
        "unit": "days"
      },
      "name": "Wait 3 Days 2",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        2450,
        200
      ]
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "followUpCount",
              "value": "2"
            }
          ]
        },
        "options": {
          "keepOnlySet": false
        }
      },
      "name": "Set FollowUp 2",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        2650,
        200
      ]
    },
    {
      "parameters": {
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
        "messages": [
          {
            "role": "system",
            "content": "You are an expert marketer writing follow-up emails for incenti.me."
          },
          {
            "role": "user",
            "content": "Follow-up #{{$json[\"followUpCount\"]}}: Write a polite follow-up email referencing our previous messages. Address {{$node[\"Get Contact\"].json[\"properties\"][\"firstname\"]}} by name, and output JSON with subject and body."
          }
        ]
      },
      "name": "Generate FollowUp Email 2",
      "type": "n8n-nodes-base.openai",
      "typeVersion": 2,
      "position": [
        2850,
        200
      ],
      "credentials": {
        "openAIApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "functionCode": "const email = JSON.parse(items[0].json.choices[0].message.content);\nreturn [{ json: email }];"
      },
      "name": "Parse FollowUp Email 2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        3050,
        200
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{$node[\"Get Contact Owner\"].json[\"email\"]}}",
        "toEmail": "={{$node[\"Get Contact\"].json[\"properties\"][\"email\"]}}",
        "subject": "={{$json[\"subject\"]}}",
        "text": "={{$json[\"body\"]}}"
      },
      "name": "Send FollowUp 2",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        3250,
        200
      ],
      "credentials": {
        "gmailOAuth2Api": "<your credential>"
      }
    },
    {
      "parameters": {
        "mode": "delay",
        "delay": 3,
        "unit": "days"
      },
      "name": "Wait 3 Days 3",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        3450,
        200
      ]
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "followUpCount",
              "value": "3"
            }
          ]
        },
        "options": {
          "keepOnlySet": false
        }
      },
      "name": "Set FollowUp 3",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        3650,
        200
      ]
    },
    {
      "parameters": {
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
        "messages": [
          {
            "role": "system",
            "content": "You are an expert marketer writing follow-up emails for incenti.me."
          },
          {
            "role": "user",
            "content": "Follow-up #{{$json[\"followUpCount\"]}}: Write a final polite follow-up email referencing our prior correspondence. Address {{$node[\"Get Contact\"].json[\"properties\"][\"firstname\"]}} by name, and output JSON with subject and body."
          }
        ]
      },
      "name": "Generate FollowUp Email 3",
      "type": "n8n-nodes-base.openai",
      "typeVersion": 2,
      "position": [
        3850,
        200
      ],
      "credentials": {
        "openAIApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "functionCode": "const email = JSON.parse(items[0].json.choices[0].message.content);\nreturn [{ json: email }];"
      },
      "name": "Parse FollowUp Email 3",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        4050,
        200
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{$node[\"Get Contact Owner\"].json[\"email\"]}}",
        "toEmail": "={{$node[\"Get Contact\"].json[\"properties\"][\"email\"]}}",
        "subject": "={{$json[\"subject\"]}}",
        "text": "={{$json[\"body\"]}}"
      },
      "name": "Send FollowUp 3",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        4250,
        200
      ],
      "credentials": {
        "gmailOAuth2Api": "<your credential>"
      }
    }
  ],
  "connections": {
    "HubSpot Trigger": {
      "main": [
        [
          {
            "node": "Get Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Contact": {
      "main": [
        [
          {
            "node": "Get Contact Owner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Contact Owner": {
      "main": [
        [
          {
            "node": "Initialize Counter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Initialize Counter": {
      "main": [
        [
          {
            "node": "Generate Initial Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Initial Email": {
      "main": [
        [
          {
            "node": "Parse Initial Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Initial Email": {
      "main": [
        [
          {
            "node": "Send Initial Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Initial Email": {
      "main": [
        [
          {
            "node": "Wait 3 Days",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 3 Days": {
      "main": [
        [
          {
            "node": "Set FollowUp 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set FollowUp 1": {
      "main": [
        [
          {
            "node": "Generate FollowUp Email 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate FollowUp Email 1": {
      "main": [
        [
          {
            "node": "Parse FollowUp Email 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse FollowUp Email 1": {
      "main": [
        [
          {
            "node": "Send FollowUp 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send FollowUp 1": {
      "main": [
        [
          {
            "node": "Wait 3 Days 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 3 Days 2": {
      "main": [
        [
          {
            "node": "Set FollowUp 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set FollowUp 2": {
      "main": [
        [
          {
            "node": "Generate FollowUp Email 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate FollowUp Email 2": {
      "main": [
        [
          {
            "node": "Parse FollowUp Email 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse FollowUp Email 2": {
      "main": [
        [
          {
            "node": "Send FollowUp 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send FollowUp 2": {
      "main": [
        [
          {
            "node": "Wait 3 Days 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 3 Days 3": {
      "main": [
        [
          {
            "node": "Set FollowUp 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set FollowUp 3": {
      "main": [
        [
          {
            "node": "Generate FollowUp Email 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate FollowUp Email 3": {
      "main": [
        [
          {
            "node": "Parse FollowUp Email 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse FollowUp Email 3": {
      "main": [
        [
          {
            "node": "Send FollowUp 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}