Skip to content

Instantly share code, notes, and snippets.

@fforbeck
Last active November 3, 2017 18:34
Show Gist options
  • Save fforbeck/b39973945bd0e897209764f1f5faeb18 to your computer and use it in GitHub Desktop.
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>`.
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