Skip to content
Snippets Groups Projects
Commit 68bff4e3 authored by ryadav88's avatar ryadav88
Browse files

slack bot for weather conditions

parents
Branches
Tags
No related merge requests found
node_modules
auth.md
web: node index.js
A slackbot that gets the weather forecast.
index.js 0 → 100644
var express = require('express');
var app = express();
var url = require('url');
var request = require('request');
var format = ".json";
var host = 'http://api.wunderground.com/api/' + apikey;
console.log('Host: ' + host);
var path = "/conditions/q/" + query + format;
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.set('port', (process.env.PORT || 9001));
app.get('/', function(req, res){
res.send('It works!');
});
app.post('/post', function(req, res){
var parsed_url = host + path;
console.log(parsed_url);
request(parsed_url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
var first_url = data.response.current_observation.station_id;
var body = {
response_type: "in_channel",
text: first_url
};
res.send(body);
}
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
{
"name": "slack-weather",
"version": "1.0.0",
"description": "_A Slackbot that gets weather conditions",
"main": "index.js",
"dependencies": {
"body-parser": "^1.14.2",
"ejs": "2.3.3",
"express": "4.13.3",
"request": "^2.67.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ryadav88/slack-weather.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/ryadav88/slack-weather/issues"
},
"homepage": "https://github.com/ryadav88/slack-weather#readme"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment