mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-12 01:29:42 -06:00
Extend Webhook with surveyIds filter (#512)
* add surveyIds filter to webhooks. Use triggers array instead of single trigger * include webhook id in webhook payload * run pnpm format
This commit is contained in:
@@ -27,11 +27,17 @@ export const meta = {
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: "trigger",
|
||||
type: "string",
|
||||
description: "The event that will trigger the webhook.",
|
||||
label: "triggers",
|
||||
type: "string[]",
|
||||
description: "List of events that will trigger the webhook",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: "surveyIds",
|
||||
type: "string[]",
|
||||
description:
|
||||
"List of survey IDs that will trigger the webhook. If not provided, the webhook will be triggered for all surveys.",
|
||||
},
|
||||
]}
|
||||
example={`{
|
||||
"url": "https://mysystem.com/myendpoint",
|
||||
@@ -51,7 +57,8 @@ export const meta = {
|
||||
"environmentId": "clisypjy4000319t4imm289uo",
|
||||
"triggers": [
|
||||
"responseFinished"
|
||||
]
|
||||
],
|
||||
"surveyIds": ["clisypjy4000319t4imm289uo"]
|
||||
}
|
||||
}`,
|
||||
},
|
||||
@@ -82,9 +89,10 @@ export const meta = {
|
||||
]}
|
||||
/>
|
||||
|
||||
| field name | required | default | description |
|
||||
| ---------- | -------- | ------- | ------------------------------------------------------------------------------------------------------ |
|
||||
| url | yes | - | The endpoint that the webhook will send data to |
|
||||
| trigger | yes | - | The event that will trigger the webhook ("responseCreated" or "responseUpdated" or "responseFinished") |
|
||||
| field name | required | default | description |
|
||||
| ---------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
|
||||
| url | yes | - | The endpoint that the webhook will send data to |
|
||||
| trigger | yes | - | The event that will trigger the webhook ("responseCreated" or "responseUpdated" or "responseFinished") |
|
||||
| surveyIds | no | - | List of survey IDs that will trigger the webhook. If not provided, the webhook will be triggered for all surveys. |
|
||||
|
||||
export default ({ children }) => <Layout meta={meta}>{children}</Layout>;
|
||||
|
||||
@@ -51,6 +51,18 @@ export async function POST(request: Request) {
|
||||
triggers: {
|
||||
hasSome: event,
|
||||
},
|
||||
OR: [
|
||||
{
|
||||
surveyIds: {
|
||||
has: surveyId,
|
||||
},
|
||||
},
|
||||
{
|
||||
surveyIds: {
|
||||
isEmpty: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -60,6 +72,7 @@ export async function POST(request: Request) {
|
||||
await fetch(webhook.url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
webhookId: webhook.id,
|
||||
event,
|
||||
data,
|
||||
}),
|
||||
|
||||
@@ -32,7 +32,7 @@ export default function UpdateQuestionId({ localSurvey, question, questionIdx, u
|
||||
value={currentValue}
|
||||
onChange={(e) => setCurrentValue(e.target.value)}
|
||||
disabled={localSurvey.status !== "draft"}
|
||||
className={isInputInvalid ? "focus:border-red-300 border-red-300" : ""}
|
||||
className={isInputInvalid ? "border-red-300 focus:border-red-300" : ""}
|
||||
/>
|
||||
{localSurvey.status === "draft" && (
|
||||
<Button
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" ADD COLUMN "surveyIds" TEXT[];
|
||||
@@ -37,6 +37,7 @@ model Webhook {
|
||||
environment Environment @relation(fields: [environmentId], references: [id], onDelete: Cascade)
|
||||
environmentId String
|
||||
triggers PipelineTriggers[]
|
||||
surveyIds String[]
|
||||
}
|
||||
|
||||
model Attribute {
|
||||
@@ -313,19 +314,19 @@ enum WidgetPlacement {
|
||||
}
|
||||
|
||||
model Product {
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||
updatedAt DateTime @updatedAt @map(name: "updated_at")
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||
updatedAt DateTime @updatedAt @map(name: "updated_at")
|
||||
name String
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
teamId String
|
||||
environments Environment[]
|
||||
brandColor String @default("#64748b")
|
||||
recontactDays Int @default(7)
|
||||
formbricksSignature Boolean @default(true)
|
||||
placement WidgetPlacement @default(bottomRight)
|
||||
clickOutsideClose Boolean @default(true)
|
||||
darkOverlay Boolean @default(false)
|
||||
brandColor String @default("#64748b")
|
||||
recontactDays Int @default(7)
|
||||
formbricksSignature Boolean @default(true)
|
||||
placement WidgetPlacement @default(bottomRight)
|
||||
clickOutsideClose Boolean @default(true)
|
||||
darkOverlay Boolean @default(false)
|
||||
}
|
||||
|
||||
enum Plan {
|
||||
|
||||
@@ -39,13 +39,14 @@ export const createWebhook = async (
|
||||
webhookInput: TWebhookInput
|
||||
): Promise<TWebhook> => {
|
||||
try {
|
||||
if (!webhookInput.url || !webhookInput.trigger) {
|
||||
if (!webhookInput.url || !webhookInput.triggers) {
|
||||
throw new InvalidInputError("Missing URL or trigger in webhook input");
|
||||
}
|
||||
return await prisma.webhook.create({
|
||||
data: {
|
||||
url: webhookInput.url,
|
||||
triggers: [webhookInput.trigger],
|
||||
triggers: webhookInput.triggers,
|
||||
surveyIds: webhookInput.surveyIds || [],
|
||||
environment: {
|
||||
connect: {
|
||||
id: environmentId,
|
||||
|
||||
@@ -14,7 +14,8 @@ export type TWebhook = z.infer<typeof ZWebhook>;
|
||||
|
||||
export const ZWebhookInput = z.object({
|
||||
url: z.string().url(),
|
||||
trigger: ZPipelineTrigger,
|
||||
triggers: z.array(ZPipelineTrigger),
|
||||
surveyIds: z.array(z.string().cuid2()).optional(),
|
||||
});
|
||||
|
||||
export type TWebhookInput = z.infer<typeof ZWebhookInput>;
|
||||
|
||||
Reference in New Issue
Block a user