Compare commits

...

9 Commits

Author SHA1 Message Date
Piyush Gupta
323d39580a fix: multi-lang 2025-02-13 11:45:00 +05:30
Piyush Gupta
bae9226326 fix: discord webhook 2025-02-13 11:33:41 +05:30
Kartik Saini
1f80f8f396 fix 2025-02-12 17:48:16 +05:30
Kartik Saini
cb120c56f6 feat: prevent users from adding a discord webhook 2025-02-12 17:42:45 +05:30
Kartik Saini
d73b497f52 Merge branch 'main' into fix/discord-webhook-not-pinging 2025-02-12 16:59:39 +05:30
Kartik Saini
bb4f8f1df3 Merge branch 'main' into fix/discord-webhook-not-pinging 2025-02-05 12:54:59 +05:30
Kartik Saini
5b8c548d84 Merge branch 'main' into fix/discord-webhook-not-pinging 2025-01-29 21:53:41 +05:30
Kartik Saini
c51cbda31a fix 2025-01-27 20:12:03 +05:30
Kartik Saini
c773ddd117 fix: discord webhook not pinging 2025-01-27 19:49:34 +05:30
7 changed files with 28 additions and 1 deletions

View File

@@ -3,7 +3,7 @@
import { getFormattedErrorMessage } from "@/lib/utils/helper";
import { SurveyCheckboxGroup } from "@/modules/integrations/webhooks/components/survey-checkbox-group";
import { TriggerCheckboxGroup } from "@/modules/integrations/webhooks/components/trigger-checkbox-group";
import { validWebHookURL } from "@/modules/integrations/webhooks/lib/utils";
import { isDiscordWebhook, validWebHookURL } from "@/modules/integrations/webhooks/lib/utils";
import { Button } from "@/modules/ui/components/button";
import { Input } from "@/modules/ui/components/input";
import { Label } from "@/modules/ui/components/label";
@@ -53,6 +53,7 @@ export const AddWebhookModal = ({ environmentId, surveys, open, setOpen }: AddWe
}
setHittingEndpoint(true);
const testEndpointActionResult = await testEndpointAction({ url: testEndpointInput });
console.log("testEndpointActionResult", testEndpointActionResult);
if (!testEndpointActionResult?.data) {
const errorMessage = getFormattedErrorMessage(testEndpointActionResult);
throw new Error(errorMessage);
@@ -113,6 +114,10 @@ export const AddWebhookModal = ({ environmentId, surveys, open, setOpen }: AddWe
throw new Error(t("common.please_select_at_least_one_survey"));
}
if (isDiscordWebhook(testEndpointInput)) {
throw new Error(t("environments.integrations.webhooks.discord_webhook_not_supported"));
}
const endpointHitSuccessfully = await handleTestEndpoint(false);
if (!endpointHitSuccessfully) return;

View File

@@ -35,3 +35,9 @@ export const validWebHookURL = (urlInput: string) => {
return { valid: false, error: "Invalid URL format. Please enter a complete URL including https://" };
}
};
export const isDiscordWebhook = (urlString: string) => {
const url = new URL(urlString);
const DISCORD_WEBHOOK_URL_PATTERN = /^https:\/\/discord\.com\/api\/webhooks\/\d+\/.+$/;
return DISCORD_WEBHOOK_URL_PATTERN.test(url.toString());
};

View File

@@ -1,4 +1,5 @@
import { webhookCache } from "@/lib/cache/webhook";
import { isDiscordWebhook } from "@/modules/integrations/webhooks/lib/utils";
import { Prisma, Webhook } from "@prisma/client";
import { prisma } from "@formbricks/database";
import { cache } from "@formbricks/lib/cache";
@@ -70,6 +71,9 @@ export const deleteWebhook = async (id: string): Promise<boolean> => {
export const createWebhook = async (environmentId: string, webhookInput: TWebhookInput): Promise<boolean> => {
try {
if (isDiscordWebhook(webhookInput.url)) {
throw new UnknownError("Discord webhooks are currently not supported.");
}
const createdWebhook = await prisma.webhook.create({
data: {
...webhookInput,
@@ -136,6 +140,10 @@ export const testEndpoint = async (url: string): Promise<boolean> => {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 5000);
if (isDiscordWebhook(url)) {
throw new UnknownError("Discord webhooks are currently not supported.");
}
const response = await fetch(url, {
method: "POST",
body: JSON.stringify({
@@ -161,6 +169,10 @@ export const testEndpoint = async (url: string): Promise<boolean> => {
if (error.name === "AbortError") {
throw new UnknownError("Request timed out after 5 seconds");
}
if (error instanceof UnknownError) {
throw error;
}
throw new UnknownError(`Error while fetching the URL: ${error.message}`);
}
};

View File

@@ -748,6 +748,7 @@
"add_webhook_description": "Sende Umfragedaten an einen benutzerdefinierten Endpunkt",
"all_current_and_new_surveys": "Alle aktuellen und neuen Umfragen",
"created_by_third_party": "Erstellt von einer dritten Partei",
"discord_webhook_not_supported": "Discord-Webhooks werden derzeit nicht unterstützt.",
"empty_webhook_message": "Deine Webhooks werden hier angezeigt, sobald Du sie hinzufügst ⏲️",
"endpoint_pinged": "Juhu! Wir können den Webhook anpingen!",
"endpoint_pinged_error": "Kann den Webhook nicht anpingen!",

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.",
"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!",

View File

@@ -748,6 +748,7 @@
"add_webhook_description": "Envoyer les données de réponse à l'enquête à un point de terminaison personnalisé",
"all_current_and_new_surveys": "Tous les sondages actuels et nouveaux",
"created_by_third_party": "Créé par un tiers",
"discord_webhook_not_supported": "Les webhooks Discord ne sont actuellement pas pris en charge.",
"empty_webhook_message": "Vos webhooks apparaîtront ici dès que vous les ajouterez. ⏲️",
"endpoint_pinged": "Yay ! Nous pouvons pinger le webhook !",
"endpoint_pinged_error": "Impossible de pinger le webhook !",

View File

@@ -748,6 +748,7 @@
"add_webhook_description": "Enviar dados das respostas da pesquisa para um endpoint personalizado",
"all_current_and_new_surveys": "Todas as pesquisas atuais e novas",
"created_by_third_party": "Criado por um Terceiro",
"discord_webhook_not_supported": "Webhooks do Discord não são suportados no momento.",
"empty_webhook_message": "Seus webhooks vão aparecer aqui assim que você adicioná-los. ⏲️",
"endpoint_pinged": "Uhul! Conseguimos pingar o webhook!",
"endpoint_pinged_error": "Não consegui pingar o webhook!",