Menu

English,

EmDash

Online booking in EmDash without a third-party service

How we built appointment booking inside an EmDash site: free slots read from the team calendar, a public route, a cached page, and no external scheduling tool.

The team Planning screen in the Kailua demo back office: the week of 2 to 8 November 2026 with appointments on the grid.

Aloha Pixel6 min read

Our sites used to take appointments through an external scheduling service. The visitor left the site, the appointment lived in another tool, and someone copied it into the CRM by hand. Our Kailua theme already has a CRM with a team calendar inside the EmDash back office, so we made booking an option of that calendar instead. It shipped in our core 3.35.0 on 13 November 2026.

This article walks through how it is built, with the real code. The same approach works for any EmDash site that keeps its own data in its database.

The rules we set

We kept the rules short on purpose:

  • opening hours per weekday, one or several ranges (morning, afternoon);
  • a minimum notice before an appointment (48 hours by default) and a horizon (60 days by default);
  • a slot is offered only if the host is free in the calendar, buffer included;
  • the visitor never sees what keeps the host busy, only what is free.

No new table. The setting is one JSON value stored in the CRM settings table under the key reservation, closed by default. An appointment booked online is a calendar appointment like any other, with the visitor attached as an external participant and a contact record created if the email is unknown.

Free slots are a pure function

The heart of it is a function with no database access. It takes the setting, a day, a duration, the busy intervals and the current time, and returns the start times that are free:

export function creneauxDuJour(r: ReglageReservation, jour: string, duree: number, occupe: readonly { debut: number; fin: number }[], maintenant: number): number[] {
  const d = lireJour(jour);
  if (!d) return [];
  const { de, a } = fenetre(r, maintenant);
  const pris = fusionner(occupe.map((o) => ({ debut: o.debut - r.tampon * MINUTE, fin: o.fin + r.tampon * MINUTE })));
  const sortie: number[] = [];
  for (const [debut, fin] of r.plages[String(jourSemaine(jour))] ?? []) {
    const fermeture = minutesDe(fin);
    for (let m = minutesDe(debut); m + duree <= fermeture; m += r.pas) {
      const t = instant({ ...d, h: Math.floor(m / 60), mi: m % 60 });
      const c = { debut: t, fin: t + duree * MINUTE };
      if (t < de || c.fin > a) continue;
      if (pris.some((x) => chevauche(x, c))) continue;
      sortie.push(t);
    }
  }
  return sortie;
}

The busy intervals are widened by the buffer, then merged. The loop walks each range of the day in steps, and keeps a slot only if it starts after the notice window, ends before the horizon, and overlaps nothing. Times travel in UTC; every day boundary is computed in the site time zone.

Because it is pure, it is tested in plain Node. The self-check of the booking module runs 23 controls without a database and without EmDash.

The public route

EmDash runs inside Astro, so a native extension can add a route with Astro’s injectRoute(). Ours sits next to the other CRM routes in the integration:

injectRoute({ pattern: ROUTE_RESERVATION, entrypoint: ici("./reservation.route.ts"), prerender: false });

The route answers at /_emdash/kailua/reservation. GET returns the public part of the setting and the free slots of one month. POST books.

The guards run in this order:

  • never cached, never indexed: every answer carries Cache-Control: no-store and X-Robots-Tag: noindex, nofollow;
  • POST in JSON, 16 KB at most, same origin (checked on the Origin header);
  • a honeypot field that only a robot fills, and a form submitted in under two seconds: the robot gets a fake success and nothing is written;
  • then the booking function rereads the slot in the calendar, because it may have gone between display and click, and applies a ceiling of online bookings per hour.

Every refusal is a sentence the page can show to the visitor. A failure to send emails never cancels the booking: the appointment is written, the visitor sees it on screen, and the reason the email did not leave goes to the Worker log.

What happens on a booking

The reserver function does the whole write:

  1. validates name, email, phone (optional or required, per the setting) and the answers to the host’s questions;
  2. reads the busy intervals of the host around that day and checks that the slot is still in the list returned by creneauxDuJour;
  3. finds the contact by email, or creates one;
  4. creates the appointment in the host’s name, with the visitor as participant, the answers in the description, and a link to the contact.

Then the route sends two emails: an invitation to the visitor with a calendar file, and a notice to the host with the same file and a link that opens the appointment in the back office.

The widget stays in a cached page

The site side is Reservation.astro: HTML, one stylesheet, one script. No React and no dependency. The page itself stays static and cacheable, because the slots arrive through the script, never at render time. Without JavaScript, the visitor reads a fallback sentence and a link.

On the Kailua demo it is one line in the home page:

<Reservation hote="Atelier Makani" role={locale === "fr" ? "Entretien et réparation" : "Servicing and repairs"} />

The widget shows the host, the durations, a month grid and the free slots of the selected day, then a confirmation with the day, the time and the calendar file.

Settings in the back office

The host sets everything from the Planning screen, with an Online booking button in its header: open or closed, who receives, durations, minimum notice, horizon, hours per day with breaks, and the questions asked to the visitor (free text or a list of choices). Reading and saving the setting are administrator routes.

Since core 3.38.0 the title, the welcome sentence and the questions can be entered per site language. A language without its own text falls back to the default text. When a visitor ticks a choice in their language, it is stored in the default text, the one the team reads in the calendar.

What we left out

On purpose:

  • no time zone picker: hours are the site’s, stated in clear;
  • no comparison with the visitor’s own calendar;
  • no payment at booking;
  • no new collection in EmDash: the booking lives in the CRM tables the theme already owns.

That last point is the real reason to do it in-house. The data stays in the site’s own database, in the buyer’s Cloudflare account, next to the contact and the history of that customer.

Where it ships

Booking is part of the CRM, which ships in the Kailua template with the Kailua 3 Pro licence. Its own page is Online booking plugin for EmDash. The live example is on the Kailua demo, in English at the root and in French under /fr/. It needs the engine switched on, which means EmDash on Cloudflare; the documentation explains how to put the back office online.

Keep reading

All articles