Accept user queries and echo them back.

This commit is contained in:
nicholas 2020-01-07 12:27:49 -05:00
parent e4eb0cc544
commit b61fee9da0

View File

@ -68,7 +68,10 @@ app.post('/', async (req, res, next) => {
// slash command // slash command
if (req.body.command) { if (req.body.command) {
const channel = req.body.channel_id; const {
channel_id,
text
} = req.body;
res.sendStatus(200); res.sendStatus(200);
@ -76,6 +79,15 @@ app.post('/', async (req, res, next) => {
const endpoint = 'https://slack.com/api/chat.postMessage'; const endpoint = 'https://slack.com/api/chat.postMessage';
const punct = /[?.!]/g;
const elision = (text || ' ').split('').pop().match(punct)
? ''
: '...';
const responseText = text === ''
? theStrategy
: `_${text}_${elision} ${theStrategy}`;
const payload = { const payload = {
method: 'POST', method: 'POST',
headers: { headers: {
@ -83,8 +95,8 @@ app.post('/', async (req, res, next) => {
'Authorization': `Bearer ${process.env.BOTACCESSTOKEN}`, 'Authorization': `Bearer ${process.env.BOTACCESSTOKEN}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
channel: channel, channel: channel_id,
text: theStrategy, text: responseText,
}), }),
}; };