Merge remote-tracking branch 'aar2dee2/integromat-app' into integromat-app
This commit is contained in:
commit
421f601441
|
@ -108,11 +108,6 @@ VITAL_REGION="us"
|
|||
# @see https://github.com/calcom/cal.com/blob/main/packages/app-store/zapier/README.md
|
||||
ZAPIER_INVITE_LINK=""
|
||||
|
||||
# - MAKE
|
||||
# Used for the Make integration
|
||||
# @see https://github.com/calcom/cal.com/blob/main/packages/app-store/make/README.md
|
||||
MAKE_INVITE_LINK=""
|
||||
|
||||
# - LARK
|
||||
# Needed to enable Lark Calendar integration and Login with Lark
|
||||
# @see <https://open.larksuite.com/document/ukTMukTMukTM/ukDNz4SO0MjL5QzM/g>
|
||||
|
|
|
@ -4,11 +4,14 @@ import { v4 } from "uuid";
|
|||
|
||||
import { getHumanReadableLocationValue } from "@calcom/core/location";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getTranslation } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { ApiKey } from "@calcom/prisma/client";
|
||||
import { BookingStatus, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
|
||||
const log = logger.getChildLogger({ prefix: ["[node-scheduler]"] });
|
||||
|
||||
export async function addSubscription({
|
||||
appApiKey,
|
||||
triggerEvent,
|
||||
|
@ -58,7 +61,7 @@ export async function addSubscription({
|
|||
|
||||
return createSubscription;
|
||||
} catch (error) {
|
||||
return console.error(
|
||||
return log.error(
|
||||
`Error creating subscription for user ${appApiKey.userId} and appId ${appApiKey.appId}.`
|
||||
);
|
||||
}
|
||||
|
@ -67,11 +70,11 @@ export async function addSubscription({
|
|||
export async function deleteSubscription({
|
||||
appApiKey,
|
||||
webhookId,
|
||||
appName,
|
||||
appId,
|
||||
}: {
|
||||
appApiKey: ApiKey;
|
||||
webhookId: string;
|
||||
appName: string;
|
||||
appId: string;
|
||||
}) {
|
||||
try {
|
||||
const webhook = await prisma.webhook.findFirst({
|
||||
|
@ -94,7 +97,7 @@ export async function deleteSubscription({
|
|||
});
|
||||
for (const booking of bookingsWithScheduledJobs) {
|
||||
const updatedScheduledJobs = booking.scheduledJobs.filter(
|
||||
(scheduledJob) => scheduledJob !== `${appName}_${webhook.id}`
|
||||
(scheduledJob) => scheduledJob !== `${appId}_${webhook.id}`
|
||||
);
|
||||
await prisma.booking.update({
|
||||
where: {
|
||||
|
@ -117,8 +120,8 @@ export async function deleteSubscription({
|
|||
}
|
||||
return deleteWebhook;
|
||||
} catch (err) {
|
||||
return console.error(
|
||||
`Error deleting subscription for user ${appApiKey.userId}, webhookId ${webhookId}, appName ${appName}`
|
||||
return log.error(
|
||||
`Error deleting subscription for user ${appApiKey.userId}, webhookId ${webhookId}, appId ${appId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -134,9 +137,7 @@ export async function listBookings(appApiKey: ApiKey) {
|
|||
}
|
||||
const bookings = await prisma.booking.findMany({
|
||||
take: 3,
|
||||
where: {
|
||||
userId: appApiKey.userId,
|
||||
},
|
||||
where: where,
|
||||
orderBy: {
|
||||
id: "desc",
|
||||
},
|
||||
|
@ -198,7 +199,7 @@ export async function listBookings(appApiKey: ApiKey) {
|
|||
|
||||
return updatedBookings;
|
||||
} catch (err) {
|
||||
return console.error(
|
||||
return log.error(
|
||||
`Error retrieving list of bookings for user ${appApiKey.userId} and appId ${appApiKey.appId}.`
|
||||
);
|
||||
}
|
||||
|
@ -250,7 +251,7 @@ export async function scheduleTrigger(
|
|||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error cancelling scheduled jobs", error);
|
||||
log.error("Error cancelling scheduled jobs", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,6 +294,6 @@ export async function cancelScheduledJobs(
|
|||
try {
|
||||
await Promise.all(promises);
|
||||
} catch (error) {
|
||||
console.error("Error cancelling scheduled jobs", error);
|
||||
log.error("Error cancelling scheduled jobs", error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,22 @@
|
|||
# Setting up Make Integration
|
||||
|
||||
1. Create a [Make account](https://www.make.com/en/login), if you don't have one.
|
||||
2. Go to `Scenarios` in the sidebar and click on **Create a new scenario**
|
||||
3. Search for `Cal.com` in the apps list and select from the list of triggers - Booking Created, Booking Deleted, Booking Rescheduled, Meeting Ended
|
||||
4. To create a **connection** you will need your Cal deployment url and the app API Key generated when you install `Make` from the Cal app store.You only need to create a **connection** once, all webhooks can use that connection.
|
||||
5. Setup the webhook for the desired event in Make.
|
||||
6. To delete a webhook, go to `Webhooks` in the left sidebar in Make, pick the webhook you want to delete and click **delete**.
|
||||
|
||||
1. Install the app from the Cal app store and generate an API key. Copy the API key.
|
||||
2. Go to `/admin/apps/automation` in Cal and set the `invite_link` for Make to `https://www.make.com/en/hq/app-invitation/6cb2772b61966508dd8f414ba3b44510` to use the app.
|
||||
3. Create a [Make account](https://www.make.com/en/login), if you don't have one.
|
||||
4. Go to `Scenarios` in the sidebar and click on **Create a new scenario**.
|
||||
5. Search for `Cal.com` in the apps list and select from the list of triggers - Booking Created, Booking Deleted, Booking Rescheduled, Meeting Ended
|
||||
6. To create a **connection** you will need your Cal deployment url and the app API Key generated above. You only need to create a **connection** once, all webhooks can use that connection.
|
||||
7. Setup the webhook for the desired event in Make.
|
||||
8. To delete a webhook, go to `Webhooks` in the left sidebar in Make, pick the webhook you want to delete and click **delete**.
|
||||
|
||||
## Localhost or Self-hosting
|
||||
|
||||
Localhost urls can not be used as the base URL for api endpoints
|
||||
|
||||
Possible solution: using [https://ngrok.com/](https://ngrok.com/)
|
||||
|
||||
1. Create Account
|
||||
2. [Download](https://ngrok.com/download) ngrok and start a tunnel to your running localhost
|
||||
- Use forwarding url as your baseUrl for the URL endpoints
|
||||
3. Use the ngrok url as your Cal deployment url when creating the **Connection** in Make.
|
|
@ -1,39 +1,16 @@
|
|||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { createDefaultInstallation } from "@calcom/app-store/_utils/installation";
|
||||
import type { AppDeclarativeHandler } from "@calcom/types/AppHandler";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import appConfig from "../config.json";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!req.session?.user?.id) {
|
||||
return res.status(401).json({ message: "You must be logged in to do this" });
|
||||
}
|
||||
const appType = "make_automation";
|
||||
try {
|
||||
const alreadyInstalled = await prisma.credential.findFirst({
|
||||
where: {
|
||||
type: appType,
|
||||
userId: req.session.user.id,
|
||||
},
|
||||
});
|
||||
if (alreadyInstalled) {
|
||||
throw new Error("Already installed");
|
||||
}
|
||||
const installation = await prisma.credential.create({
|
||||
data: {
|
||||
type: appType,
|
||||
key: {},
|
||||
userId: req.session.user.id,
|
||||
appId: "make",
|
||||
},
|
||||
});
|
||||
if (!installation) {
|
||||
throw new Error("Unable to create user credential for make");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
}
|
||||
const handler: AppDeclarativeHandler = {
|
||||
appType: appConfig.type,
|
||||
variant: appConfig.variant,
|
||||
slug: appConfig.slug,
|
||||
supportsMultipleInstalls: false,
|
||||
handlerType: "add",
|
||||
createCredential: ({ appType, user, slug, teamId }) =>
|
||||
createDefaultInstallation({ appType, userId: user.id, slug, key: {}, teamId }),
|
||||
};
|
||||
|
||||
return res.status(200).json({ url: "/apps/make/setup" });
|
||||
}
|
||||
export default handler;
|
||||
|
|
|
@ -26,7 +26,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||
const deleteEventSubscription = await deleteSubscription({
|
||||
appApiKey: validKey,
|
||||
webhookId: id,
|
||||
appName: "make",
|
||||
appId: "make",
|
||||
});
|
||||
|
||||
if (!deleteEventSubscription) {
|
||||
|
|
|
@ -26,7 +26,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||
const deleteEventSubscription = await deleteSubscription({
|
||||
appApiKey: validKey,
|
||||
webhookId: id,
|
||||
appName: "zapier",
|
||||
appId: "zapier",
|
||||
});
|
||||
|
||||
if (!deleteEventSubscription) {
|
||||
|
|
|
@ -337,11 +337,6 @@ export default async function main() {
|
|||
invite_link: process.env.ZAPIER_INVITE_LINK,
|
||||
});
|
||||
}
|
||||
if (process.env.MAKE_INVITE_LINK) {
|
||||
await createApp("make", "make", ["automation"], "make_automation", {
|
||||
invite_link: process.env.MAKE_INVITE_LINK,
|
||||
});
|
||||
}
|
||||
await createApp("huddle01", "huddle01video", ["conferencing"], "huddle01_video");
|
||||
|
||||
// Payment apps
|
||||
|
|
|
@ -220,7 +220,6 @@
|
|||
"LARK_OPEN_APP_ID",
|
||||
"LARK_OPEN_APP_SECRET",
|
||||
"LARK_OPEN_VERIFICATION_TOKEN",
|
||||
"MAKE_INVITE_LINK",
|
||||
"MS_GRAPH_CLIENT_ID",
|
||||
"MS_GRAPH_CLIENT_SECRET",
|
||||
"NEXT_PUBLIC_API_URL",
|
||||
|
|
Loading…
Reference in New Issue
Block a user