* test: booking rejection * test: check if webhook is called * feat: BOOKING_REJECTED enum ,constant in backend * feat: send booking rejected webhook to subscribers * feat: add Booking rejected migration * calendar event * Revert "calendar event" This reverts commit 28d45dccfdd3788f0124f9be8783161b1156cd09. * feat: BOOKING_REQUESTED enum, constant, migration * feat: Send BOOKING REQUESTED Webhook call * feat: Add booking rejected/requested event in form * feat: data-testid to rejection confirm btn * test: BOOKING_REJECTED, BOOKING_REQUESTED * fix: booking status PENDING, Linting * feat: add new labels to common.json * remove: meeting ended hook from request hook * refactor: abstract handleWebhookTrigger * fix: create a single file for migration * refactor: reduce code repetition and fix test * feat: add team webhooks to subscriberOptions * refactor: subscriberOptions --------- Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
|
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
|
import type { WebhookDataType } from "@calcom/features/webhooks/lib/sendPayload";
|
|
import sendPayload from "@calcom/features/webhooks/lib/sendPayload";
|
|
import logger from "@calcom/lib/logger";
|
|
|
|
export async function handleWebhookTrigger(args: {
|
|
subscriberOptions: GetSubscriberOptions;
|
|
eventTrigger: string;
|
|
webhookData: Omit<WebhookDataType, "createdAt" | "triggerEvent">;
|
|
}) {
|
|
try {
|
|
const subscribers = await getWebhooks(args.subscriberOptions);
|
|
|
|
const promises = subscribers.map((sub) =>
|
|
sendPayload(sub.secret, args.eventTrigger, new Date().toISOString(), sub, args.webhookData).catch(
|
|
(e) => {
|
|
console.error(
|
|
`Error executing webhook for event: ${args.eventTrigger}, URL: ${sub.subscriberUrl}`,
|
|
e
|
|
);
|
|
}
|
|
)
|
|
);
|
|
await Promise.all(promises);
|
|
} catch (error) {
|
|
logger.error("Error while sending webhook", error);
|
|
}
|
|
}
|