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('
');
res.write(theStrategy.toLowerCase());
res.write('
');
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')
});