-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
99 lines (77 loc) · 2.52 KB
/
index.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const q = require('daskeyboard-applet');
const logger = q.logger;
const queryUrlBase = 'https://glip.com/api/';
function getTimestamp() {
var d = new Date(Date.now()),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
class Glip extends q.DesktopApp {
constructor() {
super();
// run every min
this.pollingInterval = 1 * 60 * 1000;
this.timestamp = getTimestamp();
// For checking plural or singular
this.notification = "";
}
async applyConfig() {
logger.info("Initialisation.")
// Get conversations
// https://api.glip.com/methods/conversations.list
}
async getMessages() {
// Get messages from the conversations (check email)
// https://api.glip.com/methods/conversations.history
// Need to update. Was for testing.
// const query = "search.messages?query=pickleface&sort=timestamp&pretty=1";
const query = "search.messages?query=pickleface&sort=timestamp";
const proxyRequest = new q.Oauth2ProxyRequest({
apiKey: this.authorization.apiKey,
uri: queryUrlBase + query
});
// first get the user projects
return this.oauth2ProxyRequest(proxyRequest);
}
async run() {
console.log("Running.");
return this.getMessages().then(newMessages => {
this.timestamp = getTimestamp();
logger.info("This is the response", newMessages);
if (newMessages && newMessages.length > 0) {
if (newMessages.length == 1) {
this.notification = "notification";
} else {
this.notification = "notifications";
}
logger.info("Got " + newMessages.length + this.notification);
return new q.Signal({
points: [
[new q.Point("#0000FF", q.Effects.BLINK)]
],
name: `Glip`,
message: `You have a new notification.`,
link: {
url: 'https://glip.com',
label: 'Show in Glip',
},
});
} else {
return null;
}
}).catch(error => {
const message = error.statusCode == 402
? 'Payment required. This applet requires a premium Glip account.' : error;
logger.error(`Sending error signal: ${message}`);
throw new Error(message);
})
}
}
module.exports = {
Glip: Glip
}
const applet = new Glip();