Last active
November 3, 2017 18:34
-
-
Save fforbeck/b39973945bd0e897209764f1f5faeb18 to your computer and use it in GitHub Desktop.
Simple webtask I created to retrieve the current weather from Slack with command: `/wt wttr-in <city-name>`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const got = require('got'); | |
module.exports = (ctx, cb) => { | |
var weatherForCity = 'http://api.openweathermap.org/data/2.5/weather?&units=metric&APPID=8b49f82415341963f8768cce938de042&q=' + ctx.body.text; | |
got(weatherForCity) | |
.then(response => { | |
var json = JSON.parse(response.body); | |
var weather = json.weather[0].description + ', ' + json.main.temp + ' celcius'; | |
cb(null, { text: weather}); | |
}) | |
.catch(error => { | |
cb(null, { text: 'Unable to find the weather for this place: ' + error }); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment