-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Evan Gentis <[email protected]>
- Loading branch information
Showing
6 changed files
with
216 additions
and
2 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
EMAIL_USERNAME="[email protected]" | ||
EMAIL_PASSWORD="secretpassword" | ||
SLACK_CHANNEL="SlackChannelName" | ||
SLACK_TOKEN="slack-token" | ||
STORES="bestbuy,bandh,nvidia" | ||
NOTIFICATION_METHODS="email" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import {Config} from '../config'; | ||
import sendEmail from './email'; | ||
import sendSlaskMessage from './slack'; | ||
|
||
export default function sendNotification(cartUrl: string) { | ||
if (Config.notifications.email) { | ||
if (Config.notificationMethods.toLocaleLowerCase().includes('email')) { | ||
sendEmail(cartUrl); | ||
} | ||
|
||
if (Config.notificationMethods.toLocaleLowerCase().includes('slack')) { | ||
sendSlaskMessage(cartUrl); | ||
} | ||
} |
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,23 @@ | ||
import {WebClient} from '@slack/web-api'; | ||
import {Config} from '../config'; | ||
import {Logger} from '../logger'; | ||
|
||
const channel = Config.slack.channel ?? ''; | ||
const token = Config.slack.token ?? ''; | ||
const web = new WebClient(token); | ||
|
||
export default function sendSlackMessage(text: string) { | ||
(async () => { | ||
try { | ||
const result = await web.chat.postMessage({text, channel}); | ||
if (!result.ok) { | ||
Logger.error(result.error); | ||
return; | ||
} | ||
|
||
Logger.info(`✔ slack message sent to '${channel}': ${text}`); | ||
} catch (error) { | ||
Logger.error(error); | ||
} | ||
})(); | ||
} |