I want to setup a backend flow that sends an email whenever a booking expires. The expiry time is whenever number of hours booked expires from the time when the booking started. I have the number of hours booked in my database with every booking so that helps. I believe storing the booking expiry time would just complicate things. Instead, I could just compare the booking time and hours with the Current date/time to see if it expired or not
How can I set up a backend flow to (check) whenever Currentdate time+booked_hours<current date time and then an event to trigger that email? I just can’t seem to find the right logic.
Use a recurring backend workflow to handle this. You’ll set up a workflow to run at a set interval (e.g., every 1 or 2 hour), which then searches for all expired bookings that haven’t had an email sent yet. This avoids having to store a separate expiry time for every booking.
Make sure you have enough recurring limit to for webhook ŘŚ check it from setting api section
First i suggest when you create booking do store its expiry time, it will make things easy latter for auditing and other things , you dont need to use it for now but keep it.
now, to send a booking expiry email, there are many ways you can do it, but as you asked for Backend api and recurring. It as follow
1st create a two webhook one for triggering the process every 2 hour, 2nd going over every expired booking and sending email to its recipient and changing it status to expire.
You triger 1st webhook manully atleast one time then.
Inside it:
you search all the booking which are going to expire
You triger 2nd webhook with all the booking and a index and count parameter.
2nd webhook run for first index item; sending the email
Make it expire status
Trigger it again with incrementing index if index is less then count.
If index is not less then the count it mean all the email sent and it will stop the flow
And then in main backend workflow make it so it will schedule himself for next 2 hour
Hey @adig The simplest way is to calculate the expiry time in the backend workflow itself rather than trying to check continuously. In your backend workflow, schedule it to run when the booking should expire: add a “schedule API workflow” action when a booking is created, and set the scheduled date/time to Booking Start Time + Booked Hours.
Then, in that backend workflow, just send the email, no need to constantly compare with the current date/time. That way each booking automatically triggers its email exactly when it expires.
You can connect them by using Bubble’s “Schedule API Workflow” action on the frontend workflow. When the booking is created (or started), add that action, select your backend workflow for sending the email, and pass any necessary parameters like the user’s email or booking ID.
Then set the scheduled date/time to Booking Start Time + Booked Hours. Bubble will automatically trigger the backend workflow at that time and send the email, hence no extra connection needed.