Created
February 18, 2018 13:30
-
-
Save heyellieday/840b6d78c4124752e4502d8cb900d72f to your computer and use it in GitHub Desktop.
Slack Notifications with if-eth + express
This file contains 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 express = require('express'); | |
const bodyParser = require('body-parser'); | |
const request = require('request'); | |
const app = express(); | |
console.log(process.env.SLACKBOT_URI); | |
app.use(bodyParser.json()); | |
app.post('/webhook', (req, res) => { | |
console.log('A kitty is up for auction!', req.body); | |
res.sendStatus(200); | |
// notify slackbot | |
const payload = { | |
username: 'CryptoKittyWatcher', | |
icon_url: 'https://if-eth.com/hero.png', | |
text: `A kitty is up for auction! <https://etherscan.io/tx/${req.body.log.transactionHash}|See it on etherscan.>` | |
}; | |
request({ | |
method: 'POST', | |
uri: process.env.SLACKBOT_URI, | |
body: payload, | |
json: true | |
}, (err, res) => { | |
if (err) console.warn('Failed to hit slackbot', err); | |
}); | |
}); | |
const port = process.env.PORT || 80; | |
app.listen(port, () => console.log(`Listening on port ${port}`)); |
This file contains 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
{ | |
"name": "kitty-slackbot", | |
"version": "1.0.0", | |
"description": "Ping a slack channel every time a CryptoKitty goes up for auction", | |
"main": "index.js", | |
"scripts": { | |
"start": "node index.js" | |
}, | |
"author": "hello@if-eth.com", | |
"license": "MIT", | |
"dependencies": { | |
"body-parser": "^1.18.2", | |
"express": "^4.16.2", | |
"request": "^2.83.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment