feat: prevent users from adding a discord webhook

This commit is contained in:
Kartik Saini
2025-02-12 17:42:45 +05:30
parent d73b497f52
commit cb120c56f6
3 changed files with 26 additions and 0 deletions
@@ -113,6 +113,16 @@ export const AddWebhookModal = ({ environmentId, surveys, open, setOpen }: AddWe
throw new Error(t("common.please_select_at_least_one_survey"));
}
const DISCORD_WEBHOOK_URL_PATTERN = /^https:\/\/discord\.com\/api\/webhooks\/\d+\/.+$/;
const webhookUrl = new URL(testEndpointInput);
const isDiscordWebhook = DISCORD_WEBHOOK_URL_PATTERN.test(webhookUrl.toString());
if (isDiscordWebhook) {
throw new Error(t("environments.integrations.webhooks.discord_webhook_not_supported"));
}
const endpointHitSuccessfully = await handleTestEndpoint(false);
if (!endpointHitSuccessfully) return;
@@ -70,6 +70,15 @@ export const deleteWebhook = async (id: string): Promise<boolean> => {
export const createWebhook = async (environmentId: string, webhookInput: TWebhookInput): Promise<boolean> => {
try {
const DISCORD_WEBHOOK_URL_PATTERN = /^https:\/\/discord\.com\/api\/webhooks\/\d+\/.+$/;
const webhookUrl = new URL(webhookInput.url);
const isDiscordWebhook = DISCORD_WEBHOOK_URL_PATTERN.test(webhookUrl.toString());
if (isDiscordWebhook) {
throw new UnknownError(
"Discord webhooks are currently not supported. Please use a different webhook service."
);
}
const createdWebhook = await prisma.webhook.create({
data: {
...webhookInput,
@@ -142,6 +151,12 @@ export const testEndpoint = async (url: string): Promise<boolean> => {
const isDiscordWebhook = DISCORD_WEBHOOK_URL_PATTERN.test(webhookUrl.toString());
if (isDiscordWebhook) {
throw new UnknownError(
"Discord webhooks are currently not supported. Please use a different webhook service."
);
}
const payload = isDiscordWebhook
? {
content: "🔔 Test notification from Formbricks",
+1
View File
@@ -748,6 +748,7 @@
"add_webhook_description": "Send survey response data to a custom endpoint",
"all_current_and_new_surveys": "All current and new surveys",
"created_by_third_party": "Created by a Third Party",
"discord_webhook_not_supported": "Discord webhooks are currently not supported. Please use a different webhook service.",
"empty_webhook_message": "Your webhooks will appear here as soon as you add them. ⏲️",
"endpoint_pinged": "Yay! We are able to ping the webhook!",
"endpoint_pinged_error": "Unable to ping the webhook!",