-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bcb299
commit 5046011
Showing
2 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// slackUtils.ts | ||
|
||
import axios, { AxiosResponse } from 'axios'; | ||
|
||
interface SlackMessage { | ||
text: string; | ||
} | ||
|
||
export const sendSlackMessage = async (message: SlackMessage): Promise<AxiosResponse | void> => { | ||
const slackWebhookUrl = process.env.SLACK_WEBHOOK; | ||
|
||
if (!slackWebhookUrl) { | ||
console.error('Slack webhook URL is not defined.'); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await axios.post(slackWebhookUrl, message); | ||
return response; | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
console.error('Error sending Slack message:', error.message); | ||
// Handle the error as needed | ||
} else { | ||
console.error('An unexpected error occurred:', error); | ||
// Handle other types of errors or log them | ||
} | ||
} | ||
}; |