{
  "name": "Customer Birthday & Anniversary Emails",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "1be29d0c-fa16-4382-9f1e-314721dc5033",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -760,
        120
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "operation": "search",
        "base": {
          "__rl": true,
          "value": "appPpy7OlMovX9FcB",
          "mode": "list",
          "cachedResultName": "SaaS Support Management"
        },
        "table": {
          "__rl": true,
          "value": "tblakT5rEzqbW9m3v",
          "mode": "list",
          "cachedResultName": "Users"
        },
        "filterByFormula": "=OR(\n  AND(\n    {Date_of_Birth},\n    MONTH({Date_of_Birth}) = MONTH(TODAY()),\n    DAY({Date_of_Birth}) = DAY(TODAY())\n  ),\n  AND(\n    {Anniversary},\n    MONTH({Anniversary}) = MONTH(TODAY()),\n    DAY({Anniversary}) = DAY(TODAY())\n  )\n)\n",
        "options": {}
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        -560,
        120
      ],
      "id": "4be17313-5241-4b0f-880d-a3aeeba55876",
      "name": "Search Client",
      "alwaysOutputData": true,
      "credentials": {
        "airtableTokenApi": {
          "id": "BZ3w6czydL0CijHy",
          "name": "Airtable account"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -140,
        200
      ],
      "id": "082347b3-9e13-4873-a084-c926f18701fe",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "eff6fe23-651d-474d-8d77-3734e1ac4c13",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.Date_of_Birth }}",
              "rightValue": "={{ $('Schedule Trigger').item.json.timestamp }}"
            },
            {
              "id": "b1364fbe-5b07-4c1f-bad6-02ef3e0bf7d4",
              "leftValue": "={{ $json.Anniversary }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "552630a8-1317-48cb-a250-707b66bd0752",
      "name": "Check Available Dates",
      "type": "n8n-nodes-base.if",
      "position": [
        -360,
        120
      ],
      "typeVersion": 2.2
    },
    {
      "parameters": {
        "jsCode": "// Input: one item per person with fields like Date_of_Birth, Anniversary, Full Name, Email Address\n\nconst itemsOut = [];\n\nfor (const item of items) {\n  const data = item.json;\n  const fullName = data[\"Full Name\"] || \"there\";\n  const email = data[\"Email Address\"];\n  const today = new Date().toISOString().slice(5, 10); // \"MM-DD\"\n\n  const dob = data.Date_of_Birth ? data.Date_of_Birth.slice(5, 10) : null;\n  const anniversary = data.Anniversary ? data.Anniversary.slice(5, 10) : null;\n\n  let subject = \"🎉 Greetings!\";\n  let message = `Hello ${fullName},\\n\\nHope you have a wonderful day!`;\n\n  if (dob === today) {\n    subject = \"🎂 Happy Birthday!\";\n    message = `Dear ${fullName},\\n\\nWishing you a very Happy Birthday! 🎈\\nHave a fantastic year ahead!`;\n  } else if (anniversary === today) {\n    subject = \"💍 Happy Anniversary!\";\n    message = `Dear ${fullName},\\n\\nWishing you a very Happy Anniversary! ❤️\\nMay your bond grow stronger every year!`;\n  }\n\n  itemsOut.push({\n    json: {\n      ...data,\n      subject,\n      message,\n      sendTo: email,\n    },\n  });\n}\n\nreturn itemsOut;\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -140,
        20
      ],
      "id": "4e8bfc8b-e84a-4968-9124-7ca717cc580e",
      "name": "Generate Subject & Body"
    },
    {
      "parameters": {
        "sendTo": "={{ $json[\"Email Address\"] }}",
        "subject": "={{ $json.subject }}",
        "emailType": "text",
        "message": "={{ $json.message }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        40,
        20
      ],
      "id": "0344b35c-dc04-4f74-b07b-0461db18d12a",
      "name": "Send Emails",
      "webhookId": "c7dcfa4b-b9e7-4fcd-8288-f8f69963cb77",
      "credentials": {
        "gmailOAuth2": {
          "id": "uDat96OaUczrGBW5",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Search Client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Client": {
      "main": [
        [
          {
            "node": "Check Available Dates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Available Dates": {
      "main": [
        [
          {
            "node": "Generate Subject & Body",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Subject & Body": {
      "main": [
        [
          {
            "node": "Send Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "0f0009c0-2054-459f-8ade-937d10eb440f",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "f1c26778ec36097a9722a22c47c5e9c01f00b8862dadd0121ec118026a370fa6"
  },
  "id": "BTLcjBsjXRAyew3G"
}