chore(misc): normalize logs (#242)

This commit is contained in:
Jef LeCompte
2020-09-23 14:20:06 -04:00
committed by GitHub
parent 8466f9f398
commit 7c50e2b5aa
21 changed files with 239 additions and 183 deletions
+13 -6
View File
@@ -1,23 +1,30 @@
import {Link, Store} from '../store/model';
import {Logger, Print} from '../logger';
import {Config} from '../config';
import {Logger} from '../logger';
import {WebClient} from '@slack/web-api';
const channel = Config.notifications.slack.channel;
const token = Config.notifications.slack.token;
const web = new WebClient(token);
export function sendSlackMessage(cartUrl: string) {
export function sendSlackMessage(link: Link, store: Store) {
(async () => {
const givenUrl = link.cartUrl ? link.cartUrl : link.url;
try {
const result = await web.chat.postMessage({channel, text: cartUrl});
const result = await web.chat.postMessage({
channel,
text: `${Print.inStock(link, store)}\n${givenUrl}`
});
if (!result.ok) {
Logger.error(result.error);
Logger.error('✖ couldn\'t send slack message', result);
return;
}
Logger.info(` slack message sent to '${channel}': ${cartUrl}`);
Logger.info('✔ slack message sent');
} catch (error) {
Logger.error(error);
Logger.error('✖ couldn\'t send slack message', error);
}
})();
}