Callbacks
This page describes how you can use callbacks in BookingJs to respond to booking events such as successful bookings or cancellations.
Overview
With callbacks, you can execute custom code when certain events occur in the widget. This is useful for analytics, redirects, or integration with other systems.
Booking-related callbacks
| Callback | Description |
|---|---|
openedBookingPage | Booking page was opened |
closedBookingPage | Booking page was closed |
createBookingStarted | Booking process was started |
createBookingSuccessful | Booking was successful |
createBookingFailed | Booking failed |
Parameters
All booking-related callbacks receive an object with:
Callback parameters
{
timeslot: {
start: DateTime, // Luxon DateTime
end: DateTime,
timeslot_uuid: string, // UUID of the appointment
product_uuid: string, // UUID of the product
product_name: string,
resource_name: string,
capacity: number,
capacity_left: number,
kind: 'models.Bookable' | 'models.LotAppointment',
untouchedStart: string, // ISO string
untouchedEnd: string
},
data: {
firstName: string,
lastName: string,
email: string,
agbs: boolean,
// + custom fields
},
response?: RTKQResponse // Only for Successful/Failed
}
Example
Booking callback
timum.init({
ref: 'ihre-ressourcen-referenz',
callbacks: {
createBookingSuccessful: ({ timeslot, data, response }) => {
// Analytics event
gtag('event', 'booking_complete', {
resource: timeslot.resource_name,
product: timeslot.product_name,
customer_email: data.email
});
// Optional: Redirect
// window.location.href = '/danke?booking=' + timeslot.timeslot_uuid;
},
createBookingFailed: ({ timeslot, data, response }) => {
console.error('Buchung fehlgeschlagen:', response);
}
}
});
Cancellation-related callbacks
| Callback | Description |
|---|---|
openedCancelPage | Cancellation page was opened |
closedCancelPage | Cancellation page was closed |
cancelationStarted | Cancellation process was started |
cancelationSuccessful | Cancellation was successful |
cancelationFailed | Cancellation failed |
Dialog-related callbacks
| Callback | Description |
|---|---|
openedProductSelection | Product selection opened |
closedProductSelection | Product selection closed |
openedResourceSelection | Resource selection opened |
closedResourceSelection | Resource selection closed |
openedConfirmationPage | Confirmation page opened |
closedConfirmationPage | Confirmation page closed |
Note:
Dialog-related callbacks do not receive any parameters.
Data-related callbacks
| Callback | Parameters |
|---|---|
fetchingPublicDataSucceeded | contact, resource, provider, channel |
fetchingPublicDataFailed | error |
fetchingProductsSucceeded | products[] |
fetchingProductsFailed | error |
fetchingBookablesSucceeded | bookables (grouped by date) |
fetchingBookablesFailed | error |
Example: No appointments available
Handling empty appointments
timum.init({
ref: 'ihre-ressourcen-referenz',
callbacks: {
fetchingBookablesSucceeded: ({ bookables }) => {
const hasAppointments = Object.keys(bookables).length > 0;
if (!hasAppointments) {
// Hide widget
document.getElementById('bookingjs').style.display = 'none';
// Show alternative
document.getElementById('no-appointments').style.display = 'block';
}
}
}
});
postMessage for iframe
For iframe integration, you can use postMessageTarget to send events to the parent page:
iframe postMessage
// In the iframe
timum.init({
ref: 'ihre-ressourcen-referenz',
postMessageTarget: 'https://ihre-website.de'
});
// In the parent page
window.addEventListener('message', (event) => {
if (event.data.origin === 'bookingjs') {
console.log('Event:', event.data.type);
// event.data.type corresponds to the callback name
// e.g. 'createBookingSuccessful'
}
});
Important:
postMessageTarget overrides the normal callbacks. All events are sent via postMessage instead.
