-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (34 loc) · 1.4 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
const GoogleHome = require("google-home-push");
const Axios = require('axios')
require('dotenv').config()
if (!process.env.GOOGLE_HOME_IP || !process.env.GITHUB_TOKEN) throw new Error('Rename .env_default and add your details')
// Pass the name or IP address of your device
const googleHomeInstance = new GoogleHome(process.env.GOOGLE_HOME_IP);
const idsThatHaveBeenRead = []
const check = async () => {
console.log('Checking')
const config = {
headers: {
Authorization: `token ${process.env.GITHUB_TOKEN}`
}
};
const { data: allNotifications} = await Axios.get('https://api.github.com/notifications', config)
const notifications = allNotifications.filter(({id}) => !idsThatHaveBeenRead.includes(id))
const count = notifications.length
if (count === 0) {
console.log('No new notifications!')
return
}
let textToSend = `You have ${count} new github ${count > 1 ? 'notifications' : 'notification'}. `
let index = 0
for (const notification of notifications) {
textToSend += ++index + '. '
textToSend += 'Reason: ' + notification.reason + '. '
textToSend += 'Type: ' + notification.subject.type + '. '
textToSend += 'Title: ' + notification.subject.title + '. '
idsThatHaveBeenRead.push(notification.id)
}
googleHomeInstance.speak(textToSend)
}
check()
setInterval(check, 60 * 1000)