Skip to content

Commit bbee16b

Browse files
committed
abstract ephemeral msg function
1 parent 3dc5ef3 commit bbee16b

2 files changed

Lines changed: 53 additions & 38 deletions

File tree

src/backend/src/integrations/slack.ts

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -238,51 +238,28 @@ export const getWorkspaceId = async () => {
238238
}
239239
};
240240

241-
export async function sendEphemeralConfirmation(
241+
/**
242+
* Sends a slack ephemeral message to a user
243+
* @param channelId - the channel id of the channel to send to
244+
* @param threadTs - the timestamp of the thread to send to
245+
* @param userId - the id of the user to send to
246+
* @param text - the text of the message to send (should always be populated in case blocks can't be rendered, but if blocks render text will not)
247+
* @param blocks - the blocks of the message to send
248+
*/
249+
export async function sendEphemeralMessage(
242250
channelId: string,
243251
threadTs: string,
244252
userId: string,
245-
reimbursementRequestId: string
253+
text: string,
254+
blocks: any[]
246255
) {
247256
try {
248257
await slack.chat.postEphemeral({
249258
channel: channelId,
250259
user: userId,
251260
thread_ts: threadTs,
252-
text: 'Approve the request on concur and then click the button below to mark it as submitted on Finishline.',
253-
blocks: [
254-
{
255-
type: 'section',
256-
text: {
257-
type: 'mrkdwn',
258-
text: 'Approve the request on concur and then click the button below to mark it as submitted on Finishline.'
259-
}
260-
},
261-
{
262-
type: 'section',
263-
text: {
264-
type: 'mrkdwn',
265-
text: '<https://us2.concursolutions.com/home|*Click here to go to concur*>'
266-
}
267-
},
268-
{
269-
type: 'actions',
270-
elements: [
271-
{
272-
type: 'button',
273-
text: {
274-
type: 'plain_text',
275-
text: "✓ I've approved the request on Concur"
276-
},
277-
style: 'primary',
278-
action_id: 'sabo_submitted_confirmation',
279-
value: JSON.stringify({
280-
reimbursementRequestId
281-
})
282-
}
283-
]
284-
}
285-
]
261+
text,
262+
blocks
286263
});
287264
} catch (err: unknown) {
288265
if (err instanceof Error) {

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
getUsersInChannel,
1717
reactToMessage,
1818
replyToMessageInThread,
19-
sendEphemeralConfirmation,
19+
sendEphemeralMessage,
2020
sendMessage
2121
} from '../integrations/slack';
2222
import { getUserSlackId, getUserSlackMentionOrName } from './users.utils';
@@ -246,7 +246,45 @@ export const sendPendingSaboSubmissionNotification = async (
246246
const userId = await getUserSlackId(financeUserId);
247247
if (threads && threads.length !== 0 && userId) {
248248
const msgs = threads.map((thread) =>
249-
sendEphemeralConfirmation(thread.channelId, thread.timestamp, userId, reimbursementRequestId)
249+
sendEphemeralMessage(
250+
thread.channelId,
251+
thread.timestamp,
252+
userId,
253+
'Approve the request on concur and then click the button below to mark it as submitted on Finishline.',
254+
[
255+
{
256+
type: 'section',
257+
text: {
258+
type: 'mrkdwn',
259+
text: 'Approve the request on concur and then click the button below to mark it as submitted on Finishline.'
260+
}
261+
},
262+
{
263+
type: 'section',
264+
text: {
265+
type: 'mrkdwn',
266+
text: '<https://us2.concursolutions.com/home|*Click here to go to concur*>'
267+
}
268+
},
269+
{
270+
type: 'actions',
271+
elements: [
272+
{
273+
type: 'button',
274+
text: {
275+
type: 'plain_text',
276+
text: "✓ I've approved the request on Concur"
277+
},
278+
style: 'primary',
279+
action_id: 'sabo_submitted_confirmation',
280+
value: JSON.stringify({
281+
reimbursementRequestId
282+
})
283+
}
284+
]
285+
}
286+
]
287+
)
250288
);
251289
await Promise.all(msgs);
252290
}

0 commit comments

Comments
 (0)