Improves Zapier response and payload (#3892)

* improve listBookings API call

* improve payload for zapier call

* use more readable location for integrations

* remove cancellation reason

* convert location to readbale string

* code clean up

* code clean up

* updated expected webhook response for e2e tests

* fix failing e2e

* revert webhook response

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2022-09-08 13:18:00 -06:00
1 parent 0b8eb3b8ec
commit bb24539731
5 files changed
+116 -14

No files matched your search

+13 -1
View File
@@ -37,7 +37,7 @@ import type { EventResult, PartialReference } from "@calcom/types/EventManager";
import { getSession } from "@lib/auth";
import { HttpError } from "@lib/core/http/error";
import sendPayload from "@lib/webhooks/sendPayload";
import sendPayload, { EventTypeInfo } from "@lib/webhooks/sendPayload";
import { getTranslation } from "@server/lib/i18n";
@@ -845,13 +845,25 @@ async function handler(req: NextApiRequest) {
metadata: reqBody.metadata,
});
const bookingId = booking?.id;
const eventTypeInfo: EventTypeInfo = {
eventTitle: eventType.title,
eventDescription: eventType.description,
requiresConfirmation: eventType.requiresConfirmation || null,
price: eventType.price,
currency: eventType.currency,
length: eventType.length,
};
const promises = subscribers.map((sub) =>
sendPayload(sub.secret, eventTrigger, new Date().toISOString(), sub, {
...evt,
...eventTypeInfo,
bookingId,
rescheduleUid,
metadata: reqBody.metadata,
eventTypeId,
status: eventType.requiresConfirmation ? "PENDING" : "ACCEPTED",
}).catch((e) => {
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e);
})
+21 -2
View File
@@ -27,7 +27,7 @@ import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { getSession } from "@lib/auth";
import sendPayload from "@lib/webhooks/sendPayload";
import sendPayload, { EventTypeInfo } from "@lib/webhooks/sendPayload";
import getWebhooks from "@lib/webhooks/subscriptions";
import { getTranslation } from "@server/lib/i18n";
@@ -75,6 +75,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
select: {
recurringEvent: true,
title: true,
description: true,
requiresConfirmation: true,
price: true,
currency: true,
length: true,
workflows: {
include: {
workflow: {
@@ -165,9 +170,23 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
eventTypeId: (bookingToDelete.eventTypeId as number) || 0,
triggerEvent: eventTrigger,
};
const eventTypeInfo: EventTypeInfo = {
eventTitle: bookingToDelete?.eventType?.title || null,
eventDescription: bookingToDelete?.eventType?.description || null,
requiresConfirmation: bookingToDelete?.eventType?.requiresConfirmation || null,
price: bookingToDelete?.eventType?.price || null,
currency: bookingToDelete?.eventType?.currency || null,
length: bookingToDelete?.eventType?.length || null,
};
const webhooks = await getWebhooks(subscriberOptions);
const promises = webhooks.map((webhook) =>
sendPayload(webhook.secret, eventTrigger, new Date().toISOString(), webhook, evt).catch((e) => {
sendPayload(webhook.secret, eventTrigger, new Date().toISOString(), webhook, {
...evt,
...eventTypeInfo,
status: "CANCELLED",
}).catch((e) => {
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${webhook.subscriberUrl}`, e);
})
);