Skip to content

Commit

Permalink
fix: add flow name to S3 Slack notifications & webhook message (#3711)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Sep 19, 2024
1 parent f8dfadd commit 25dc863
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api.planx.uk/modules/send/s3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}]`;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
}),
}),
}),
}),
Expand Down

0 comments on commit 25dc863

Please sign in to comment.