import { phProjectAPIKey } from "https://esm.town/v/ianvph/phProjectAPIKey";
import { capturePostHogEvent } from "https://esm.town/v/ianvph/capturePostHogEvent";
export async function testWebhookTarget(req: Request) {
let reqJson = await req.json();
console.log(reqJson);
const eventType = reqJson["event"];
let eventName = "calendly_event";
if (eventType === "invitee.created") {
eventName = "meeting_scheduled";
}
else if (eventType === "invitee.canceled") {
eventName = "meeting_cancelled";
}
const user = reqJson["payload"]["email"];
const name = reqJson["payload"]["name"];
const properties = {
email: user,
event_type: eventType,
name: name,
};
capturePostHogEvent(
phProjectAPIKey,
user,
eventName,
properties,
);
return Response.json({ ok: true });
}