generated from pabio/github-actions-starter
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Move notification to helper function
- Loading branch information
1 parent
38380a0
commit 3bb60ab
Showing
2 changed files
with
31 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { UpptimeConfig } from "./interfaces"; | ||
import axios from "axios"; | ||
|
||
export const sendNotification = async (config: UpptimeConfig, text: string) => { | ||
console.log("[debug] Sending notification", text); | ||
console.log(`[debug] Notification config has ${(config.notifications || []).length} keys`); | ||
for await (const notification of config.notifications || []) { | ||
if (notification.type === "slack") { | ||
console.log("[debug] Sending Slack notification to channel", notification.channel); | ||
const token = process.env.SLACK_APP_ACCESS_TOKEN; | ||
if (token) | ||
await axios.post( | ||
"https://slack.com/api/chat.postMessage", | ||
{ channel: notification.channel, text }, | ||
{ headers: { Authorization: `Bearer ${process.env.SLACK_BOT_ACCESS_TOKEN}` } } | ||
); | ||
console.log("[debug] Slack token found?", !!token); | ||
} else if (notification.type === "discord") { | ||
console.log("[debug] Sendind Discord notification"); | ||
const webhookUrl = process.env.DISCORD_WEBHOOK_URL; | ||
if (webhookUrl) await axios.post(webhookUrl, { content: text }); | ||
} | ||
} | ||
console.log("[debug] Notifications are sent"); | ||
}; |
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