71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
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.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) => {
|
|
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')
|
|
});
|