migrate webhookTriggers and workflows apis (#19875)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { handleWebhookScheduledTriggers } from "@calcom/features/webhooks/lib/handleWebhookScheduledTriggers";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const apiKey = req.headers.get("authorization") || req.nextUrl.searchParams.get("apiKey");
|
||||
|
||||
if (process.env.CRON_API_KEY !== apiKey) {
|
||||
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
|
||||
}
|
||||
|
||||
await handleWebhookScheduledTriggers(prisma);
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { handler } from "@calcom/features/ee/workflows/api/scheduleEmailReminders";
|
||||
|
||||
export { handler as POST };
|
||||
@@ -0,0 +1,3 @@
|
||||
import { handler } from "@calcom/features/ee/workflows/api/scheduleSMSReminders";
|
||||
|
||||
export { handler as POST };
|
||||
@@ -0,0 +1,3 @@
|
||||
import { handler } from "@calcom/features/ee/workflows/api/scheduleWhatsappReminders";
|
||||
|
||||
export { handler as POST };
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from "@calcom/features/webhooks/lib/cron";
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from "@calcom/features/ee/workflows/api/scheduleEmailReminders";
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from "@calcom/features/ee/workflows/api/scheduleSMSReminders";
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from "@calcom/features/ee/workflows/api/scheduleWhatsappReminders";
|
||||
@@ -1,5 +1,6 @@
|
||||
/* Schedule any workflow reminder that falls within 72 hours for email */
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -7,7 +8,6 @@ import generateIcsString from "@calcom/emails/lib/generateIcsString";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { defaultHandler } from "@calcom/lib/server/defaultHandler";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
import prisma from "@calcom/prisma";
|
||||
@@ -31,16 +31,15 @@ import customTemplate from "../lib/reminders/templates/customTemplate";
|
||||
import emailRatingTemplate from "../lib/reminders/templates/emailRatingTemplate";
|
||||
import emailReminderTemplate from "../lib/reminders/templates/emailReminderTemplate";
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.headers.authorization || req.query.apiKey;
|
||||
export async function handler(req: NextRequest) {
|
||||
const apiKey = req.headers.get("authorization") || req.nextUrl.searchParams.get("apiKey");
|
||||
|
||||
if (process.env.CRON_API_KEY !== apiKey) {
|
||||
res.status(401).json({ message: "Not authenticated" });
|
||||
return;
|
||||
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!process.env.SENDGRID_API_KEY || !process.env.SENDGRID_EMAIL) {
|
||||
res.status(405).json({ message: "No SendGrid API key or email" });
|
||||
return;
|
||||
return NextResponse.json({ message: "No SendGrid API key or email" }, { status: 405 });
|
||||
}
|
||||
|
||||
// delete batch_ids with already past scheduled date from scheduled_sends
|
||||
@@ -105,8 +104,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const unscheduledReminders: PartialWorkflowReminder[] = await getAllUnscheduledReminders();
|
||||
|
||||
if (!unscheduledReminders.length) {
|
||||
res.status(200).json({ message: "No Emails to schedule" });
|
||||
return;
|
||||
return NextResponse.json({ message: "No Emails to schedule" }, { status: 200 });
|
||||
}
|
||||
|
||||
for (const reminder of unscheduledReminders) {
|
||||
@@ -438,9 +436,5 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
});
|
||||
|
||||
res.status(200).json({ message: `${unscheduledReminders.length} Emails to schedule` });
|
||||
return NextResponse.json({ message: `${unscheduledReminders.length} Emails to schedule` }, { status: 200 });
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
POST: Promise.resolve({ default: handler }),
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* Schedule any workflow reminder that falls within 7 days for SMS */
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { bulkShortenLinks } from "@calcom/ee/workflows/lib/reminders/utils";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import { defaultHandler } from "@calcom/lib/server/defaultHandler";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { WorkflowActions, WorkflowMethods, WorkflowTemplates } from "@calcom/prisma/enums";
|
||||
@@ -19,11 +19,11 @@ import type { VariablesType } from "../lib/reminders/templates/customTemplate";
|
||||
import customTemplate from "../lib/reminders/templates/customTemplate";
|
||||
import smsReminderTemplate from "../lib/reminders/templates/smsReminderTemplate";
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.headers.authorization || req.query.apiKey;
|
||||
export async function handler(req: NextRequest) {
|
||||
const apiKey = req.headers.get("authorization") || req.nextUrl.searchParams.get("apiKey");
|
||||
|
||||
if (process.env.CRON_API_KEY !== apiKey) {
|
||||
res.status(401).json({ message: "Not authenticated" });
|
||||
return;
|
||||
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
|
||||
}
|
||||
|
||||
//delete all scheduled sms reminders where scheduled date is past current date
|
||||
@@ -61,8 +61,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
})) as (PartialWorkflowReminder & { retryCount: number })[];
|
||||
|
||||
if (!unscheduledReminders.length) {
|
||||
res.json({ ok: true });
|
||||
return;
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
|
||||
for (const reminder of unscheduledReminders) {
|
||||
@@ -216,9 +215,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
console.log(`Error scheduling SMS with error ${error}`);
|
||||
}
|
||||
}
|
||||
res.status(200).json({ message: "SMS scheduled" });
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
POST: Promise.resolve({ default: handler }),
|
||||
});
|
||||
return NextResponse.json({ message: "SMS scheduled" }, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* Schedule any workflow reminder that falls within 7 days for WHATSAPP */
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { defaultHandler } from "@calcom/lib/server/defaultHandler";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { WorkflowActions, WorkflowMethods } from "@calcom/prisma/enums";
|
||||
@@ -12,11 +12,11 @@ import type { PartialWorkflowReminder } from "../lib/getWorkflowReminders";
|
||||
import { select } from "../lib/getWorkflowReminders";
|
||||
import * as twilio from "../lib/reminders/providers/twilioProvider";
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.headers.authorization || req.query.apiKey;
|
||||
export async function handler(req: NextRequest) {
|
||||
const apiKey = req.headers.get("authorization") || req.nextUrl.searchParams.get("apiKey");
|
||||
|
||||
if (process.env.CRON_API_KEY !== apiKey) {
|
||||
res.status(401).json({ message: "Not authenticated" });
|
||||
return;
|
||||
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
|
||||
}
|
||||
|
||||
//delete all scheduled whatsapp reminders where scheduled date is past current date
|
||||
@@ -42,8 +42,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
})) as PartialWorkflowReminder[];
|
||||
|
||||
if (!unscheduledReminders.length) {
|
||||
res.json({ ok: true });
|
||||
return;
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
|
||||
for (const reminder of unscheduledReminders) {
|
||||
@@ -115,9 +114,5 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json({ message: "WHATSAPP scheduled" });
|
||||
return NextResponse.json({ message: "WHATSAPP scheduled" }, { status: 200 });
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
POST: Promise.resolve({ default: handler }),
|
||||
});
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/* Cron job for scheduled webhook events triggers */
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { defaultHandler } from "@calcom/lib/server/defaultHandler";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { handleWebhookScheduledTriggers } from "./handleWebhookScheduledTriggers";
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.headers.authorization || req.query.apiKey;
|
||||
if (process.env.CRON_API_KEY !== apiKey) {
|
||||
res.status(401).json({ message: "Not authenticated" });
|
||||
return;
|
||||
}
|
||||
|
||||
await handleWebhookScheduledTriggers(prisma);
|
||||
|
||||
res.json({ ok: true });
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
POST: Promise.resolve({ default: handler }),
|
||||
});
|
||||
Reference in New Issue
Block a user