Skip to content

Commit 1083c58

Browse files
committed
slack notifications mention users
1 parent 0f6048e commit 1083c58

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

src/backend/src/services/reimbursement-requests.services.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,11 @@ export default class ReimbursementRequestService {
11071107
...getReimbursementStatusQueryArgs(organization.organizationId)
11081108
});
11091109

1110-
await sendReimbursementRequestLeadershipApprovedNotification(reimbursementRequest.notificationSlackThreads);
1110+
await sendReimbursementRequestLeadershipApprovedNotification(
1111+
reimbursementRequest.notificationSlackThreads,
1112+
submitter.userId,
1113+
reimbursementRequest.recipientId
1114+
);
11111115

11121116
return reimbursementStatusTransformer(reimbursementStatus);
11131117
}
@@ -1188,7 +1192,11 @@ export default class ReimbursementRequestService {
11881192
...getReimbursementStatusQueryArgs(organization.organizationId)
11891193
});
11901194

1191-
await sendPendingSaboSubmissionNotification(reimbursementRequest.notificationSlackThreads);
1195+
await sendPendingSaboSubmissionNotification(
1196+
reimbursementRequest.notificationSlackThreads,
1197+
submitter.userId,
1198+
reimbursementRequest.recipientId
1199+
);
11921200

11931201
return reimbursementStatusTransformer(reimbursementStatus);
11941202
}
@@ -1628,7 +1636,7 @@ export default class ReimbursementRequestService {
16281636
...getReimbursementStatusQueryArgs(organization.organizationId)
16291637
});
16301638

1631-
await sendReimbursementRequestChangesRequestedNotification(reimbursementRequest.notificationSlackThreads);
1639+
await sendReimbursementRequestChangesRequestedNotification(reimbursementRequest.notificationSlackThreads, user.userId);
16321640

16331641
return reimbursementStatusTransformer(deletedStatus);
16341642
}

src/backend/src/utils/slack.utils.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
replyToMessageInThread,
1919
sendMessage
2020
} from '../integrations/slack';
21-
import { getUserFullName, getUserSlackId } from './users.utils';
21+
import { getUserSlackId, getUserSlackMentionOrName } from './users.utils';
2222
import prisma from '../prisma/prisma';
2323
import { HttpException } from './errors.utils';
2424
import { Change_Request, Design_Review, Team, WBS_Element } from '@prisma/client';
@@ -38,7 +38,7 @@ interface SlackMessageThread {
3838
changeRequestId: string | null;
3939
}
4040

41-
const DEV_TESTING_OVERRIDE = false;
41+
const DEV_TESTING_OVERRIDE = true;
4242

4343
// build the "due" string for the upcoming deadlines slack message
4444
export const buildDueString = (daysUntilDeadline: number): string => {
@@ -137,7 +137,7 @@ export const sendReimbursementRequestCreatedNotificationAndCreateMessageInfo = a
137137
): Promise<void> => {
138138
if (process.env.NODE_ENV !== 'production' && !DEV_TESTING_OVERRIDE) return; // don't send msgs unless in prod
139139

140-
const msg = `${await getUserFullName(submitterId)} created a reimbursement request (ID#: ${requestIdentifier}) 💲`;
140+
const msg = `${await getUserSlackMentionOrName(submitterId)} created a reimbursement request (ID#: ${requestIdentifier}) 💲`;
141141
const link = `https://finishlinebyner.com/finance/reimbursement-requests/${requestId}`;
142142
const linkButtonText = 'View Reimbursement Request';
143143

@@ -203,24 +203,35 @@ export const sendThreadResponse = async (threads: SlackMessageThread[], message:
203203
export const sendReimbursementRequestPendingFinanceNotification = async (threads: SlackMessageThread[]) =>
204204
await sendThreadResponse(threads, `This Reimbursement Request is now pending finance :moneybag:`);
205205

206-
export const sendReimbursementRequestLeadershipApprovedNotification = async (threads: SlackMessageThread[]) =>
206+
export const sendReimbursementRequestLeadershipApprovedNotification = async (
207+
threads: SlackMessageThread[],
208+
approverId: string,
209+
recipientId: string
210+
) =>
207211
await sendThreadResponse(
208212
threads,
209-
`This Reimbursment Request has been approved by leadership, you may now purchase the items and add the receipts, then mark the reimbursement request as pending finance.`
213+
`${await getUserSlackMentionOrName(approverId)} has approved this reimbursement request. ${await getUserSlackMentionOrName(recipientId)} you may now purchase the items, add the receipts, and mark the reimbursement request as pending finance.`
210214
);
211215

212-
export const sendReimbursementRequestChangesRequestedNotification = async (threads: SlackMessageThread[]) =>
216+
export const sendReimbursementRequestChangesRequestedNotification = async (threads: SlackMessageThread[], userId: string) =>
213217
await sendThreadResponse(
214218
threads,
215-
'The finance team has requested changes on this reimbursement request, please make the changes and remark as pending finance.'
219+
`${await getUserSlackMentionOrName(userId)} has requested changes on this reimbursement request, please make the changes and remark as pending finance.`
216220
);
217221

218222
export const sendSubmittedToSaboNotification = async (threads: SlackMessageThread[]) => {
219223
await sendThreadResponse(threads, 'This reimbursement request has been submitted to sabo!');
220224
};
221225

222-
export const sendPendingSaboSubmissionNotification = async (threads: SlackMessageThread[]) => {
223-
await sendThreadResponse(threads, 'This Reimbursement Request is pending submission to sabo!');
226+
export const sendPendingSaboSubmissionNotification = async (
227+
threads: SlackMessageThread[],
228+
financeUserId: string,
229+
pendingSubmissionFromId: string
230+
) => {
231+
await sendThreadResponse(
232+
threads,
233+
`${await getUserSlackMentionOrName(financeUserId)} has added this reimbursement request to Concur. ${await getUserSlackMentionOrName(pendingSubmissionFromId)}, please approve the request in Concur and mark it as submitted on Finishline.`
234+
);
224235
};
225236

226237
export const sendSlackDesignReviewConfirmNotification = async (

src/backend/src/utils/users.utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ export const getUserFullName = async (userId: string | null) => {
2525
return `${user.firstName} ${user.lastName}`;
2626
};
2727

28+
export const getUserSlackMentionOrName = async (userId: string | null) => {
29+
if (!userId) return 'no one';
30+
const user = await prisma.user.findUnique({
31+
where: { userId },
32+
include: {
33+
userSettings: {
34+
select: { slackId: true }
35+
}
36+
}
37+
});
38+
if (!user) return 'no one';
39+
return user.userSettings?.slackId ? `<@${user.userSettings.slackId}>` : `${user.firstName} ${user.lastName}`;
40+
};
41+
2842
export const getUserSlackId = async (userId?: string): Promise<string | undefined> => {
2943
if (!userId) return undefined;
3044
const user = await prisma.user.findUnique({ where: { userId }, include: { userSettings: true } });

0 commit comments

Comments
 (0)