From 25dc86300e632b1f20d4570d9c25cab6a1d767e5 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Thu, 19 Sep 2024 11:26:23 +0200 Subject: [PATCH] fix: add flow name to S3 Slack notifications & webhook message (#3711) --- api.planx.uk/modules/send/s3/index.ts | 2 ++ .../webhooks/service/sendNotification/index.test.ts | 9 +++++++++ .../modules/webhooks/service/sendNotification/index.ts | 4 ++-- .../modules/webhooks/service/sendNotification/schema.ts | 9 +++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api.planx.uk/modules/send/s3/index.ts b/api.planx.uk/modules/send/s3/index.ts index ffd57cd2ba..ccd2d2ccd9 100644 --- a/api.planx.uk/modules/send/s3/index.ts +++ b/api.planx.uk/modules/send/s3/index.ts @@ -49,6 +49,7 @@ const sendToS3 = async (req: Request, res: Response, next: NextFunction) => { const session = await $api.session.find(sessionId); const passport = session?.data?.passport as Passport; + const flowName = session?.flow?.name; // Generate the ODP Schema JSON, skipping validation if not a supported application type const doValidation = isApplicationTypeSupported(passport); @@ -73,6 +74,7 @@ const sendToS3 = async (req: Request, res: Response, next: NextFunction) => { }, data: { message: "New submission from PlanX", + service: flowName, environment: env, file: fileUrl, payload: doValidation ? "Validated ODP Schema" : "Discretionary", diff --git a/api.planx.uk/modules/webhooks/service/sendNotification/index.test.ts b/api.planx.uk/modules/webhooks/service/sendNotification/index.test.ts index e46a1d249a..563984520b 100644 --- a/api.planx.uk/modules/webhooks/service/sendNotification/index.test.ts +++ b/api.planx.uk/modules/webhooks/service/sendNotification/index.test.ts @@ -351,6 +351,15 @@ describe("Send Slack notifications endpoint", () => { new: { session_id: "s3-pa-123", team_slug: "test-team", + webhook_request: { + data: { + service: "Test flow", + message: "New submission from PlanX", + payload: "Discretionary", + environment: "Staging", + file: "api.editor.planx.dev/private/file/test", + }, + }, }, }, }, diff --git a/api.planx.uk/modules/webhooks/service/sendNotification/index.ts b/api.planx.uk/modules/webhooks/service/sendNotification/index.ts index 9dd900aaf7..0fa5aa221b 100644 --- a/api.planx.uk/modules/webhooks/service/sendNotification/index.ts +++ b/api.planx.uk/modules/webhooks/service/sendNotification/index.ts @@ -44,8 +44,8 @@ const getMessageForEventType = (data: EventData, type: EventType) => { } if (type === "s3-submission") { - const { session_id, team_slug } = data as S3EventData; - return `New S3 + Power Automate submission *${session_id}* [${team_slug}]`; + const { session_id, team_slug, webhook_request } = data as S3EventData; + return `New S3 + Power Automate submission "${webhook_request.data.service}" *${session_id}* [${team_slug}]`; } }; diff --git a/api.planx.uk/modules/webhooks/service/sendNotification/schema.ts b/api.planx.uk/modules/webhooks/service/sendNotification/schema.ts index 0ecf85ccf5..49a8fc8847 100644 --- a/api.planx.uk/modules/webhooks/service/sendNotification/schema.ts +++ b/api.planx.uk/modules/webhooks/service/sendNotification/schema.ts @@ -66,6 +66,15 @@ export const s3SubmissionSchema = z.object({ new: z.object({ session_id: z.string(), team_slug: z.string(), + webhook_request: z.object({ + data: z.object({ + message: z.string(), + service: z.string(), + environment: z.string(), + file: z.string(), + payload: z.string(), + }), + }), }), }), }),