-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushService.js
70 lines (59 loc) · 1.81 KB
/
pushService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// pushService.js
// Service to for pushing notifications
// ==================
// import
const PushOver = require('pushover-notifications');
/**
* Service to push notifications.
* {@link ApiAccessService}
*/
class ApiPushService {
/**
* Constructor for init Push Service
* @param {*} user user id for push service
* @param {*} token token for push service
*/
constructor (user, token) {
this.user = user;
this.token = token;
const parameter = {
user: user,
token: token,
onerror: function (error) {
console.log(error);
}
};
this.push = new PushOver(parameter);
}
/**
* Push given message and title
* @param {string} title notification title
* @param {string} message input message
* @param {requestCallback} callback callback to handle result/error
*/
pushNotification (title, message, callback) {
// default 0: normal notification
this.pushNotificationWithPriority(title, message, 0, callback);
}
/**
* Push given message and title
* @param {string} title notification title
* @param {string} message input message
* @param {number} priority notification priority (-2,-1,0,1,2)
* @param {requestCallback} callback callback to handle result/error
*/
pushNotificationWithPriority (title, message, priority, callback) {
if (this.user == undefined || this.token == undefined) {
console.log(`# # # # #\n${title} - ${message}\n# # # # #`);
return;
}
const msg = {
message: message,
title: title,
sound: 'magic',
priority: priority
};
this.push.send(msg, callback);
}
};
module.exports = ApiPushService;