fix email notifications display empty responses, fix webhook data format (#383)

This commit is contained in:
Matti Nannt
2023-06-16 11:49:09 +02:00
committed by GitHub
parent 2f65c8d011
commit e6f6e2296f
5 changed files with 30 additions and 11 deletions

View File

@@ -59,7 +59,8 @@ export async function PUT(
// send response update to pipeline
// don't await to not block the response
sendToPipeline("responseUpdated", {
sendToPipeline({
event: "responseUpdated",
environmentId: survey.environmentId,
surveyId: survey.id,
// only send the updated fields
@@ -72,7 +73,8 @@ export async function PUT(
if (response.finished) {
// send response to pipeline
// don't await to not block the response
sendToPipeline("responseFinished", {
sendToPipeline({
event: "responseFinished",
environmentId: survey.environmentId,
surveyId: survey.id,
data: response,

View File

@@ -82,14 +82,16 @@ export async function POST(request: Request): Promise<NextResponse> {
}
}
sendToPipeline("responseCreated", {
sendToPipeline({
event: "responseCreated",
environmentId: survey.environmentId,
surveyId: response.surveyId,
data: response,
});
if (responseInput.finished) {
sendToPipeline("responseFinished", {
sendToPipeline({
event: "responseFinished",
environmentId: survey.environmentId,
surveyId: response.surveyId,
data: response,

View File

@@ -1,6 +1,17 @@
import { INTERNAL_SECRET, WEBAPP_URL } from "@formbricks/lib/constants";
import { TPipelineTrigger } from "@formbricks/types/v1/pipelines";
export async function sendToPipeline(event, data) {
export async function sendToPipeline({
event,
surveyId,
environmentId,
data,
}: {
event: TPipelineTrigger;
surveyId: string;
environmentId: string;
data: any;
}) {
return fetch(`${WEBAPP_URL}/api/pipeline`, {
method: "POST",
headers: {
@@ -8,8 +19,8 @@ export async function sendToPipeline(event, data) {
},
body: JSON.stringify({
internalSecret: INTERNAL_SECRET,
environmentId: data.environmentId,
surveyId: data.surveyId,
environmentId: environmentId,
surveyId: surveyId,
event,
data,
}),

View File

@@ -0,0 +1,5 @@
import { z } from "zod";
export const ZPipelineTrigger = z.enum(["responseFinished", "responseCreated", "responseUpdated"]);
export type TPipelineTrigger = z.infer<typeof ZPipelineTrigger>;

View File

@@ -1,6 +1,5 @@
import { z } from "zod";
export const ZWebhookTrigger = z.enum(["responseFinished", "responseCreated", "responseUpdated"]);
import { ZPipelineTrigger } from "./pipelines";
export const ZWebhook = z.object({
id: z.string().cuid2(),
@@ -8,14 +7,14 @@ export const ZWebhook = z.object({
updatedAt: z.date(),
url: z.string().url(),
environmentId: z.string().cuid2(),
triggers: z.array(ZWebhookTrigger),
triggers: z.array(ZPipelineTrigger),
});
export type TWebhook = z.infer<typeof ZWebhook>;
export const ZWebhookInput = z.object({
url: z.string().url(),
trigger: ZWebhookTrigger,
trigger: ZPipelineTrigger,
});
export type TWebhookInput = z.infer<typeof ZWebhookInput>;