{
  "nodes": [
    {
      "id": "67f254ab-521c-42e4-b042-c3a5b5bc1859",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        -256
      ],
      "parameters": {
        "width": 480,
        "height": 752,
        "content": "## Pipedrive note reminder before meetings\n\n### How it works\n\n1. A schedule trigger fires periodically and fetches upcoming appointments from Google Calendar.\n2. Custom JavaScript code processes the calendar events and a Pipedrive lookup retrieves the matching contact person.\n3. The workflow fetches the associated lead in Pipedrive and filters out leads that don't exist or where a brief has already been sent.\n4. It then retrieves existing notes on the lead and filters out leads that already have a note, preventing duplicate sends.\n5. A commercial brief email is sent via Gmail to qualifying leads, and the Pipedrive lead label is updated to reflect the action taken.\n\n### Setup steps\n\n- - [ ] Configure the **Schedule Trigger** with the desired polling interval (e.g., every morning).\n- - [ ] Connect a **Google Calendar** account and set the correct calendar ID in the \"Agenda Get RDV\" node.\n- - [ ] Connect a **Pipedrive** account and configure the API key for both Pipedrive nodes and the HTTP request nodes pointing to your Pipedrive instance.\n- - [ ] Update the **Code in JavaScript** node to correctly map calendar event fields (e.g., attendee email) to Pipedrive lookup parameters.\n- - [ ] Connect a **Gmail** account to the \"Send brief commercial\" node and customize the email subject, body, and recipient field.\n- - [ ] Review filter conditions in both filter nodes to match your lead status field names and brief-sent flag logic.\n\n### Customization\n\nYou can adjust the schedule frequency, change the filter conditions to match different lead stages, or replace Gmail with another email node (e.g., SMTP, Outlook) for sending the commercial brief."
      },
      "typeVersion": 1
    },
    {
      "id": "1c3ab287-16ae-463e-ba6f-efe96940c897",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 320,
        "content": "## Scheduled calendar event fetch\n\nThe schedule trigger fires at set intervals and retrieves upcoming appointment events from Google Calendar."
      },
      "typeVersion": 1
    },
    {
      "id": "bcb63fa3-abbb-493b-a28d-ccd46adca32f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1488,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 320,
        "content": "## Process event and get contact\n\nCustom JavaScript transforms the calendar event data, then the matching contact person is fetched from Pipedrive."
      },
      "typeVersion": 1
    },
    {
      "id": "13a23bc8-5634-4be9-835b-d0c0a6913cef",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1904,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 336,
        "content": "## Lead lookup and brief status filter\n\nFetches the associated lead ID from Pipedrive via API, then filters out leads that don't exist or have already received a brief."
      },
      "typeVersion": 1
    },
    {
      "id": "55d28cbb-4233-4f18-9579-42c3e0fb9e9c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2320,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 320,
        "content": "## Retrieve and filter lead notes\n\nFetches existing notes on the Pipedrive lead and filters out any leads that already have a note, preventing duplicate briefs."
      },
      "typeVersion": 1
    },
    {
      "id": "ab6a43b6-3f78-48c0-bb43-44edfa698c0c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2736,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 320,
        "content": "## Send brief and update lead label\n\nSends the commercial brief email via Gmail to qualifying leads, then updates the Pipedrive lead label to mark the brief as sent."
      },
      "typeVersion": 1
    },
    {
      "id": "97790ab1-0cb8-4ba9-a7df-254813da5865",
      "name": "Every 30 Minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1104,
        -80
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "9f1baf61-2765-494a-8e03-34a74f8058bf",
      "name": "Parse Calendar Events",
      "type": "n8n-nodes-base.code",
      "position": [
        1536,
        -80
      ],
      "parameters": {
        "jsCode": "const events = $input.all();\nconst results = [];\n\nfor (const item of events) {\n  const event = item.json;\n  \n  if (!event.summary?.includes('Growth AI - Automatisons vos t\u00e2ches')) continue;\n  \n  for (const attendee of event.attendees || []) {\n    if (['user@example.com', 'user@example.com'].includes(attendee.email)) continue;\n    \n    results.push({ json: { email: attendee.email } });\n  }\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "4be8c9e0-69f8-4b69-8566-610eb86b57dc",
      "name": "Fetch Pipedrive Notes",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2368,
        -80
      ],
      "parameters": {
        "url": "https://api.pipedrive.com/v1/notes",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "lead_id",
              "value": "={{ $json.data[0].id }}"
            },
            {
              "name": "limit",
              "value": "100"
            }
          ]
        },
        "nodeCredentialType": "pipedriveApi"
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "719f226c-9ed6-4bd4-8e96-76e09f98772f",
      "name": "Fetch Lead from Pipedrive",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1952,
        -80
      ],
      "parameters": {
        "url": "https://institutdureferencement.pipedrive.com/api/v1/leads",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "person_id",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "nodeCredentialType": "pipedriveApi"
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "d7fd428b-31b5-416f-b6c1-583a0cc02cf7",
      "name": "Fetch Person from Pipedrive",
      "type": "n8n-nodes-base.pipedrive",
      "position": [
        1728,
        -80
      ],
      "parameters": {
        "term": "={{ $json.email }}",
        "resource": "person",
        "operation": "search",
        "additionalFields": {
          "exactMatch": true
        }
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "17e09bd3-95a3-4453-aae1-f3e24c8080c2",
      "name": "Fetch Calendar Appointments",
      "type": "n8n-nodes-base.googleCalendar",
      "position": [
        1296,
        -80
      ],
      "parameters": {
        "options": {},
        "timeMax": "={{ $now.plus({ hour: 2 }) }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "operation": "getAll"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "af90f288-705c-4e18-9ff0-f4d49e899303",
      "name": "Filter Lead Exists and Brief Sent",
      "type": "n8n-nodes-base.filter",
      "position": [
        2144,
        -80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fec10bde-c36c-4248-b669-a420f6ba6ed6",
              "operator": {
                "type": "array",
                "operation": "notContains",
                "rightType": "any"
              },
              "leftValue": "={{ $json.data[0].label_ids }}",
              "rightValue": "e1f62da0-1f83-11f1-a690-7956deb6b47d"
            },
            {
              "id": "90eefbf6-0d71-4359-b9bb-4a1cb93a0616",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.data[0].id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "319f5a6e-5f10-48b8-a630-a8f22be43921",
      "name": "Filter Note Exists",
      "type": "n8n-nodes-base.filter",
      "position": [
        2560,
        -80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e83f2384-ae5f-41f7-8723-1ebbe7381d15",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.data }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "c5aa5e21-16da-4046-8632-ce740f033402",
      "name": "Send Commercial Brief Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2784,
        -80
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $json.data[0].content }}",
        "options": {},
        "subject": "=Commercial brief {{ $json.data[0].person.name }} - {{ $json.data[0].organization.name }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a45dcf02-962e-4399-bfba-d47e4c625812",
      "name": "Update Lead Label in Pipedrive",
      "type": "n8n-nodes-base.pipedrive",
      "position": [
        3008,
        -80
      ],
      "parameters": {
        "leadId": "={{ $('Filter Note Exists').item.json.data[0].lead_id }}",
        "resource": "lead",
        "operation": "update",
        "updateFields": {
          "label_ids": [
            "e1f62da0-1f83-11f1-a690-7956deb6b47d"
          ]
        }
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b0b5033d-77b2-47af-9fcd-643b52af5377",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        -544
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 208,
        "content": "## Need more advanced automation solutions? Contact us for custom enterprise workflows!\n\n# Growth-AI.fr\n\n## https://www.linkedin.com/in/allanvaccarizi/\n## https://www.linkedin.com/in/hugo-marinier-%F0%9F%A7%B2-6537b633/"
      },
      "typeVersion": 1
    },
    {
      "id": "712768ce-cad4-4e31-b7e4-64ec5d179ea1",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        -960
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 400,
        "content": "![Logo Growth AI](https://cdn.prod.website-files.com/6825df5b20329ba581df4914/68d413c43f8729fa336568a6_Logo_horizontal.png)"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Every 30 Minutes": {
      "main": [
        [
          {
            "node": "Fetch Calendar Appointments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Note Exists": {
      "main": [
        [
          {
            "node": "Send Commercial Brief Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Pipedrive Notes": {
      "main": [
        [
          {
            "node": "Filter Note Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Calendar Events": {
      "main": [
        [
          {
            "node": "Fetch Person from Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Lead from Pipedrive": {
      "main": [
        [
          {
            "node": "Filter Lead Exists and Brief Sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Calendar Appointments": {
      "main": [
        [
          {
            "node": "Parse Calendar Events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Person from Pipedrive": {
      "main": [
        [
          {
            "node": "Fetch Lead from Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Commercial Brief Email": {
      "main": [
        [
          {
            "node": "Update Lead Label in Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Lead Exists and Brief Sent": {
      "main": [
        [
          {
            "node": "Fetch Pipedrive Notes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}