diff --git a/src/index.js b/src/index.js index 1f85168..34162ad 100644 --- a/src/index.js +++ b/src/index.js @@ -68,7 +68,10 @@ app.post('/', async (req, res, next) => { // slash command if (req.body.command) { - const channel = req.body.channel_id; + const { + channel_id, + text + } = req.body; res.sendStatus(200); @@ -76,6 +79,15 @@ app.post('/', async (req, res, next) => { 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 = { method: 'POST', headers: { @@ -83,8 +95,8 @@ app.post('/', async (req, res, next) => { 'Authorization': `Bearer ${process.env.BOTACCESSTOKEN}`, }, body: JSON.stringify({ - channel: channel, - text: theStrategy, + channel: channel_id, + text: responseText, }), };