chore: refactor config and fix audits (#406)

This commit is contained in:
Jef LeCompte
2020-10-03 13:15:39 -04:00
committed by GitHub
parent f006a8595b
commit 8098a31092
28 changed files with 1765 additions and 403 deletions
+25 -20
View File
@@ -1,30 +1,35 @@
import {Link, Store} from '../store/model';
import {Logger, Print} from '../logger';
import {Config} from '../config';
import {Print, logger} from '../logger';
import {WebClient} from '@slack/web-api';
import {config} from '../config';
const channel = Config.notifications.slack.channel;
const token = Config.notifications.slack.token;
const slack = config.notifications.slack;
const channel = slack.channel;
const token = slack.token;
const web = new WebClient(token);
export function sendSlackMessage(link: Link, store: Store) {
(async () => {
const givenUrl = link.cartUrl ? link.cartUrl : link.url;
if (slack.channel && slack.token) {
logger.debug('↗ sending slack message');
try {
const result = await web.chat.postMessage({
channel,
text: `${Print.inStock(link, store)}\n${givenUrl}`
});
(async () => {
const givenUrl = link.cartUrl ? link.cartUrl : link.url;
if (!result.ok) {
Logger.error('✖ couldn\'t send slack message', result);
return;
try {
const result = await web.chat.postMessage({
channel,
text: `${Print.inStock(link, store)}\n${givenUrl}`
});
if (!result.ok) {
logger.error('✖ couldn\'t send slack message', result);
return;
}
logger.info('✔ slack message sent');
} catch (error) {
logger.error('✖ couldn\'t send slack message', error);
}
Logger.info('✔ slack message sent');
} catch (error) {
Logger.error('✖ couldn\'t send slack message', error);
}
})();
})();
}
}