1- import { ChatPostMessageResponse , WebClient } from '@slack/web-api ' ;
1+ import { App , ExpressReceiver } from '@slack/bolt ' ;
22import { HttpException } from '../utils/errors.utils' ;
33
4- const slack = new WebClient ( process . env . SLACK_BOT_TOKEN ) ;
4+ const receiver = new ExpressReceiver ( {
5+ signingSecret : process . env . SLACK_SIGNING_SECRET || '' ,
6+ endpoints : '/slack/events'
7+ } ) ;
8+
9+ // Initialize the Bolt app
10+ const slackApp = new App ( {
11+ token : process . env . SLACK_BOT_TOKEN ,
12+ receiver
13+ } ) ;
14+
15+ // Get the WebClient from the Bolt app
16+ const slack = slackApp . client ;
517
618/**
719 * Send a slack message
@@ -18,8 +30,7 @@ export const sendMessage = async (slackId: string, message: string, link?: strin
1830 const block = generateSlackTextBlock ( message , link , linkButtonText ) ;
1931
2032 try {
21- const response : ChatPostMessageResponse = await slack . chat . postMessage ( {
22- token : SLACK_BOT_TOKEN ,
33+ const response = await slack . chat . postMessage ( {
2334 channel : slackId ,
2435 text : message ,
2536 blocks : [ block ] ,
@@ -54,7 +65,6 @@ export const replyToMessageInThread = async (
5465
5566 try {
5667 await slack . chat . postMessage ( {
57- token : SLACK_BOT_TOKEN ,
5868 channel : slackId ,
5969 thread_ts : parentTimestamp ,
6070 text : message ,
@@ -87,7 +97,6 @@ export const editMessage = async (
8797
8898 try {
8999 await slack . chat . update ( {
90- token : SLACK_BOT_TOKEN ,
91100 channel : slackId ,
92101 ts : timestamp ,
93102 text : message ,
@@ -110,7 +119,6 @@ export const reactToMessage = async (slackId: string, parentTimestamp: string, e
110119
111120 try {
112121 await slack . reactions . add ( {
113- token : SLACK_BOT_TOKEN ,
114122 channel : slackId ,
115123 timestamp : parentTimestamp ,
116124 name : emoji
@@ -230,4 +238,59 @@ export const getWorkspaceId = async () => {
230238 }
231239} ;
232240
241+ export async function sendEphemeralConfirmation (
242+ channelId : string ,
243+ threadTs : string ,
244+ userId : string ,
245+ reimbursementRequestId : string
246+ ) {
247+ try {
248+ await slack . chat . postEphemeral ( {
249+ channel : channelId ,
250+ user : userId ,
251+ 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+ ]
286+ } ) ;
287+ } catch ( err : unknown ) {
288+ if ( err instanceof Error ) {
289+ throw new HttpException ( 500 , `Failed to send slack notifications: ${ err . message } ` ) ;
290+ }
291+ }
292+ }
293+
294+ // Export the slack client, bolt app, and receiver for any direct usage if needed
295+ export { slack , slackApp , receiver } ;
233296export default slack ;
0 commit comments