{
  "name": "Send a reschedule link when a booking is canceled",
  "nodes": [
    {
      "parameters": {
        "content": "## Send a reschedule link when a booking is canceled\n\nPortfolio demo only. This workflow is an original example for demonstration. It is not client work and it does not represent a deployment for any customer.\n\nRun **Run demo** to execute the offline rules engine. The live branch is used only when the incoming item sets `demo` to false and the placeholder credentials have been replaced.",
        "height": 220,
        "width": 520,
        "color": 4
      },
      "id": "3a463964-3e2d-42d8-93ac-c2157bffafc2",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "76be3ed6-4b0f-4380-b857-335c6058566a",
      "name": "Run demo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        40,
        280
      ],
      "notes": "CLI and the n8n editor start here. An empty manual run loads the bundled sample.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "cancellation-reschedule-link",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "9ee0c6f8-6e77-4dbf-838d-bb858be97a0c",
      "name": "Inbound webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        40,
        460
      ],
      "notes": "POST JSON to this path. Include demo:false only after credentials are connected.",
      "notesInFlow": true,
      "webhookId": "2267c2d1-9e13-40d2-94e5-05bb007eebf5"
    },
    {
      "parameters": {
        "events": [
          "invitee.created",
          "invitee.canceled"
        ]
      },
      "id": "77fa872f-1e4c-459a-aa30-608ae8cc9fec",
      "name": "Calendly trigger",
      "type": "n8n-nodes-base.calendlyTrigger",
      "typeVersion": 1,
      "position": [
        40,
        640
      ],
      "credentials": {
        "calendlyOAuth2Api": {
          "id": "PLACEHOLDER_CALENDLYOAUTH2API",
          "name": "Calendly account"
        }
      },
      "notes": "invitee.created and invitee.canceled. Cal.com can hit the inbound webhook with the same payload shape.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const sample = {\n  \"demo\": true,\n  \"email\": \"nora@brightline.example\",\n  \"phone\": \"+15555550123\",\n  \"title\": \"Ops audit with Brightline\",\n  \"start\": \"2026-12-02T15:00:00.000Z\",\n  \"end\": \"2026-12-02T15:30:00.000Z\",\n  \"status\": \"canceled\"\n};\nconst incoming = $input.first()?.json ?? {};\nconst provided = Object.keys(incoming).filter((key) => incoming[key] !== undefined && incoming[key] !== null && incoming[key] !== '');\nconst base = provided.length ? { ...sample, ...incoming } : { ...sample };\nconst flag = incoming.demo;\nbase.demo = !(flag === false || flag === 'false' || flag === 0 || flag === '0');\nreturn [{ json: base }];\n"
      },
      "id": "0e1bbfd8-27f9-4719-8bbd-0376c5421366",
      "name": "Normalize input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        340,
        360
      ],
      "notes": "Merges the request over the bundled sample. demo stays true unless the caller explicitly turns it off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst produced = (() => {\n\nconst start = Date.parse(item.start || item.startsAt || '');\nconst status = String(item.status || 'booked').toLowerCase();\nconst offsets = ['24h'];\nconst hours = { '24h': 24, '2h': 2, '1h': 1, '15m': 0.25 };\nconst reminders = offsets.map((offset) => ({\n  offset,\n  sendAt: Number.isNaN(start) ? null : new Date(start - (hours[offset] || 1) * 3600 * 1000).toISOString(),\n  channel: item.phone ? 'sms' : 'email',\n}));\nlet route = 'schedule';\nif (status === 'canceled' || status === 'cancelled') route = 'reschedule';\nelse if (status === 'no-show') route = 'recover';\nelse if (Number.isNaN(start)) route = 'missing-time';\nconst record = {\n  email: item.email || '',\n  phone: item.phone || '',\n  to: item.phone || '',\n  title: item.title || 'Appointment',\n  start: item.start || item.startsAt || '',\n  end: item.end || '',\n  status,\n  reminders,\n  message: 'Reminder: ' + (item.title || 'your appointment') + ' at ' + (item.start || item.startsAt || 'the scheduled time') + '.',\n};\nreturn {\n  summary: record.title + ' for ' + (record.email || record.phone || 'the guest') + ' is ' + route + '.',\n  route,\n  record,\n  slackText: route.toUpperCase() + ' \u2014 ' + record.title + ' (' + (record.start || 'unscheduled') + ')',\n  actions: reminders.map((reminder) => ({ app: reminder.channel, operation: 'remind', payload: reminder })),\n};\n\n})();\nif (!produced || typeof produced.summary !== 'string' || !produced.summary.trim()) {\n  throw new Error('Apply rules must return a summary string');\n}\nreturn [{\n  json: {\n    ...item,\n    ...produced,\n    demo: item.demo !== false,\n  },\n}];\n"
      },
      "id": "b18c0601-4763-417d-97e7-53253aa3839d",
      "name": "Apply rules",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        360
      ],
      "notes": "Deterministic stand-in for the model or enrichment API. Replace or precede this with a live model node when you turn demo mode off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "f477d111-30bc-4c8c-8531-38c65bc3d331",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "37cb338f-65f6-4abb-a73e-e6d8e8a9ce6b",
      "name": "Demo mode?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        360
      ],
      "notes": "True: package the offline result. False: run the credentialed apps.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nreturn [{\n  json: {\n    demo: true,\n    status: 'demo_ready',\n    workflow: 'cancellation-reschedule-link',\n    summary: item.summary,\n    route: item.route ?? null,\n    record: item.record ?? {},\n    actions: item.actions ?? [],\n    slackText: item.slackText ?? item.summary,\n    notes: 'Demo mode did not call external apps. Send {\"demo\": false} after placeholder credentials are replaced.',\n  },\n}];\n"
      },
      "id": "2945f6b4-892e-4476-bd25-7db8e27862e8",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "draft",
        "operation": "create",
        "sendTo": "={{ $json.record.email || $json.email || 'lead@example.com' }}",
        "subject": "={{ $json.record.subject || $json.summary }}",
        "message": "={{ $json.record.body || $json.record.message || $json.summary }}",
        "emailType": "text",
        "messageId": "={{ $json.record.messageId || 'MESSAGE_ID' }}",
        "labelIds": [
          "Label_1"
        ]
      },
      "id": "af62da29-975d-4f88-aeb4-d8937f5cc19c",
      "name": "Create Gmail draft",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "PLACEHOLDER_GMAILOAUTH2",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#bookings"
        },
        "text": "={{ $json.slackText || $json.summary }}",
        "otherOptions": {}
      },
      "id": "d805b8ec-2330-4c06-9676-3a1fc93000e3",
      "name": "Post #bookings",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "slackOAuth2Api": {
          "id": "PLACEHOLDER_SLACKOAUTH2API",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Live path\n\nReplace every `PLACEHOLDER_*` credential, then POST the sample with `\"demo\": false`.\n\nThe nodes on this branch use the `record` and `actions` fields produced by Apply rules.",
        "height": 180,
        "width": 420,
        "color": 6
      },
      "id": "907482fc-e747-413e-9e2f-c52a5165b40e",
      "name": "Live path",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        520
      ]
    }
  ],
  "connections": {
    "Run demo": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inbound webhook": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calendly trigger": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize input": {
      "main": [
        [
          {
            "node": "Apply rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply rules": {
      "main": [
        [
          {
            "node": "Demo mode?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Demo mode?": {
      "main": [
        [
          {
            "node": "Package demo result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Gmail draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Gmail draft": {
      "main": [
        [
          {
            "node": "Post #bookings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "A canceled invitee gets a reschedule draft and Slack is told the slot is free."
  },
  "active": false
}
