* 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 <30310907+CarinaWolli@users.noreply.github.com> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/features/webhooks/lib/scheduleTrigger.ts Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * 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 <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Omar López <zomars@me.com>
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import defaultPrisma from "@calcom/prisma";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
|
|
|
export type GetSubscriberOptions = {
|
|
userId?: number | null;
|
|
eventTypeId?: number | null;
|
|
triggerEvent: WebhookTriggerEvents;
|
|
teamId?: number | number[] | null;
|
|
orgId?: number | null;
|
|
oAuthClientId?: string | null;
|
|
};
|
|
|
|
const getWebhooks = async (options: GetSubscriberOptions, prisma: PrismaClient = defaultPrisma) => {
|
|
const teamId = options.teamId;
|
|
const userId = options.userId ?? 0;
|
|
const eventTypeId = options.eventTypeId ?? 0;
|
|
const teamIds = Array.isArray(teamId) ? teamId : [teamId ?? 0];
|
|
const orgId = options.orgId ?? 0;
|
|
const oAuthClientId = options.oAuthClientId ?? "";
|
|
|
|
// if we have userId and teamId it is a managed event type and should trigger for team and user
|
|
const allWebhooks = await prisma.webhook.findMany({
|
|
where: {
|
|
OR: [
|
|
{
|
|
platform: true,
|
|
},
|
|
{
|
|
userId,
|
|
},
|
|
{
|
|
eventTypeId,
|
|
},
|
|
{
|
|
teamId: {
|
|
in: [...teamIds, orgId],
|
|
},
|
|
},
|
|
{ platformOAuthClientId: oAuthClientId },
|
|
],
|
|
AND: {
|
|
eventTriggers: {
|
|
has: options.triggerEvent,
|
|
},
|
|
active: {
|
|
equals: true,
|
|
},
|
|
},
|
|
},
|
|
select: {
|
|
id: true,
|
|
subscriberUrl: true,
|
|
payloadTemplate: true,
|
|
appId: true,
|
|
secret: true,
|
|
},
|
|
});
|
|
|
|
return allWebhooks;
|
|
};
|
|
|
|
export default getWebhooks;
|