mirror of
https://github.com/Dannecron/hello-slack-bot.git
synced 2025-12-26 00:22:35 +03:00
hello bot
This commit is contained in:
24
app.js
24
app.js
@@ -0,0 +1,24 @@
|
|||||||
|
var express = require('express');
|
||||||
|
var bodyParser = require('body-parser');
|
||||||
|
var zmrBot = require('./bot.js');
|
||||||
|
|
||||||
|
var app = express();
|
||||||
|
var port = process.env.PORT || 3000;
|
||||||
|
|
||||||
|
// body parser middleware
|
||||||
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
// test route
|
||||||
|
app.get('/', function (req, res) { res.status(200).send('Hello world!') });
|
||||||
|
|
||||||
|
app.post('/hello', zmrBot);
|
||||||
|
|
||||||
|
// error handler
|
||||||
|
app.use(function (err, req, res, next) {
|
||||||
|
console.error(err.stack);
|
||||||
|
res.status(400).send(err.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(port, function () {
|
||||||
|
console.log('Slack bot listening on port ' + port);
|
||||||
|
});
|
||||||
13
bot.js
Normal file
13
bot.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = function (req, res, next) {
|
||||||
|
var userName = req.body.user_name;
|
||||||
|
var botPayload = {
|
||||||
|
text : 'Hello, ' + userName + '!'
|
||||||
|
};
|
||||||
|
|
||||||
|
// avoid infinite loop
|
||||||
|
if (userName !== 'slackbot') {
|
||||||
|
return res.status(200).json(botPayload);
|
||||||
|
} else {
|
||||||
|
return res.status(200).end();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "zmr_slackbot",
|
"name": "zmr_slackbot",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "zaymer slackbot",
|
"description": "zaymer slackbot",
|
||||||
"main": "bot.js",
|
"main": "app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user