mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
chore(misc): normalize logs (#242)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user