diff --git a/server/api/hooks.js b/server/api/hooks.js index f89cfad6..2c8726d8 100644 --- a/server/api/hooks.js +++ b/server/api/hooks.js @@ -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`. \nYou’ve 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 couldn’t find your user on this team in Outline.', + response_type: 'ephemeral', + text: 'Sorry, we couldn’t find your user – have you signed into Outline?', }; return; } diff --git a/server/api/hooks.test.js b/server/api/hooks.test.js index a38f65ec..d79a39ed 100644 --- a/server/api/hooks.test.js +++ b/server/api/hooks.test.js @@ -128,6 +128,34 @@ describe('#hooks.slack', async () => { ); }); + it('should respond with help content for help keyword', async () => { + const user = await buildUser(); + const res = await server.post('/api/hooks.slack', { + body: { + token: process.env.SLACK_VERIFICATION_TOKEN, + user_id: user.serviceId, + text: 'help', + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.text.includes('How to use')).toEqual(true); + }); + + it('should respond with help content for no keyword', async () => { + const user = await buildUser(); + const res = await server.post('/api/hooks.slack', { + body: { + token: process.env.SLACK_VERIFICATION_TOKEN, + user_id: user.serviceId, + text: '', + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.text.includes('How to use')).toEqual(true); + }); + it('should respond with error if unknown user', async () => { const res = await server.post('/api/hooks.slack', { body: {