Connecting Sessions and Trafft

Doing my first project on activepieces.

Want to use Trafft to schedule a meeting

A customer scheduled a remote meeting
Trafft sends webhook to ActivePieces
ActivePieces send API call to sessions
ActivePieces gets response with URL
ActivePieces send URL back to Trafft

Anyone have this flow working?
I got as far as ActivePieces sending API call to sessions but the time doesn’t match up. Not sure how to get the url back to Trafft yet.

#Current Flow

  1. TRAFFT HOOK (WEBHOOK)
    |
    v
  2. Convert_Time (CODE)
    |
    v
  3. SESSIONS_API (HTTP)
    |
    v
  4. GET_URL (CODE)
    |
    v
  5. TEST (GMAIL TEST MSG)

#WEBHOOK ActivePieces ↔ TRAFFT
→ https//cloud.activepieces.com/api/v1/webhooks/doremido

{
  "body": {
    "extras": [
      "Extra 1, $20, 30min, x2",
      "Extra 2, $30, 10min, x1"
    ],
    "bookingUuid": "BOOKING UID HERE",
    "serviceName": "Service Name",
    "customFields": [
      "Custom Field 1: Custom Fields 1 Value A, Custom Field 1 Value B",
      "Custom Field 2: Custom Fields 1 Value A"
    ],
    "locationName": "Location Name",
    "servicePrice": "25",
    "customerEmail": "customer_example@example.example",
    "customerPhone": "+000000000",
    "employeeEmail": "employee_example@example.example",
    "employeePhone": "+000000000",
    "locationPhone": "+000000000",
    "locationAddress": "Location Address",
    "serviceCategory": "Service Category Name",
    "serviceDuration": "300",
    "appointmentPrice": "25",
    "customerFullName": "Customer Full Name",
    "customerLastName": "Customer Last Name",
    "employeeFullName": "Employee Full Name",
    "employeeLastName": "Employee Last Name",
    "appointmentStatus": "Approved",
    "customerFirstName": "Customer First Name",
    "employeeFirstName": "Employee First Name",
    "appointmentEndDate": "July 16, 2022",
    "appointmentEndTime": "6:00 pm",
    "appointmentStartDate": "July 16, 2022",
    "appointmentStartTime": "5:00 pm",
    "appointmentEndDateTime": "July 16, 2022 6:00 pm",
    "appointmentStartDateTime": "July 16, 2022 5:00 pm"
  },

#Code for time conversion Trafft native to Sessions native

export const code = async (inputs) => {
  const inputStartDateTime = inputs.StartDateTime;
  const inputEndDateTime = inputs.EndDateTime;

  const convertTo24HourFormat = (dateTime: string) => {
    const [_, month, day, year, hours, minutes, period] = dateTime.match(/(\w+) (\d+), (\d+) (\d+):(\d+) (\w+)/) || [];
    let hours24 = parseInt(hours, 10);

    if (period.toLowerCase() === "pm" && hours24 !== 12) {
      hours24 += 12;
    } else if (period.toLowerCase() === "am" && hours24 === 12) {
      hours24 = 0;
    }

    const monthNumber = new Date(Date.parse(month + " 1, 2012")).getMonth() + 1;
    const monthString = monthNumber.toString().padStart(2, "0");
    const dayString = day.padStart(2, "0");

    const isoString = `${year}-${monthString}-${dayString}T${hours24.toString().padStart(2, "0")}:${minutes}:00.000Z`;
    return isoString;
  };

  const startDateTime24 = convertTo24HourFormat(inputStartDateTime);
  const endDateTime24 = convertTo24HourFormat(inputEndDateTime);

  return {
    startDateTime24: startDateTime24,
    endDateTime24: endDateTime24,
  };
};

Output Example

{
  "endDateTime24": "2022-07-16T18:00:00.000Z",
  "startDateTime24": "2022-07-16T17:00:00.000Z"
}

#HTTP REQUEST - API Call to Sessions
#Login Info
ActivePieces → Send HTTP Post
https://api.app.sessions.us/api/sessions
->HEADER KEY “x-api-key”
->HEADER Value “INSERT API KEY HERE”

#api call to sessions.us to create a session

{
  "name": "New Session",
  "startAt": "{{step_1['startDateTime24']}}",
  "plannedEnd": "{{step_1['endDateTime24']}}",
  "description": null,
  "timeZone": "America/New_York",
  "quickSession": false,
  "reminders": [],
  "participants": []
}

VS
#/api/sessions API DOCUMENTATION

{
  "name": "New Session",
  "startAt": "2023-09-19T15:48:06.372Z",
  "plannedEnd": "2023-09-19T15:48:06.372Z",
  "description": null,
  "timeZone": "Europe/Bucharest",
  "quickSession": false,
  "reminders": [],
  "participants": []
}
1 Like

This is self documentation until I have more time to work on it.
I am kind of kicking myself I should have tried achieving this with appsumo calendar, the api is already here.

I think this is great progress! Just want to add that it’s easier to use Date Helper → Format Date to change the date format. But Trafft’s format might not be supported as it’s 12-hour with am/pm which I don’t see implemented in the piece yet.

Keep us posted on the updates, and let me know if you’d like to share the flow as a template with everyone else.

@ashrafsam @DOOMER

Keep in mind that you can also change the Date Format in Trafft if you wish…

TimMan

1 Like

Interesting, thanks for the tip, just connected trafft :slight_smile:

Hey, sorry I just came to say I had refunded Trafft so I will not be finishing this work.
ActivePieces is awesome though.