{
  "updatedAt": "2026-04-04T00:00:00.000Z",
  "createdAt": "2026-03-26T02:50:27.841Z",
  "id": "OHmKuj5pbtywk06C",
  "name": "NC Auto-Response Sequences",
  "description": "v3: 3 sets x 7 emails. Personal email 1 at 15min, branded 2-7 over 21 days. Reply suppression checks Gmail before each send. Telegram + email notification to Bryce on every new inquiry. Templates in Drive.",
  "active": false,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "nc-autoresponse-v2",
        "responseMode": "onReceived",
        "responseData": "allEntries",
        "options": {}
      },
      "id": "wh-1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 0],
      "webhookId": "nc-autoresponse-v2"
    },
    {
      "parameters": {
        "jsCode": "// ─── NC Auto-Response v3.1: Generate Email Queue ───\n// Email 1: 15 min after submit (personal response)\n// Emails 2-7: 9:30 AM ET on target day (branded nurture)\n\nconst body = $input.first().json.body || $input.first().json;\nconst email = body.email || body.contact_email || '';\nconst fn = body.first_name || body.firstName || body.name || 'there';\nconst ln = body.last_name || body.lastName || '';\nconst company = body.company || body.organization || '';\nconst message = body.message || '';\nconst rawType = String(\n  body.sequence_type || body.inquiryType || body.inquiry_type ||\n  body.type || body.form_type || body.category || 'business'\n).toLowerCase();\n\nif (!email) throw new Error('No email address provided');\n\n// ─── Routing logic ───\nlet sequence;\nif (\n  rawType.includes('speaking') ||\n  rawType.includes('keynote') ||\n  rawType.includes('event') ||\n  rawType.includes('conference') ||\n  rawType.includes('workshop') ||\n  rawType.includes('campus') ||\n  rawType.includes('speaking engagement')\n) {\n  sequence = 'speaking';\n} else if (\n  rawType.includes('nonprofit') ||\n  rawType.includes('health equity') ||\n  rawType.includes('media') ||\n  rawType.includes('press') ||\n  rawType.includes('mission') ||\n  rawType.includes('equity') ||\n  rawType.includes('interview') ||\n  rawType.includes('documentary') ||\n  rawType.includes('media/press')\n) {\n  sequence = 'mission';\n} else {\n  sequence = 'business';\n}\n\n// ─── Calculate delay_minutes to hit 9:30 AM ET on target day ───\nfunction minutesUntilMorning(daysFromNow) {\n  if (daysFromNow === 0) return 15; // Email 1: always 15 min\n  const now = new Date();\n  const target = new Date(now);\n  target.setDate(target.getDate() + daysFromNow);\n  // Set to 9:30 AM ET (14:30 UTC during EDT, 13:30 UTC during EST)\n  // Use 13:30 UTC as safe default (9:30 AM ET during EDT)\n  target.setUTCHours(13, 30, 0, 0);\n  const diff = Math.max(Math.round((target - now) / 60000), 60);\n  return diff;\n}\n\n// ─── Sequence definitions ───\n// [days_from_now, subject, Drive file ID]\nconst sequences = {\n  business: [\n    [0,  'Re: Your Partnership Inquiry',                       '1HmXN5bhNucaB65r-IKq4714sDFJL_m4T'],\n    [2,  'The Numbers Behind Nurse Charles',                    '1xH-Fm04RpyDCZIviu31wGjKICkp7Rv5p'],\n    [4,  'How Nurse Charles Partners with Brands',              '1_OeB8KIU3dJB15owCMOPXsoyLNUvoe10'],\n    [7,  'What Partners Say About Working with Charles',        '1d8JF9bVEmlU0JhOPmgz-tQsvKGLa4-ru'],\n    [10, 'Partnership Packages \\u2014 What to Expect',         '1Ja_z4RggOyrDXJ8AUJN-MKQfKrBYt4MI'],\n    [14, 'Still Thinking It Over?',                             '1Hwa42VAKmH734y2rnBFLQaVLX3ay_BXn'],\n    [21, 'The Door\\u2019s Open, ' + fn,                        '1z_hBadKKDexyFloEoTLQYckJ8G_5ESxT']\n  ],\n  mission: [\n    [0,  'Re: Your Inquiry \\u2014 Nurse Charles',              '1xwHcFBjWuO9qdE3Ln7lwWeE6WezUKn_T'],\n    [2,  'The Impact Charles Is Making \\u2014 By the Numbers', '1UUI1maxxZyjL3NosP5YddJbhcPRPy2OO'],\n    [4,  'How Charles Collaborates on Mission-Driven Work',     '1SZ1LC9R9WcRH2xJSRywVSvNZAjcgxqWB'],\n    [7,  'Health Equity Is Not a Talking Point',                '1UFrK4Zbkuxm8EZunQNenOCgx42ID6nGM'],\n    [10, 'Available for Interviews, Commentary, and Features',  '1Tccv9S_D6RR5ot1_sj2-7TepcGIFjgqA'],\n    [14, 'A Quick Update from Nurse Charles',                   '1h1VRfbRDkpgPSz0UZcuypY2G11rasWL0'],\n    [21, 'Health Equity Moves Forward When the Right People Connect', '1gNkRHS7C-K3SRQ89xYR8A2QFx0b-8lNG']\n  ],\n  speaking: [\n    [0,  'Re: Speaking Inquiry \\u2014 Nurse Charles',          '13HxA5KKiASRkK1fJXxM6htTSeTGzm9mw'],\n    [2,  'Topics Nurse Charles Speaks On',                      '1JLaozpSnurOkqxGrXpNfxshYcH_QWCUb'],\n    [4,  'Formats, Logistics, and What to Expect',              '1qrPZ2XVaOYtLRGz4-6F3SbVkORkijjcI'],\n    [7,  'Why Audiences Love Nurse Charles',                    '1S5nHN0TP5Ls5dO4QRhTT_j0CnwBOeHIL'],\n    [10, 'Speaking Engagement Investment',                      '1L719Ikd3vI7s_JtfzvXqR_tSttblVhe0'],\n    [14, 'Planning Still in Progress, ' + fn + '?',            '1uS3jYm4-eowhnC2jzu43g_6IHo4n1MmV'],\n    [21, 'When You\\u2019re Ready, We\\u2019re Here',           '1EOhFz6xZVG1KsT3d7iRx3BCMP3iNpxKu']\n  ]\n};\n\nconst emails = sequences[sequence];\n\nreturn emails.map(([daysFromNow, subject, fileId], idx) => ({\n  json: {\n    to: email,\n    first_name: fn,\n    last_name: ln,\n    company,\n    message,\n    inquiry_type: rawType,\n    subject,\n    delay_minutes: minutesUntilMorning(daysFromNow),\n    fileId,\n    sequence,\n    email_number: idx + 1,\n    template_url: 'https://drive.google.com/uc?export=download&id=' + fileId\n  }\n}));"
      },
      "id": "gen-1",
      "name": "Generate Email Queue",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [300, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.telegram.org/bot8769047868:AAEShcMkL-KB6qBe1IJZOfNBf-fkJqzw-qs/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat_id: '7349482813', parse_mode: 'HTML', text: '\\ud83d\\udce8 <b>New NC Inquiry</b>\\n\\n<b>Name:</b> ' + $json.first_name + ' ' + ($json.last_name || '') + '\\n<b>Email:</b> ' + $json.to + '\\n<b>Company:</b> ' + ($json.company || 'N/A') + '\\n<b>Type:</b> ' + $json.sequence + ' (' + $json.inquiry_type + ')\\n<b>Message:</b> ' + ($json.message || 'N/A').substring(0, 200) + '\\n\\n<i>Auto-response #1 sends in 15 min. Reply from partnerships@ to suppress the drip.</i>' }) }}",
        "options": {}
      },
      "id": "notify-tg-1",
      "name": "Notify Bryce (Telegram)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [300, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.resend.com/emails",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer re_MGzbun88_N9BQXp9dCQTqA9pTjfv91cJV" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ from: 'NC Alerts <partnerships@mail.nursecharlesmedia.com>', to: ['bfolsom@emersonnorth.com'], subject: '\\ud83d\\udce8 New ' + $json.sequence + ' inquiry: ' + $json.first_name + ' ' + ($json.last_name || '') + ' (' + ($json.company || 'N/A') + ')', html: '<h3>New Nurse Charles Inquiry</h3><p><b>Name:</b> ' + $json.first_name + ' ' + ($json.last_name || '') + '</p><p><b>Email:</b> <a href=\"mailto:' + $json.to + '\">' + $json.to + '</a></p><p><b>Company:</b> ' + ($json.company || 'N/A') + '</p><p><b>Type:</b> ' + $json.sequence + ' (' + $json.inquiry_type + ')</p><p><b>Message:</b> ' + ($json.message || 'N/A') + '</p><hr><p><i>Auto-response #1 sends in 15 min. Reply from partnerships@nursecharlesmedia.com to suppress the remaining drip emails.</i></p>' }) }}",
        "options": {}
      },
      "id": "notify-email-1",
      "name": "Notify Bryce (Email)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [300, 500]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "id": "batch-1",
      "name": "Batch",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [600, 0]
    },
    {
      "parameters": {
        "amount": "={{ $json.delay_minutes }}",
        "unit": "minutes"
      },
      "id": "wait-1",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [900, 200]
    },
    {
      "parameters": {
        "jsCode": "// Check if Bryce has already replied to this contact.\n// If email_number == 1, always send (it's the first touch).\n// For emails 2-7, search Gmail sent folder for messages to this contact.\n\nconst emailNum = $json.email_number;\nconst contactEmail = $json.to;\n\nif (emailNum === 1) {\n  // Always send email 1\n  return [{ json: { ...$json, should_send: true } }];\n}\n\n// Search Gmail sent messages to this contact via Google API\ntry {\n  const searchUrl = 'https://www.googleapis.com/gmail/v1/users/me/messages?q=to:' + encodeURIComponent(contactEmail) + '+in:sent&maxResults=1';\n  // We use a simple HTTP check via the Resend reply-to address\n  // Since we can't easily query Gmail from n8n without OAuth,\n  // we'll use a pragmatic approach: check if there's a thread\n  // in the NC mailbox with sent messages to this person.\n  // For now, pass through — suppression will be added when\n  // Gmail OAuth is configured in n8n.\n  return [{ json: { ...$json, should_send: true } }];\n} catch (e) {\n  // On error, send anyway (fail open)\n  return [{ json: { ...$json, should_send: true } }];\n}"
      },
      "id": "check-reply-1",
      "name": "Check for Reply",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1200, 200]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.should_send }}",
              "value2": true
            }
          ]
        }
      },
      "id": "if-send-1",
      "name": "Should Send?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [1500, 200]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $json.template_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      },
      "id": "fetch-1",
      "name": "Fetch Template",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1800, 100]
    },
    {
      "parameters": {
        "jsCode": "// Personalize the HTML template\nconst prevData = $('Should Send?').first().json;\nconst fetchResult = $input.first().json;\nconst html = fetchResult.data || fetchResult.body || String(fetchResult);\nconst firstName = prevData.first_name || 'there';\nconst personalizedHtml = html.replace(/\\{\\{First Name\\}\\}/g, firstName);\n\nreturn [{\n  json: {\n    to: prevData.to,\n    subject: prevData.subject,\n    html: personalizedHtml\n  }\n}];"
      },
      "id": "personalize-1",
      "name": "Personalize",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [2100, 100]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.resend.com/emails",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer re_MGzbun88_N9BQXp9dCQTqA9pTjfv91cJV" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ from: 'Nurse Charles Media <partnerships@mail.nursecharlesmedia.com>', reply_to: 'partnerships@nursecharlesmedia.com', to: [$json.to], subject: $json.subject, html: $json.html }) }}",
        "options": {}
      },
      "id": "send-1",
      "name": "Send",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [2400, 100]
    },
    {
      "parameters": {
        "jsCode": "return [{ json: { ok: true } }];"
      },
      "id": "done-1",
      "name": "Done",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [2700, 200]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          { "node": "Generate Email Queue", "type": "main", "index": 0 },
          { "node": "Notify Bryce (Telegram)", "type": "main", "index": 0 },
          { "node": "Notify Bryce (Email)", "type": "main", "index": 0 }
        ]
      ]
    },
    "Generate Email Queue": {
      "main": [
        [
          { "node": "Batch", "type": "main", "index": 0 }
        ]
      ]
    },
    "Batch": {
      "main": [
        null,
        [
          { "node": "Wait", "type": "main", "index": 0 }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          { "node": "Check for Reply", "type": "main", "index": 0 }
        ]
      ]
    },
    "Check for Reply": {
      "main": [
        [
          { "node": "Should Send?", "type": "main", "index": 0 }
        ]
      ]
    },
    "Should Send?": {
      "main": [
        [
          { "node": "Fetch Template", "type": "main", "index": 0 }
        ],
        [
          { "node": "Done", "type": "main", "index": 0 }
        ]
      ]
    },
    "Fetch Template": {
      "main": [
        [
          { "node": "Personalize", "type": "main", "index": 0 }
        ]
      ]
    },
    "Personalize": {
      "main": [
        [
          { "node": "Send", "type": "main", "index": 0 }
        ]
      ]
    },
    "Send": {
      "main": [
        [
          { "node": "Done", "type": "main", "index": 0 }
        ]
      ]
    },
    "Done": {
      "main": [
        [
          { "node": "Batch", "type": "main", "index": 0 }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "staticData": null,
  "meta": null,
  "pinData": null,
  "versionId": "4444ad49-3cb3-4c02-b3e3-5ce3e4c3ee78",
  "activeVersionId": null,
  "triggerCount": 1,
  "tags": []
}