See llms.txt for all machine-readable content.

Back to Templates

Book conflict-free staff appointments with forms, Postgres and SMTP email

Quick overview

This workflow provides an n8n booking form that validates appointment requests, reserves the first available staff member in Postgres without double-booking, emails the customer a confirmation via SMTP, and suggests alternative time slots when the requested time is unavailable.

How it works

  1. Receives an appointment request through an n8n Form with name, email, date, time, and optional notes.
  2. Validates the request (email/name, notice period, booking window, and staff working hours) and calculates the appointment start/end times.
  3. Reserves the first available staff member by calling a Postgres function that inserts a booking with conflict protection via unique indexes.
  4. If a new booking is created, sends a confirmation email via SMTP (BCC to the owner) and stores any email-send error back to Postgres.
  5. If the customer already has a confirmed booking for the same slot, returns a page confirming the existing booking without changing anything.
  6. If all eligible staff are taken, loads upcoming bookings from Postgres, computes the next five available times, and returns a page suggesting alternative slots.

Setup

  1. Create a Postgres credential in n8n and run the one-time setup trigger to create the bookings table, indexes, and n8n_book_first_free function.
  2. Add the same Postgres credential to each Postgres node and ensure the database is reachable from your n8n instance.
  3. Add an SMTP credential for sending emails and set an allowed sender address in the workflow’s from_email setting.
  4. Update the booking settings (business name, notification email, slot length, min notice, max days ahead, and staff schedules) to match your business hours and availability.
  5. Set the workflow timezone in n8n and keep the form’s Time dropdown aligned with your slot grid, then activate the workflow and share the form’s Production URL.