-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweather.js
43 lines (32 loc) · 1.05 KB
/
weather.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
var weather = require('weather-js');
var Botkit = require('botkit');
askWeather = function(response, convo) {
convo.ask("For which location would you like me to get the weather?", function(response, convo) {
console.log(response);
// console.log(convo);
convo.say("Awesome. Let me check...");
getWeather(response,convo);
});
}
getWeather = function(response,convo){
weather.find({search: response.text, degreeType: 'F'}, function(err, result) {
if(err) console.log(err);
// var jsonContent = JSON.parse(result);
console.log(result[0].current.imageUrl);
// convo.say(JSON.stringify(result[0].current, null, 2));
var reply_with_attachments = {
'attachments': [
{
'fallback':"temperature",
'title': 'Current temperature is ' +result[0].current.temperature ,
'text': result[0].location.name,
"image_url":result[0].current.imageUrl,
'color': '#7CD197'
}
]
}
convo.say(reply_with_attachments);
convo.next();
});
}
module.exports = askWeather;