-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (63 loc) · 1.73 KB
/
index.js
File metadata and controls
74 lines (63 loc) · 1.73 KB
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
const gplay = require('google-play-scraper')
const request = require('axios')
const AWS = require('aws-sdk')
const fs = require('fs')
const appId = 'APPID CHANGE ME'
const ssm = new AWS.SSM({region: 'ap-southeast-2'});
const params = {
Name: 'slackwebhook-ssm',
WithDecryption: true
};
ssm.getParameter(params, (ssmError, slackWebhook) => {
const slackSend = async (review) => {
let stars = ''
for (i = 0; i < +review.score; i++) {
stars = stars.concat(':star:')
}
let barcolor = 'good'
if (+review.score < 3) {
barcolor = 'danger'
}
else if (+review.score === 3) {
barcolor = 'warning'
}
return await request.post(slackWebhook.Parameter.Value, {
channel: '#android-reviews-channel',
username: 'Android Reviews Bot',
icon_emoji: ':android:',
attachments: [{
color: barcolor,
title: review.userName,
text: `${review.text}\n\n${stars}`,
thumb_url: review.userImage
}],
})
}
const getReviews = async (appId) => {
return await gplay.reviews({appId , page: 0, sort: gplay.sort.NEWEST})
}
const main = (async () => {
try {
reviews = await getReviews(appId)
}
catch (error) {
throw error
}
fs.readFile('ids.json', 'utf8', (err, data) => {
if (err){
console.log(err)
throw err
}
obj = JSON.parse(data)
for (var i = 0, l = reviews.length; i < l; i++) {
if (obj.ids.indexOf(reviews[i].id) === -1) {
console.log(reviews[i].id + 'not found')
slackSend(reviews[i])
obj.ids.push(reviews[i].id)
console.log(reviews[i])
}
fs.writeFileSync('ids.json', JSON.stringify(obj), 'utf8')
}
})
})()
});