50 lines
1007 B
JavaScript
50 lines
1007 B
JavaScript
import Push from 'pushover-notifications';
|
|
|
|
import { PUSH_SETTINGS } from './config';
|
|
|
|
export default class Pusher {
|
|
constructor(logger) {
|
|
this.pushClient = null;
|
|
this.groupPushClient = null;
|
|
this.logger = logger;
|
|
}
|
|
|
|
async connect() {
|
|
this.pushClient = new Push({
|
|
user: PUSH_SETTINGS.PUSHOVER_USER,
|
|
token: PUSH_SETTINGS.PUSHOVER_TOKEN,
|
|
});
|
|
|
|
if (PUSH_SETTINGS.PUSHOVER_GROUP) {
|
|
this.groupPushClient = new Push({
|
|
user: PUSH_SETTINGS.PUSHOVER_GROUP,
|
|
token: PUSH_SETTINGS.PUSHOVER_TOKEN,
|
|
});
|
|
}
|
|
|
|
this.logger.log('Push notifications enabled!');
|
|
}
|
|
|
|
send(title, message) {
|
|
this.pushClient.send({
|
|
message,
|
|
title,
|
|
sound: 'magic',
|
|
priority: 0,
|
|
}, null);
|
|
}
|
|
|
|
sendAll(title, message) {
|
|
if (this.groupPushClient) {
|
|
this.groupPushClient.send({
|
|
message,
|
|
title,
|
|
sound: 'magic',
|
|
priority: 0,
|
|
}, null);
|
|
} else {
|
|
this.send(title, message);
|
|
}
|
|
}
|
|
}
|