The booking sync matches clients to calendar events by attendee email
The portal shows every client their upcoming and past meetings with me. Those bookings do not come from a form or a manual entry. They come from my Google Calendar via a cron job that runs daily. The sync function starts by loading every active client from the database and building a Map — email address lowercase as the key, client ID as the value. Then it authenticates with Google using an OAuth2 client configured with a refresh token and fetches calendar events from ninety days ago to thirty days ahead. For each event, it reads the attendee list and checks every attendee email against the client Map. If an attendee matches a client, that event becomes a booking. The function extracts four things from the calendar event — the title, the start time, the end time, and the Google Meet link. The Meet link has a fallback chain: first it checks conferenceData.entryPoints for a video type, then it falls back to the hangoutLink property. If neither exists, the booking renders without a Join button. Each booking is upserted by calendarEventId so the same event never creates duplicate records. If I reschedule a meeting in Google Calendar, the next sync picks up the new times and updates the existing record. If I cancel it, it stays in the database as a past booking — the portal does not delete records that once existed. The cron endpoint authenticates with a CRON_SECRET bearer token so it cannot be triggered by anyone who does not have the secret. It also exposes a GET handler so I can trigger a manual sync from a browser during development. One cron job, one Map lookup, one upsert per event, and every client sees their meetings without me touching the portal.
Comments coming soon
Sign in with TikTok to leave a comment. Coming soon.