fix(pushover): add expire and retry

Fixes #983
This commit is contained in:
Jef LeCompte
2020-12-08 14:20:15 -05:00
parent d56bcddb05
commit 0072dda90b
5 changed files with 48 additions and 27 deletions
+2
View File
@@ -241,7 +241,9 @@ const notifications = {
playSound: envOrString(process.env.PLAY_SOUND),
pushbullet: envOrString(process.env.PUSHBULLET),
pushover: {
expire: envOrNumber(process.env.PUSHOVER_EXPIRE),
priority: envOrNumber(process.env.PUSHOVER_PRIORITY),
retry: envOrNumber(process.env.PUSHOVER_RETRY),
token: envOrString(process.env.PUSHOVER_TOKEN),
username: envOrString(process.env.PUSHOVER_USER)
},
+19 -9
View File
@@ -4,20 +4,30 @@ import Push, {PushoverMessage} from 'pushover-notifications';
import {config} from '../config';
const pushover = config.notifications.pushover;
const push = new Push({
token: pushover.token,
user: pushover.username
});
export function sendPushoverNotification(link: Link, store: Store) {
if (pushover.token && pushover.username) {
logger.debug('↗ sending pushover message');
const message: PushoverMessage = {
message: link.cartUrl ? link.cartUrl : link.url,
priority: pushover.priority,
title: Print.inStock(link, store)
};
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)
}
: {
expire: pushover.expire,
message: link.cartUrl ? link.cartUrl : link.url,
priority: pushover.priority,
retry: pushover.retry,
title: Print.inStock(link, store)
};
push.send(message, (error: Error) => {
if (error) {
+7 -5
View File
@@ -37,15 +37,17 @@ declare module 'pushover-notifications' {
}
export interface PushoverMessage {
message: string;
file?: string | {name: string; data: string};
device?: string;
expire?: number;
file?: string | {name: string; data: string};
message: string;
priority?: number;
retry?: number;
sound?: Sound;
timestamp?: number;
title?: string;
url?: string;
url_title?: string;
priority?: number;
sound?: Sound;
timestamp?: number;
}
export class Pushover {