Accept user queries and echo them back.
This commit is contained in:
parent
e4eb0cc544
commit
b61fee9da0
18
src/index.js
18
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,
|
||||
}),
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user