-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (35 loc) · 1.15 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
const alexaSkillKit = require('alexa-skill-kit');
const AlexaMessageBuilder = require('alexa-message-builder');
const request = require('request-promise');
const imgur = require('imgur');
const secrets = require('./secrets');
imgur.setClientId(secrets.imgur.client_id);
imgur.setAPIUrl('https://api.imgur.com/3/');
exports.handler = function(event, context) {
alexaSkillKit(event, context, parsedMessage => {
let config = {
uri: 'https://themtn.top/api',
simple: false,
json: true
}
let verdict;
return request.get(config)
.catch(err => {
console.log('caught error', err.stack)
})
.then(result => {
verdict = result.result ? 'The mountain is out!' : 'The mountain is not out.';
return imgur.uploadUrl(result.image);
})
.then(result => {
console.log(result);
return new AlexaMessageBuilder()
.addText(verdict)
.addStandardCard('Mt.Rainier', verdict, {
smallImageUrl: result.data.link.replace('http://', 'https://'),
largeImageUrl: result.data.link.replace('http://', 'https://')
})
.get()
});
})
}