See the full workflow code, workflow input data, event data and an example of a task as well as the detailed explanation of the workflow steps. And catch a glimpse of the dashboard monitoring workflow.
const { duration } = require("zenaton");
/* Workflow for an event-booking marketplace with notifications
to the user, location owner and customer success team */
module.exports.handle = function*(booking) {
this.run.task("sendEmail", booking.owner.email, "REQUEST_TO_OWNER");
const ownerReplyEvent = yield this.wait
.event("ownerReplyEvent")
.for(duration.seconds(15));
if (ownerReplyEvent) {
// Get the owner's response from the event's data
const [_, eventData] = ownerReplyEvent;
this.bookingConfirmation = eventData;
if (this.bookingConfirmation.status === "accepted") {
// Create a booking and save it to the database
yield this.run.task("createBooking", booking);
} else {
// if the owner refused
// alert the user about the cancellation
this.run.task("sendEmail", booking.user.email, "OWNER_CANCELLATION");
}
} else {
// if the owner doesn't reply
// send an SMS reminder
this.run.task("sendSMS", booking.owner.phone, "OWNER_REMINDER");
this.run.task(
"sendSlackMessage",
`#${booking.id} is waiting for the owner's reply...`
);
// stop the workflow execution
return;
}
// if the restaurant requires a deposit
if (booking.deposit) {
// send a deposit request email to the user
this.run.task(
"sendEmail",
booking.user.email,
"DEPOSIT_REQUEST",
this.bookingConfirmation
);
// Notify the customer success team about the deposit request
this.run.task(
"sendSlackMessage",
`#${booking.id} waiting for user deposit...`
);
} else {
// if the restaurant did not require a deposit
// notify the user via confirmation SMS and email
this.run.task("sendSMS", booking.owner.user, "USER_REMINDER");
this.run.task("sendEmail", booking.user.email, "BOOKING_CONFIRMATION");
// Notify the customer success team about the new booking completion
this.run.task("sendSlackMessage", `#${booking.id} booking complete.`);
// Update the booking record in the database
yield this.run.task("updateBooking", booking);
}
};
A workflow instance is launched when a user requests a booking. The workflow input includes the location name, deposit requirement (Y/N) and the number of people.
{
id: "1f2a0f5c-cfb5-44a2-a081-67d74a60af62",
place_id: 23696,
booking_day: "2019-12-01",
booking_date: "2019-12-31",
user: {
email: "user@example.com",
phone: "+33611223344"
},
owner: {
email: "owner@the-best-restaurant.com"
phone: "+33799887766"
},
deposit: true
}
The OwnerReplyEvent
event is sent to the workflow when the owner validates the booking request in the application and includes the parameters about the owner's requirements for a deposit:
{
"name": "OwnerReplyEvent",
"data": [
{
"status": "accepted",
"deposit_amount": 235.98,
"deposit_url": "http://..."
}
]
}
The DepositReceivedEvent
event is sent to the workflow when the user has paid the deposit:
{
"name": "DepositReceivedEvent",
"data": []
}
A workflow instance is launched when the user requests a booking at a location.
Check the workflow input to see if the location requires a deposit.
If the location requires a deposit,
– send a booking confirmation email to the customer with details on how to make a deposit,
– send a slack notification to customer success that a deposit has been requested,
– execute a task to calculate the time to wait for the deposit - 36 hours from the date of request email or 6 hours before the event if the event is earlier than 36 hours. Learn more about idempotency in documentation.
– Wait for the customer to pay the deposit (deposit event) until the amount of time (hours)that is calculated in the formula.
Real-world Examples
Start building workflows
Sign-up and run a sample project Learn more