feat: OOO webhook and zapier (#15434)
* zapier and webhook * instructions for zapier * Fix types * fix types * revert adding zap template * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <[email protected]> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <[email protected]> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <[email protected]> * Update packages/features/webhooks/lib/scheduleTrigger.ts Co-authored-by: Carina Wollendorfer <[email protected]> * wip * Fixes from comments, no more sendPayloadNoBooking * fix subscriberOptions teamIds param type * types * Update packages/features/webhooks/lib/sendPayload.ts * Re add zapierPayload to don't break old zaps * instead of metadata use oooEntry inside webhookPayload * undo comment message * Types * reset changes on yarn.lock * review changes * fix types * fix types * tentative fix for types in webhook * type improvements * fix description + clean up * revert yarn.lock changes * allow custom template for ooo entry * type fixes * type fix * fix donwloadLinks in payload * simplify some types * allow array or number for teamId * same payload for test trigger * code clean up * fix no show e2e test * translate text for webhook payload and fix conditional * add test for ooo_created webhooks * reset files * merge fix * fix test data test id * remove unused variable * only trigger for accepted memberships * remove unused variable --------- Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
27 files changed
+606
-126
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import type { TGetTranscriptAccessLink } from "@calcom/app-store/dailyvideo/zod";
|
||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
||||
import type { EventPayloadType } from "@calcom/features/webhooks/lib/sendPayload";
|
||||
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
@@ -53,11 +54,13 @@ export const triggerRecordingReadyWebhook = async ({
|
||||
})
|
||||
);
|
||||
|
||||
const payload: EventPayloadType = {
|
||||
...evt,
|
||||
downloadLink,
|
||||
};
|
||||
|
||||
const promises = webhooks.map((webhook) =>
|
||||
sendPayload(webhook.secret, eventTrigger, new Date().toISOString(), webhook, {
|
||||
...evt,
|
||||
downloadLink,
|
||||
}).catch((e) => {
|
||||
sendPayload(webhook.secret, eventTrigger, new Date().toISOString(), webhook, payload).catch((e) => {
|
||||
log.error(
|
||||
`Error executing webhook for event: ${eventTrigger}, URL: ${webhook.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}`,
|
||||
safeStringify(e)
|
||||
@@ -91,16 +94,18 @@ export const triggerTranscriptionGeneratedWebhook = async ({
|
||||
})
|
||||
);
|
||||
|
||||
const payload: EventPayloadType = {
|
||||
...evt,
|
||||
downloadLinks,
|
||||
};
|
||||
|
||||
const promises = webhooks.map((webhook) =>
|
||||
sendPayload(
|
||||
webhook.secret,
|
||||
WebhookTriggerEvents.RECORDING_TRANSCRIPTION_GENERATED,
|
||||
new Date().toISOString(),
|
||||
webhook,
|
||||
{
|
||||
...evt,
|
||||
downloadLinks,
|
||||
}
|
||||
payload
|
||||
).catch((e) => {
|
||||
log.error(
|
||||
`Error executing webhook for event: ${WebhookTriggerEvents.RECORDING_TRANSCRIPTION_GENERATED}, URL: ${webhook.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}`,
|
||||
|
||||
@@ -23,7 +23,7 @@ const OutOfOfficePage = () => {
|
||||
const { t } = useLocale();
|
||||
|
||||
const params = useSearchParams();
|
||||
const openModalOnStart = !!params?.get("om");
|
||||
const openModalOnStart = !!params?.get("open");
|
||||
useEffect(() => {
|
||||
if (openModalOnStart) {
|
||||
setOpenModal(true);
|
||||
|
||||
@@ -107,7 +107,7 @@ test.describe("Bookings", () => {
|
||||
createdAt: "[redacted/dynamic]",
|
||||
payload: {
|
||||
message: "[email protected] marked as no-show",
|
||||
attendees: [{ email: "[email protected]", noShow: true, utcOffset: null }],
|
||||
attendees: [{ email: "[email protected]", noShow: true }],
|
||||
bookingUid: bookingWhereFirstUserIsOrganizer?.uid,
|
||||
bookingId: bookingWhereFirstUserIsOrganizer?.id,
|
||||
},
|
||||
|
||||
@@ -741,3 +741,139 @@ test.describe("FORM_SUBMITTED", async () => {
|
||||
webhookReceiver.close();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("OOO_CREATED", async () => {
|
||||
test("on creating an OOO, triggers OOO webhook", async ({ page, users, webhooks }) => {
|
||||
const user = await users.create();
|
||||
await user.apiLogin();
|
||||
const webhookReceiver = await webhooks.createReceiver();
|
||||
|
||||
await page.goto("/settings/my-account/out-of-office");
|
||||
|
||||
await page.getByTestId("add_entry_ooo").click();
|
||||
await page.getByTestId("reason_select").click();
|
||||
|
||||
await page.getByTestId("select-option-4").click();
|
||||
|
||||
await page.getByTestId("notes_input").click();
|
||||
await page.getByTestId("notes_input").fill("Demo notes");
|
||||
await page.getByTestId("create-or-edit-entry-ooo-redirect").click();
|
||||
|
||||
await expect(page.locator(`data-testid=table-redirect-n-a`)).toBeVisible();
|
||||
|
||||
await webhookReceiver.waitForRequestCount(1);
|
||||
|
||||
const [request] = webhookReceiver.requestList;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const body = request.body as any;
|
||||
body.createdAt = dynamic;
|
||||
body.payload.oooEntry.createdAt = dynamic;
|
||||
body.payload.oooEntry.updatedAt = dynamic;
|
||||
body.payload.oooEntry.end = dynamic;
|
||||
body.payload.oooEntry.id = dynamic;
|
||||
body.payload.oooEntry.start = dynamic;
|
||||
body.payload.oooEntry.updatedAt = dynamic;
|
||||
body.payload.oooEntry.user.id = dynamic;
|
||||
body.payload.oooEntry.user.email = dynamic;
|
||||
body.payload.oooEntry.user.username = dynamic;
|
||||
body.payload.oooEntry.uuid = dynamic;
|
||||
expect(body).toEqual({
|
||||
createdAt: "[redacted/dynamic]",
|
||||
payload: {
|
||||
oooEntry: {
|
||||
createdAt: "[redacted/dynamic]",
|
||||
end: "[redacted/dynamic]",
|
||||
id: "[redacted/dynamic]",
|
||||
notes: "Demo notes",
|
||||
reason: {
|
||||
emoji: "🤒",
|
||||
reason: "ooo_reasons_sick_leave",
|
||||
},
|
||||
reasonId: 4,
|
||||
start: "[redacted/dynamic]",
|
||||
toUser: null,
|
||||
updatedAt: "[redacted/dynamic]",
|
||||
user: {
|
||||
id: "[redacted/dynamic]",
|
||||
email: "[redacted/dynamic]",
|
||||
name: null,
|
||||
timeZone: "Europe/London",
|
||||
username: "[redacted/dynamic]",
|
||||
},
|
||||
uuid: "[redacted/dynamic]",
|
||||
},
|
||||
},
|
||||
triggerEvent: "OOO_CREATED",
|
||||
});
|
||||
|
||||
webhookReceiver.close();
|
||||
});
|
||||
|
||||
test("on creating an OOO inside a team, triggers OOO webhook", async ({ page, users, webhooks }) => {
|
||||
const user = await users.create(null, {
|
||||
hasTeam: true,
|
||||
});
|
||||
await user.apiLogin();
|
||||
const { webhookReceiver, teamId } = await webhooks.createTeamReceiver();
|
||||
|
||||
await page.goto("/settings/my-account/out-of-office");
|
||||
|
||||
await page.getByTestId("add_entry_ooo").click();
|
||||
await page.getByTestId("reason_select").click();
|
||||
|
||||
await page.getByTestId("select-option-4").click();
|
||||
|
||||
await page.getByTestId("notes_input").click();
|
||||
await page.getByTestId("notes_input").fill("Demo notes");
|
||||
await page.getByTestId("create-or-edit-entry-ooo-redirect").click();
|
||||
|
||||
await expect(page.locator(`data-testid=table-redirect-n-a`)).toBeVisible();
|
||||
|
||||
await webhookReceiver.waitForRequestCount(1);
|
||||
|
||||
const [request] = webhookReceiver.requestList;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const body = request.body as any;
|
||||
body.createdAt = dynamic;
|
||||
body.payload.oooEntry.createdAt = dynamic;
|
||||
body.payload.oooEntry.updatedAt = dynamic;
|
||||
body.payload.oooEntry.end = dynamic;
|
||||
body.payload.oooEntry.id = dynamic;
|
||||
body.payload.oooEntry.start = dynamic;
|
||||
body.payload.oooEntry.updatedAt = dynamic;
|
||||
body.payload.oooEntry.user.id = dynamic;
|
||||
body.payload.oooEntry.user.email = dynamic;
|
||||
body.payload.oooEntry.user.username = dynamic;
|
||||
body.payload.oooEntry.uuid = dynamic;
|
||||
expect(body).toEqual({
|
||||
triggerEvent: "OOO_CREATED",
|
||||
createdAt: "[redacted/dynamic]",
|
||||
payload: {
|
||||
oooEntry: {
|
||||
createdAt: "[redacted/dynamic]",
|
||||
end: "[redacted/dynamic]",
|
||||
id: "[redacted/dynamic]",
|
||||
notes: "Demo notes",
|
||||
reason: {
|
||||
emoji: "🤒",
|
||||
reason: "ooo_reasons_sick_leave",
|
||||
},
|
||||
reasonId: 4,
|
||||
start: "[redacted/dynamic]",
|
||||
toUser: null,
|
||||
updatedAt: "[redacted/dynamic]",
|
||||
user: {
|
||||
id: "[redacted/dynamic]",
|
||||
email: "[redacted/dynamic]",
|
||||
name: null,
|
||||
timeZone: "Europe/London",
|
||||
username: "[redacted/dynamic]",
|
||||
},
|
||||
uuid: "[redacted/dynamic]",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
webhookReceiver.close();
|
||||
});
|
||||
});
|
||||
@@ -487,6 +487,7 @@
|
||||
"meeting_ended": "Meeting Ended",
|
||||
"form_submitted": "Form Submitted",
|
||||
"booking_paid": "Booking Paid",
|
||||
"ooo_created": "Out of Office Created",
|
||||
"booking_no_show_updated": "Booking No-Show Updated",
|
||||
"event_triggers": "Event Triggers",
|
||||
"subscriber_url": "Subscriber URL",
|
||||
|
||||
Reference in new issue
Block a user