mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import {Link, Store} from '../store/model';
|
|
import {Print, logger} from '../logger';
|
|
import Push, {PushoverMessage} from 'pushover-notifications';
|
|
import {config} from '../config';
|
|
|
|
const pushover = config.notifications.pushover;
|
|
|
|
export function sendPushoverNotification(link: Link, store: Store) {
|
|
if (pushover.token && pushover.username) {
|
|
logger.debug('↗ sending pushover message');
|
|
|
|
const push = new Push({
|
|
token: pushover.token,
|
|
user: pushover.username
|
|
});
|
|
|
|
const message: PushoverMessage =
|
|
pushover.priority < 2
|
|
? {
|
|
message: link.cartUrl ? link.cartUrl : link.url,
|
|
priority: pushover.priority,
|
|
title: Print.inStock(link, store),
|
|
...(link.screenshot && {file: `./${link.screenshot}`})
|
|
}
|
|
: {
|
|
expire: pushover.expire,
|
|
message: link.cartUrl ? link.cartUrl : link.url,
|
|
priority: pushover.priority,
|
|
retry: pushover.retry,
|
|
title: Print.inStock(link, store),
|
|
...(link.screenshot && {file: `./${link.screenshot}`})
|
|
};
|
|
|
|
push.send(message, (error: Error) => {
|
|
if (error) {
|
|
logger.error("✖ couldn't send pushover message", error);
|
|
} else {
|
|
logger.info('✔ pushover message sent');
|
|
}
|
|
});
|
|
}
|
|
}
|