Booking Event Triggers
Overview
Booking activity — creation, cancellation, status changes, reminders coming due — should be able to drive workflows. For example: when a customer books service A, send them preparation instructions; when they cancel, add them to a "cancelled customers" audience so a promotion can be sent later.
This job is the bridge between the appointment domain and the trigger engine: it matches rules,
enriches the data, and publishes work onto the action_execute queue.
Business Flow
-
Receive a
BookingEventPayloadcontaining the identifying fields —bookingId,userId,lineOaId,organizationId— plus optional detail such asjourneyId,serviceId,staffId,locationId, status, dates and times, and the service, staff, location and customer names. -
Enrich the payload — any field the producer left empty is filled in from the database: service name, staff name, location name, dates and times. Values are only filled in when the original really is absent.
-
Resolve which source types to match based on the event type.
Event type Source types matched booking_createdbooking_createdbooking_cancelledbooking_cancelledandbooking_status_changedbooking_reminderbooking_reminderbooking_status_changedbooking_status_changed -
Query
trigger_rulefor rules with any of those source types, belonging to the same OA and organisation, enabled, and not soft-deleted. -
Each rule is filtered a second time against the conditions in its source config — the journey, service, location or staff member must match. Rules that do not match are skipped.
-
Build the action payload by merging the enriched booking data into the action config, so downstream actions can use booking details as merge tags (sending a booking link, for example).
-
Publish onto the
action_executequeue. -
Merge the
appt_*values, such asappt_serviceandappt_date, intoline_user.custom_attributeso they become available for segmentation. -
The service swallows all of its own errors rather than propagating them, so the handler always acknowledges the message.
Key Files & Functions
| File | Responsibility |
|---|---|
internal/appointment/booking_event.go | BookingEventService.ProcessEvent covers the whole flow, supported by getSourceTypes, matchesSourceConfig, enrichPayload and updateCustomAttributes. BookingEventPayload uses pointers for optional fields so "sent as null" can be told apart from "not sent at all". |
internal/appointment/consumer.go | Consumer.HandleBookingEvent |
internal/appointment/helpers.go | collectRows, asMap, nullableAny |
cmd/worker/main.go | runCronScheduler — constructs the service and wires its target queue to action_execute |
Queues: consumes booking_event_trigger and publishes action_execute, both on the
cron-scheduler profile.
Connections to Other Services
- Receives jobs from the pg-listener via
pg_notify('booking_event'), emitted by a trigger onappointment.booking. The real origin is client-api-go or cms-api-go modifying a booking. - Database tables —
trigger_rule(the rules being matched); the appointment tablesbooking,journey,service,staffandlocation(used for enrichment); andline_user(theappt_*custom attributes). - RabbitMQ — publishes to
action_execute, handing off to Action Execution. - No direct LINE API calls: messages are actually sent by the action executor or by Appointment Notifications.