Skip to content

Commit

Permalink
fix(pushover): add expire and retry
Browse files Browse the repository at this point in the history
Fixes #983
  • Loading branch information
jef committed Dec 8, 2020
1 parent d56bcdd commit 0072dda
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ PROXY_ADDRESS=""
PROXY_PROTOCOL=""
PROXY_PORT=""
PUSHBULLET=""
PUSHOVER_EXPIRE=""
PUSHOVER_RETRY=""
PUSHOVER_TOKEN=""
PUSHOVER_USER=""
PUSHOVER_PRIORITY=""
Expand Down
31 changes: 18 additions & 13 deletions docs/reference/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -99,49 +101,52 @@ 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

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

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
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
28 changes: 19 additions & 9 deletions src/notification/pushover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions src/types/pushover-notifications.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ declare module 'pushover-notifications' {
}

export interface PushoverMessage {
message: string;
file?: string | {name: string; data: string};
device?: string;
title?: string;
url?: string;
url_title?: 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;
}

export class Pushover {
Expand Down

0 comments on commit 0072dda

Please sign in to comment.