Files
calendar/packages/app-store/intercom/api/sheet.ts
T
VachmaraandGitHub df598bf281 feat: improve Intercom app (#19687)
* fix: don't POST to cal.com/[user]/[type]

* fix: return html with cal calendar embed

* fix: intercom app team events types

* feat: improve Intercom UX integration

* Merge branch 'main' of https://github.com/calcom/cal.com
2025-03-04 10:48:31 +05:30

59 lines
1.5 KiB
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import type { NewCanvas, TextComponent, SpacerComponent } from "../lib";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { sheet_values } = req.body;
if (!sheet_values) {
return res.status(400).json({ error: "Invalid input data" });
}
const { booking, eventType, organizer } = sheet_values;
// Prepare date and time information
const startTime = new Date(booking.startTime);
const options = {
weekday: "long" as const,
year: "numeric" as const,
month: "long" as const,
day: "numeric" as const,
hour: "numeric" as const,
minute: "numeric" as const,
timeZone: organizer.timeZone,
timeZoneName: "short" as const,
};
const formattedDate = startTime.toLocaleDateString("en-US", options);
// Create text components for the recap
const confirmedText: TextComponent = {
type: "text",
text: `Confirmed: ${eventType.title}`,
style: "header",
align: "left",
};
const detailsText: TextComponent = {
type: "text",
text: `You are scheduled with ${organizer.name} on ${formattedDate}`,
style: "paragraph",
align: "left",
};
const spacer: SpacerComponent = {
type: "spacer",
size: "m",
};
// Build the canvas data
const canvasData: NewCanvas = {
canvas: {
content: {
components: [confirmedText, spacer, detailsText],
},
},
};
return res.status(200).json(canvasData);
}