Capture Calendly bookings as User EventsUpdated 21/05/2019


This code allows you to capture calendly bookings as User Events


const { payload = {}, event: event_action = {} } = body;
const { event = {}, event_type = {}, invitee = {}, questions_and_answers, time } = payload;
const { name: event_name } = event_type;
const { email } = invitee;

const ident = {
  email,
  anonymous_id: email
}

let isTracked = false;
const actionName = event_action === "invitee.canceled" ? "canceled" : "booked";
const eventName = `Demo ${actionName}`
const {
  assigned_to = "none",
  cancel_reason,
  canceled,
  canceled_at,
  end_time,
  start_time,
  uuid,
  location
} = event

const {
  kind: type_kind,
  name: type_name,
  slug: type_slug,
  uuid: type_uuid,
  duration: type_duration_min
} = event_type

const properties = {
  assigned_to,
  cancel_reason,
  canceled,
  canceled_at: moment(canceled_at).toISOString(),
  end_time_at: moment(end_time).toISOString(),
  start_time_at: moment(start_time).toISOString(),
  uuid,
  location,
  type_kind,
  type_name,
  type_slug,
  type_uuid,
  type_duration_min,
  demo_email: email
}

hull
  .user(userIdent)
  .track(eventName, properties, {
    created_at: moment(time).toISOString()
  });