{
  "name": "Appointment booking with SMS and email reminders",
  "nodes": [
    {
      "parameters": {
        "content": "## Appointment booking with SMS and email reminders\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": "e4af260b-452a-4cc0-af22-bd66f5b11a8a",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "a28a7a31-aa9f-42b9-af5a-0249179bea8a",
      "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": "appointment-booking-reminders",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "54ada5b3-39d5-47c5-9898-6acd064a5bbd",
      "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": "228c8136-a8cb-46ac-a16d-6b0d6b69e59c"
    },
    {
      "parameters": {
        "events": [
          "invitee.created",
          "invitee.canceled"
        ]
      },
      "id": "8ba2e354-988f-498c-9c4d-7fc605e5eaf8",
      "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\": \"booked\"\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": "47d67a76-3fbb-4dc3-986f-d5880af1c4ce",
      "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', '2h'];\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": "28b6a737-7393-4491-a0f6-80d2db3f00ac",
      "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": "ea1b1e24-b67c-4c5e-954b-282baee901ee",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "46d90075-1dfd-43e7-b495-0670ee0235ff",
      "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: 'appointment-booking-reminders',\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": "bccc0819-cfc5-4cde-b907-13b48f609c35",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "resource": "sms",
        "operation": "send",
        "from": "={{ $json.record.from || '+15555550100' }}",
        "to": "={{ $json.record.to || $json.record.phone || $json.phone }}",
        "message": "={{ $json.record.message || $json.slackText || $json.summary }}",
        "twiml": "={{ $json.record.twiml || '<Response><Say>We will call you back shortly.</Say></Response>' }}"
      },
      "id": "f22398be-ac85-4ae0-96c1-0fc9095a432f",
      "name": "Send SMS",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "twilioApi": {
          "id": "PLACEHOLDER_TWILIOAPI",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "send",
        "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": "4154a76e-61ad-45e9-a87a-1f179628ce4d",
      "name": "Send Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "PLACEHOLDER_GMAILOAUTH2",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "resource": "event",
        "operation": "create",
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "calendar@example.com"
        },
        "start": "={{ $json.record.start }}",
        "end": "={{ $json.record.end }}",
        "additionalFields": {
          "summary": "={{ $json.record.title || $json.summary }}"
        }
      },
      "id": "c20ddafa-f701-465b-8559-d4c2e47bc783",
      "name": "Create calendar event",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1.3,
      "position": [
        1740,
        760
      ],
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "PLACEHOLDER_GOOGLECALENDAROAUTH2API",
          "name": "Google Calendar account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#bookings"
        },
        "text": "={{ $json.slackText || $json.summary }}",
        "otherOptions": {}
      },
      "id": "b68af446-928c-461f-af1a-b6949b875b44",
      "name": "Post #bookings",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        2020,
        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": "f90ac20d-cf9f-4d58-95a6-a7c1fb8b9448",
      "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": "Send SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send SMS": {
      "main": [
        [
          {
            "node": "Send Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Gmail": {
      "main": [
        [
          {
            "node": "Create calendar event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create calendar event": {
      "main": [
        [
          {
            "node": "Post #bookings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "A Calendly or Cal.com booking is turned into a 24-hour and a 2-hour reminder plan. SMS goes out when a phone exists, email otherwise. The calendar node can mirror the hold, and Slack sees the booking."
  },
  "active": false
}
