mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 09:57:38 +00:00
refactor: lookup, rm defaults (#69)
prep work for #38 Signed-off-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ const mailOptions: Mail.Options = {
|
||||
subject
|
||||
};
|
||||
|
||||
export default function sendEmail(text: string) {
|
||||
export function sendEmail(text: string) {
|
||||
mailOptions.text = text;
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
|
||||
@@ -1,26 +1 @@
|
||||
import {Config} from '../config';
|
||||
import sendEmail from './email';
|
||||
import sendSlaskMessage from './slack';
|
||||
import sendSMS from './sms';
|
||||
import playSound from './sound';
|
||||
|
||||
export default function sendNotification(cartUrl: string) {
|
||||
if (Config.notifications.email.username && Config.notifications.email.password) {
|
||||
sendEmail(cartUrl);
|
||||
}
|
||||
|
||||
if (Config.notifications.slack.channel && Config.notifications.slack.token) {
|
||||
sendSlaskMessage(cartUrl);
|
||||
}
|
||||
|
||||
if (Config.notifications.phone.number) {
|
||||
const carrier = Config.notifications.phone.carrier.toLowerCase();
|
||||
if (carrier && Config.notifications.phone.availableCarriers.has(carrier)) {
|
||||
sendSMS(cartUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.notifications.playSound) {
|
||||
playSound();
|
||||
}
|
||||
}
|
||||
export * from './notification';
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import {Config} from '../config';
|
||||
import {sendEmail} from './email';
|
||||
import {sendSMS} from './sms';
|
||||
import {playSound} from './sound';
|
||||
import {sendSlackMessage} from './slack';
|
||||
|
||||
export function sendNotification(cartUrl: string) {
|
||||
if (Config.notifications.email.username && Config.notifications.email.password) {
|
||||
sendEmail(cartUrl);
|
||||
}
|
||||
|
||||
if (Config.notifications.slack.channel && Config.notifications.slack.token) {
|
||||
sendSlackMessage(cartUrl);
|
||||
}
|
||||
|
||||
if (Config.notifications.phone.number) {
|
||||
const carrier = Config.notifications.phone.carrier.toLowerCase();
|
||||
if (carrier && Config.notifications.phone.availableCarriers.has(carrier)) {
|
||||
sendSMS(cartUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.notifications.playSound) {
|
||||
playSound();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ const channel = Config.notifications.slack.channel;
|
||||
const token = Config.notifications.slack.token;
|
||||
const web = new WebClient(token);
|
||||
|
||||
export default function sendSlackMessage(text: string) {
|
||||
export function sendSlackMessage(text: string) {
|
||||
(async () => {
|
||||
try {
|
||||
const result = await web.chat.postMessage({text, channel});
|
||||
|
||||
@@ -20,7 +20,7 @@ const mailOptions: Mail.Options = {
|
||||
subject
|
||||
};
|
||||
|
||||
export default function sendSMS(text: string) {
|
||||
export function sendSMS(text: string) {
|
||||
mailOptions.text = text;
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as fs from 'fs';
|
||||
const notificationSound = './resources/sounds/' + Config.notifications.playSound;
|
||||
const player = playerLib();
|
||||
|
||||
export default function playSound() {
|
||||
export function playSound() {
|
||||
// Check if file exists
|
||||
fs.access(notificationSound, fs.constants.F_OK, err => {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user