From 0072dda90b637b93647cf3a35dc612cf43d89445 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Tue, 8 Dec 2020 14:20:15 -0500 Subject: [PATCH] fix(pushover): add `expire` and `retry` Fixes #983 --- .env-example | 2 ++ docs/reference/notification.md | 31 ++++++++++++++++----------- src/config.ts | 2 ++ src/notification/pushover.ts | 28 ++++++++++++++++-------- src/types/pushover-notifications.d.ts | 12 ++++++----- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/.env-example b/.env-example index 4379eb6..3b64056 100644 --- a/.env-example +++ b/.env-example @@ -66,6 +66,8 @@ PROXY_ADDRESS="" PROXY_PROTOCOL="" PROXY_PORT="" PUSHBULLET="" +PUSHOVER_EXPIRE="" +PUSHOVER_RETRY="" PUSHOVER_TOKEN="" PUSHOVER_USER="" PUSHOVER_PRIORITY="" diff --git a/docs/reference/notification.md b/docs/reference/notification.md index 6e205b2..3aadb72 100644 --- a/docs/reference/notification.md +++ b/docs/reference/notification.md @@ -87,6 +87,8 @@ Generate required keys using [instructions](https://developers.meethue.com/devel For cloud only usage, instructions to generate are located [here](https://developers.meethue.com/develop/hue-api/remote-authentication/). +> :point_right: Here's a [video demonstration](https://vimeo.com/476083242). + | Environment variable | Description | |:---:|---| | `PHILIPS_HUE_API_KEY` | Hue Bridge API Key | @@ -99,15 +101,13 @@ For cloud only usage, instructions to generate are located [here](https://develo | `PHILIPS_HUE_CLOUD_CLIENT_ID` | Cloud Client ID. Cloud only | | `PHILIPS_HUE_CLOUD_CLIENT_SECRET` | Cloud Client Secret. Cloud only | -> :point_right: Here's a [video demonstration](https://vimeo.com/476083242). - ## Pushbullet Generate token at https://www.pushbullet.com/#settings/account. | Environment variable | Description | |:---:|---| -| `PUSHBULLET` | PushBullet API key | +| `PUSHBULLET` | API key | ## Pushover @@ -115,23 +115,28 @@ Generate token at https://pushover.net/apps/build. | Environment variable | Description | |:---:|---| -| `PUSHOVER_TOKEN` | Pushover access token | -| `PUSHOVER_USER` | Pushover username | -| `PUSHOVER_PRIORITY` | Pushover message priority | +| `PUSHOVER_EXPIRE` | How many seconds your notification will continue to be retried for (every `PUSHOVER_RETRY` seconds) | +| `PUSHOVER_RETRY` | How often (in seconds) the Pushover servers will send the same notification to the user | +| `PUSHOVER_PRIORITY` | Message priority | +| `PUSHOVER_TOKEN` | API token | +| `PUSHOVER_USER` | Username | + +???+ note + `PUSHOVER_EXPIRE` and `PUSHOVER_RETRY` are only used when `PUSHOVER_PRIORITY="2"` ## Slack | Environment variable | Description | |:---:|---| -| `SLACK_CHANNEL` | Slack channel for posting | -| `SLACK_TOKEN` | Slack API token | +| `SLACK_CHANNEL` | Channel for posting | +| `SLACK_TOKEN` | API token | ## Telegram | Environment variable | Description | |:---:|---| -| `TELEGRAM_ACCESS_TOKEN` | Telegram access token | -| `TELEGRAM_CHAT_ID` | Telegram chat ID. Can be comma separated, e.g.: `123456789,987654321` | +| `TELEGRAM_ACCESS_TOKEN` | Access token | +| `TELEGRAM_CHAT_ID` | Chat ID. Can be comma separated, e.g.: `123456789,987654321` | ## Twilio @@ -139,9 +144,9 @@ Token generation can be found at https://twilio.com/console. | Environment variable | Description | |:---:|---| -| `TWILIO_ACCOUNT_SID` | Twilio Account SID | -| `TWILIO_AUTH_TOKEN` | Twilio Auth Token | -| `TWILIO_FROM_NUMBER` | Twilio provided phone number to send messages from | +| `TWILIO_ACCOUNT_SID` | Account SID | +| `TWILIO_AUTH_TOKEN` | Auth Token | +| `TWILIO_FROM_NUMBER` | Provided phone number to send messages from | | `TWILIO_TO_NUMBER` | Mobile number to send SMS to | ???+ note diff --git a/src/config.ts b/src/config.ts index 919b328..7c14475 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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) }, diff --git a/src/notification/pushover.ts b/src/notification/pushover.ts index 8fb21cb..84689bf 100644 --- a/src/notification/pushover.ts +++ b/src/notification/pushover.ts @@ -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) { diff --git a/src/types/pushover-notifications.d.ts b/src/types/pushover-notifications.d.ts index 9beb23a..e24ee31 100644 --- a/src/types/pushover-notifications.d.ts +++ b/src/types/pushover-notifications.d.ts @@ -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 {