-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
41 lines (36 loc) · 1.29 KB
/
handler.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
'use strict';
const https = require('https');
const moment = require('moment');
const yesterday = moment().subtract(1, 'day');
const size = 5;
module.exports.github = (event, context, callback) => {
let request = {
host: 'api.github.com',
headers: {'user-agent': 'AlexaSkill/1.0'},
path: `/search/repositories?sort=stars&order=desc&q=created:>${yesterday.format('YYYY-MM-DD')}`
};
https.get(request, res => {
res.setEncoding('utf8');
let body = '';
res.on('data', data => {
body += data;
});
res.on('end', () => {
body = JSON.parse(body);
let top = body.items.splice(0, size);
callback(null, {
version: '1.0',
response: {
outputSpeech: {
type: 'PlainText',
text: `There are ${body.total_count} trending repositories since, ${yesterday.format("dddd hA")}. I have the top ${size}, they are: ${top.map((item) => {
let name = item.full_name.split('/');
return `${name[1]} by ${name[0]}. `
})}`,
},
shouldEndSession: true,
},
});
});
});
};