Enforce unsub url
This commit is contained in:
@@ -20,6 +20,11 @@ import { logger } from "../logger/log";
|
|||||||
import { createWorkerHandler, TeamJob } from "../queue/bullmq-context";
|
import { createWorkerHandler, TeamJob } from "../queue/bullmq-context";
|
||||||
import { SuppressionService } from "./suppression-service";
|
import { SuppressionService } from "./suppression-service";
|
||||||
|
|
||||||
|
const CAMPAIGN_UNSUB_PLACEHOLDER_TOKENS = [
|
||||||
|
"{{unsend_unsubscribe_url}}",
|
||||||
|
"{{usesend_unsubscribe_url}}",
|
||||||
|
];
|
||||||
|
|
||||||
export async function sendCampaign(id: string) {
|
export async function sendCampaign(id: string) {
|
||||||
let campaign = await db.campaign.findUnique({
|
let campaign = await db.campaign.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
@@ -71,6 +76,18 @@ export async function sendCampaign(id: string) {
|
|||||||
throw new Error("No HTML content for campaign");
|
throw new Error("No HTML content for campaign");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unsubPlaceholderFound = CAMPAIGN_UNSUB_PLACEHOLDER_TOKENS.some(
|
||||||
|
(placeholder) =>
|
||||||
|
campaign.content?.includes(placeholder) ||
|
||||||
|
campaign.html?.includes(placeholder)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!unsubPlaceholderFound) {
|
||||||
|
throw new Error(
|
||||||
|
"Campaign must include an unsubscribe link before sending"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await sendCampaignEmail(campaign, {
|
await sendCampaignEmail(campaign, {
|
||||||
campaignId: campaign.id,
|
campaignId: campaign.id,
|
||||||
from: campaign.from,
|
from: campaign.from,
|
||||||
|
Reference in New Issue
Block a user