Start a POST response to Slack mentions.
This commit is contained in:
parent
36d86168de
commit
b66d75dac3
65
index.js
65
index.js
@ -1,25 +1,70 @@
|
||||
const express = require('express')
|
||||
const app = express();
|
||||
const https = require('https');
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
const strategies = require('./strategies');
|
||||
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
const theStrategy = strategies[ Math.floor(Math.random()*strategies.length) ];
|
||||
res.send(theStrategy);
|
||||
res.write('<head><meta name="viewport" content="width=device-width, initial-scale=1"></head><body style="background-color:#111; margin:0; padding:0; display:flex;align-items:center;justify-content:center;min-height:24em;"><div style="color:#eee;margin:0 auto; max-width:80%;flex:1;text-align:center;font-family:Futura;font-size:30px;line-height:40px">');
|
||||
res.write(theStrategy.toLowerCase());
|
||||
res.write('</div></body>');
|
||||
res.end();
|
||||
});
|
||||
|
||||
app.post('/', (req, res, next) => {
|
||||
let payload = req.body;
|
||||
res.sendStatus(200);
|
||||
|
||||
if (payload.event.type === 'app_mention') {
|
||||
// respond in kind
|
||||
if (req.body.type === 'url_verification') {
|
||||
return res.status(200).json(req.body.challenge);
|
||||
}
|
||||
|
||||
if (req.body.type ==='event_callback') {
|
||||
if (req.body.event.type === 'app_mention' && 1===2) {
|
||||
var theResponse = {
|
||||
hostname: 'slack.com',
|
||||
path: '/api/chat.postMessage?token='+botAccessToken,
|
||||
port: 443,
|
||||
method: 'POST',
|
||||
channel: 'CETLNV30Q',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
},
|
||||
text: 'Hihihi',
|
||||
channel: 'CETLNV30Q',
|
||||
}
|
||||
|
||||
var theMessage = {
|
||||
text: 'Hello I Am Bot',
|
||||
channel: 'CETLNV30Q',
|
||||
}
|
||||
|
||||
var theResponseRequest = https.request(theResponse, (theSlackResponse) => {
|
||||
console.log('statusCode: '+theSlackResponse.statusCode);
|
||||
console.log('headers: '+JSON.stringify(theSlackResponse.headers,null,2));
|
||||
|
||||
theSlackResponse.on('data', (d) => {
|
||||
process.stdout.write(d);
|
||||
});
|
||||
});
|
||||
|
||||
theResponseRequest.on('error', (e) => {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
theResponseRequest.write('hi123');
|
||||
|
||||
theResponseRequest.end();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return res.status(200).end();
|
||||
});
|
||||
|
||||
app.listen(4242, () => {
|
||||
console.log('oblique strategies are being served')
|
||||
});
|
||||
|
||||
|
||||
|
@ -7,8 +7,10 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Nicholas Warzin",
|
||||
"repository": "https://nickwarzin.com:4243/nicholas/oblique-strategies",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.18.3",
|
||||
"express": "^4.16.4"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user