This reverts commit 4902c6a0f8.
Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
co-authored by
Alex van Andel
parent
68f76e2acc
commit
35059d7727
@@ -2,7 +2,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { bulkShortenLinks } from "@calcom/ee/workflows/lib/reminders/utils";
|
||||
import { getShortenLink } 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";
|
||||
@@ -127,8 +127,26 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
rescheduleLink: `${bookerUrl}/reschedule/${reminder.booking.uid}` || "",
|
||||
};
|
||||
|
||||
const [{ shortLink: meetingUrl }, { shortLink: cancelLink }, { shortLink: rescheduleLink }] =
|
||||
await bulkShortenLinks([urls.meetingUrl, urls.cancelLink, urls.rescheduleLink]);
|
||||
const [meetingUrl, cancelLink, rescheduleLink] = await Promise.allSettled([
|
||||
getShortenLink(urls.meetingUrl),
|
||||
getShortenLink(urls.cancelLink),
|
||||
getShortenLink(urls.rescheduleLink),
|
||||
]).then((results) => {
|
||||
return results.map((result) => {
|
||||
let finalResult = "";
|
||||
|
||||
if (result.status === "fulfilled") {
|
||||
const v = result.value;
|
||||
if (typeof v === "string") {
|
||||
finalResult = v;
|
||||
} else {
|
||||
finalResult = v.shortLink;
|
||||
}
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
});
|
||||
});
|
||||
|
||||
const variables: VariablesType = {
|
||||
eventName: reminder.booking?.eventType?.title,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { bulkShortenLinks } from "@calcom/ee/workflows/lib/reminders/utils";
|
||||
import { getShortenLink } from "@calcom/ee/workflows/lib/reminders/utils";
|
||||
import { SENDER_ID, WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { TimeFormat } from "@calcom/lib/timeFormat";
|
||||
@@ -153,8 +153,26 @@ export const scheduleSMSReminder = async (args: ScheduleTextReminderArgs) => {
|
||||
rescheduleLink: `${evt.bookerUrl ?? WEBSITE_URL}/reschedule/${evt.uid}`,
|
||||
};
|
||||
|
||||
const [{ shortLink: meetingUrl }, { shortLink: cancelLink }, { shortLink: rescheduleLink }] =
|
||||
await bulkShortenLinks([urls.meetingUrl, urls.cancelLink, urls.rescheduleLink]);
|
||||
const [meetingUrl, cancelLink, rescheduleLink] = await Promise.allSettled([
|
||||
getShortenLink(urls.meetingUrl),
|
||||
getShortenLink(urls.cancelLink),
|
||||
getShortenLink(urls.rescheduleLink),
|
||||
]).then((results) => {
|
||||
return results.map((result) => {
|
||||
let finalResult = "";
|
||||
|
||||
if (result.status === "fulfilled") {
|
||||
const v = result.value;
|
||||
if (typeof v === "string") {
|
||||
finalResult = v;
|
||||
} else {
|
||||
finalResult = v.shortLink;
|
||||
}
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
});
|
||||
});
|
||||
|
||||
const variables: VariablesType = {
|
||||
eventName: evt.title,
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import { dub } from "@calcom/features/auth/lib/dub";
|
||||
|
||||
export const bulkShortenLinks = async (links: string[]) => {
|
||||
const linksToShorten = links.filter((link) => link !== "");
|
||||
const results = await dub.links.createMany(
|
||||
linksToShorten.map((link) => ({ domain: "sms.cal.com", url: link }))
|
||||
);
|
||||
|
||||
return links.map((link) => {
|
||||
const createdLink = results.find((result) => result.url === link);
|
||||
if (createdLink) {
|
||||
return { shortLink: createdLink.shortLink };
|
||||
// if invalid link, return the original link as it is
|
||||
} else {
|
||||
return { shortLink: link };
|
||||
}
|
||||
});
|
||||
export const getShortenLink = (link: string) => {
|
||||
// don't hit dub with with empty string
|
||||
if (!link.length) {
|
||||
const pr: Promise<string> = new Promise((resolve) => resolve(link));
|
||||
return pr;
|
||||
} else {
|
||||
return dub.links.create({
|
||||
url: link,
|
||||
domain: "sms.cal.com",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user