mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-22 11:29:22 -05:00
feat: prevent users from adding a discord webhook
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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!",
|
||||
|
||||
Reference in New Issue
Block a user