Skip to content

Fix missing booking confirmation emails for anonymous visitors - #24

Open
gonengar wants to merge 1 commit into
mainfrom
fix/booking-confirmation-emails
Open

Fix missing booking confirmation emails for anonymous visitors#24
gonengar wants to merge 1 commit into
mainfrom
fix/booking-confirmation-emails

Conversation

@gonengar

Copy link
Copy Markdown
Collaborator

Summary

Anonymous visitors who booked an appointment were never receiving the confirmation email, even though the booking record showed status: CONFIRMED. The site already has the preinstalled "Send clients an email confirmation when they book" automation (active), but its trigger gate evaluated false on every booking we created.

The automation fires on wix_bookings-sessions_booked and is gated by:

notify_participants = true AND approval_service = false AND contact_id != null

Inspecting recent bookings on the live site showed each one missing one or more of these signals:

Booking participantNotification contactId paymentStatus selectedPaymentOption
Old (confirmBooking-only path) set at confirm-time (after sessions_booked already fired) empty UNDEFINED UNDEFINED
New (this PR) set at create-time populated via appendOrCreateContact PAID OFFLINE

Changes

  • src/components/BookEngineer.tsx — before createBooking:
    • Call submittedContact.appendOrCreateContact to upsert the CRM contact and resolve a real contactId.
    • Pass contactDetails.contactId into createBooking so the booking is linked at create-time rather than relying on async resolution from the anonymous visitor identity.
    • Pass participantNotification: { notifyParticipants: true, message } as the second createBooking arg so the notify_participants flag persists on the booking entity (this is what the trigger reads — confirm-time notifications don't backfill it).
    • Add selectedPaymentOption: "OFFLINE" so the booking record reflects the actual payment path.
  • src/pages/api/bookings/confirm.ts — switch from confirmBooking to confirmOrDecline with paymentStatus: "PAID" via an elevated httpClient.fetchWithAuth call (the SDK doesn't yet expose confirmOrDecline on the auto-SDK we use). Matches the offline-paid flow.

Test plan

  • Book an appointment as a logged-out visitor on the preview deployment.
  • Verify in the dashboard that the resulting booking has paymentStatus: PAID, selectedPaymentOption: OFFLINE, participantNotification.notifyParticipants: true, and a non-null contactDetails.contactId.
  • Confirm the customer email arrives at the inbox used on the booking form.
  • Book a second time with the same email — confirm the contact is reused (same contactId, no duplicate CRM contact).

🤖 Generated with Claude Code

The site automation that sends the confirmation email fires on
sessions_booked and gates on notify_participants=true and a non-null
contact_id from the booking record. The previous flow left both empty:
participantNotification was only set on confirmBooking (which doesn't
backfill the booking entity at create-time), and the booking's contact
link was left to async resolution from the anonymous visitor identity.

- Pre-create the CRM contact with appendOrCreateContact and pass the
  returned contactId on booking.contactDetails.contactId. Same email
  returns the same contactId, so this is idempotent.
- Set participantNotification.notifyParticipants on createBooking so
  the flag persists on the entity and the trigger sees it.
- Switch the server-side confirm route from confirmBooking to
  confirmOrDecline with paymentStatus PAID, matching the offline
  payment path. Also set selectedPaymentOption OFFLINE at create-time
  so the booking record reflects a properly paid offline booking.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant