line

Location Booking & Deposit Process

A workflow that manages the booking confirmation and deposit process for a marketplace where users can book event spaces at restaurants. The workflow launches when the customer requests a booking and triggers emails or SMS messages to manage the booking reservation and deposit processes between the location owner and customer. It also sends Slack notifications to the customer success teams keeping them updated on each step.

Visual of Workflow

This flowchart shows a visual representation of the workflow tasks.
line

Workflow Overview

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.

Workflow Code

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);
  }
};

Workflow Input

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
}

Send Events To Booking Workflow

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": []
}

Workflow Steps

A workflow instance is launched when the user requests a booking at a location.

  • Send a booking request email via Sendgrid to the location owner with the date, time and number of people.
  • Wait for the owner to respond (replyEvent) from the owner until 1 day.
  • If the owner refuses the booking, send an email via Sendgrid to the customer
  • If the owner does not reply within the wait period:
    – send an SMS reminder to the owner via Twilio
    – send a slack notification to customer success team.
  • If the owner accepts the booking request:
    – Create the booking in the database with the booking data (date, time, number of people, location data, etc) in a task
    – Cancel other booking requests for other locations from the user in a task.
    – Send confirmation email via sendgrid to the location-owner with booking details

Check the workflow input to see if the location requires a deposit.

  • If the location does not require a deposit,
    – send the customer a confirmation SMS and email with booking and location details,
    – send a slack message to customer success that the a booking is confirmed,
    – update booking record in the database with confirmation details.
  • 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.

    • If the deposit is received within the wait period:
      – Send a confirmation SMS to the customer,
      – Update the booking record in the database with confirmation and deposit details.
  • If the deposit is not received within the wait period:
    – Execute a task to cancel the booking,
    – Send an email to the customer with cancellation details,
    – Send an email to the location owner with cancellation details.
    – Send a slack message to the team that the booking has been cancelled.

Workflow Executions

The Zenaton dashboard shows an overall view of each step of each workflow instance. Drill down to see event data, task output, error messages and log files.
line