fix: add support for help slack command

This commit is contained in:
Tom Moor
2019-06-25 20:43:59 -07:00
parent 46ad1feb96
commit c9c5e43389
2 changed files with 47 additions and 3 deletions

View File

@ -96,10 +96,25 @@ router.post('hooks.slack', async ctx => {
const { token, user_id, text } = ctx.body;
ctx.assertPresent(token, 'token is required');
ctx.assertPresent(user_id, 'user_id is required');
ctx.assertPresent(text, 'text is required');
if (token !== process.env.SLACK_VERIFICATION_TOKEN)
if (token !== process.env.SLACK_VERIFICATION_TOKEN) {
throw new AuthenticationError('Invalid verification token');
}
// Handle "help" command or no input
if (text.trim() === 'help' || !text.trim()) {
ctx.body = {
response_type: 'ephemeral',
text: 'How to use /outline',
attachments: [
{
text:
'To search your knowledgebase use `/outline keyword`. \nYouve already learned how to get help with `/outline help`.',
},
],
};
return;
}
const user = await User.findOne({
where: {
@ -109,7 +124,8 @@ router.post('hooks.slack', async ctx => {
});
if (!user) {
ctx.body = {
text: 'Sorry, we couldnt find your user on this team in Outline.',
response_type: 'ephemeral',
text: 'Sorry, we couldnt find your user have you signed into Outline?',
};
return;
}