├── .gitignore ├── LICENSE ├── Procfile ├── README.md ├── app.js ├── app.json ├── hnbot.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | #### joe made this: https://goel.io/joe 2 | 3 | #####=== Node ===##### 4 | 5 | # Logs 6 | logs 7 | *.log 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directory 30 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 31 | node_modules 32 | 33 | # Debug log from npm 34 | npm-debug.log 35 | 36 | #####=== OSX ===##### 37 | .DS_Store 38 | .AppleDouble 39 | .LSOverride 40 | 41 | # Icon must end with two \r 42 | Icon 43 | 44 | # Thumbnails 45 | ._* 46 | 47 | # Files that might appear on external disk 48 | .Spotlight-V100 49 | .Trashes 50 | 51 | # Directories potentially created on remote AFP share 52 | .AppleDB 53 | .AppleDesktop 54 | Network Trash Folder 55 | Temporary Items 56 | .apdisk 57 | 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Karan Goel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: node app.js 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **SEE https://github.com/karan/slack-news INSTEAD** 2 | 3 | slack-hn 4 | ======== 5 | 6 | Read Hacker News right from Slack just typing `/hn`. 7 | 8 | ![](http://i.imgur.com/kpdF7SR.gif) 9 | 10 | ## Usage 11 | 12 | From any Slack channel, just type `/hn`. The posts will be shown on the same channel. 13 | 14 | ## Installation 15 | 16 | - Go to your channel 17 | - Click on **Configure Integrations**. 18 | - Scroll all the way down to **DIY Integrations & Customizations** section. 19 | 20 | #### Add a new slash command with the following settings: 21 | 22 | - Click on **Add** next to **Slash Commands**. 23 | 24 | - Command: `/hn` 25 | - URL: `http://slack-hn.herokuapp.com/hn` 26 | - Method: `GET` 27 | 28 | ![](http://i.imgur.com/vNL3MCk.png) 29 | 30 | All other settings can be set on your own discretion. 31 | 32 | #### Set up a new incoming webhook 33 | 34 | - Click on **Add** next to **Incoming WebHooks**. 35 | 36 | - Choose a channel to integrate with (this doesn't matter -- it'll always respond to the channel you called it from) 37 | - Note the new Webhook URL. 38 | 39 | ![](http://i.imgur.com/JRJ92xj.png) 40 | 41 | - Set a new environment variable called `SLACK_WEBHOOK_URL`. 42 | 43 | ```bash 44 | # Unux systems (AWS etc) 45 | $ export SLACK_WEBHOOK_URL= 46 | 47 | # Heroku 48 | $ heroku config:set SLACK_WEBHOOK_URL= 49 | ``` 50 | 51 | #### (Optional) Setup your own server 52 | 53 | Although the code is hosted at `http://slack-hn.herokuapp.com/`, you are free to setup your own instance. 54 | 55 | Make sure to change the **Slash Command** URL to whatever your URL is. 56 | 57 | ##### Heroku 58 | 59 | [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/karan/slack-hn/tree/master) 60 | 61 | And then: 62 | 63 | ```bash 64 | $ heroku config:set SLACK_WEBHOOK_URL= 65 | ``` 66 | 67 | ##### Other servers 68 | 69 | ```bash 70 | $ git clone git@github.com:karan/slack-hn.git 71 | $ cd slack-hn 72 | $ npm install 73 | $ export SLACK_WEBHOOK_URL= 74 | $ node app.js 75 | ``` 76 | 77 | ## Contributing 78 | 79 | - Please use the [issue tracker]() to report any bugs or file feature requests. 80 | 81 | - PRs are welcome. 82 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var bodyParser = require('body-parser'); 3 | var hnbot = require('./hnbot'); 4 | 5 | var app = express(); 6 | var port = process.env.PORT || 3000; 7 | 8 | // body parser middleware 9 | app.use(bodyParser.urlencoded({ extended: true })); 10 | 11 | // test route 12 | app.get('/', function (req, res) { res.status(200).send('Hello world!') }); 13 | 14 | app.get('/hn', hnbot); 15 | 16 | // error handler 17 | app.use(function (err, req, res, next) { 18 | console.error(err.stack); 19 | res.status(400).send(err.message); 20 | }); 21 | 22 | app.listen(port, function () { 23 | console.log('Slack HN bot listening on port ' + port); 24 | }); 25 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "slack-hn", 3 | "description": "Read Hacker News right from Slack.", 4 | "repository": "https://github.com/karan/slack-hn", 5 | "keywords": ["node", "express", "slack", "hackernews"] 6 | } 7 | -------------------------------------------------------------------------------- /hnbot.js: -------------------------------------------------------------------------------- 1 | var request = require('request'); 2 | var async = require('async'); 3 | var https = require('https'); 4 | 5 | var WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL; 6 | 7 | module.exports = function (req, res, next) { 8 | 9 | request('http://node-hnapi.herokuapp.com/news', function(err, response, items) { 10 | if (err || response.statusCode != 200) { 11 | return res.status(500).end(); 12 | } 13 | 14 | items = JSON.parse(items); 15 | 16 | var botPayload = 'Current Hacker News homepage:\n' 17 | 18 | var index = 0; 19 | async.forEach(items, function(item, cb) { 20 | botPayload += '<%url%|%rank%. %title%>\n' 21 | .replace('%url%', item.url) 22 | .replace('%rank%', index + 1) 23 | .replace('%title%', item.title); 24 | index++; 25 | cb(); 26 | }, function(err) { 27 | 28 | var payload = { 29 | text: botPayload, 30 | username: 'HackerNews', 31 | channel: req.query.channel_id 32 | }; 33 | 34 | request.post({ 35 | url: WEBHOOK_URL, 36 | body: JSON.stringify(payload) 37 | 38 | }, function(err, resp, data) { 39 | if (err) { 40 | return res.status(500).end(); 41 | } 42 | }); 43 | }); 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "slack-hn", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "async": "^0.9.0", 10 | "body-parser": "~1.8.1", 11 | "express": "~4.9.0", 12 | "request": "^2.53.0" 13 | } 14 | } 15 | --------------------------------------------------------------------------------