diff --git a/server/api/hooks.js b/server/api/hooks.js index 218ea76e..46de6be5 100644 --- a/server/api/hooks.js +++ b/server/api/hooks.js @@ -71,13 +71,14 @@ router.post('hooks.slack', async ctx => { color: document.collection.color, title: document.title, title_link: `${process.env.URL}${document.getUrl()}`, + footer: document.collection.name, text: document.getSummary(), - ts: new Date(document.updatedAt).getTime(), + ts: document.getTimestamp(), }); } ctx.body = { - text: `This is what we found…`, + text: `This is what we found for "${text}"…`, attachments, }; } else { diff --git a/server/api/hooks.test.js b/server/api/hooks.test.js index 60cc8183..29c3053e 100644 --- a/server/api/hooks.test.js +++ b/server/api/hooks.test.js @@ -65,18 +65,20 @@ describe('#hooks.slack', async () => { }); it('should return search results', async () => { - const { user } = await seed(); + const { user, document, collection } = await seed(); const res = await server.post('/api/hooks.slack', { body: { token: process.env.SLACK_VERIFICATION_TOKEN, user_id: user.slackId, - text: 'Welcome', + text: document.title, }, }); const body = await res.json(); expect(res.status).toEqual(200); expect(body.attachments.length).toEqual(1); + expect(body.attachments[0].title).toEqual(document.title); + expect(body.attachments[0].footer).toEqual(collection.name); }); it('should error if unknown user', async () => { diff --git a/server/models/Document.js b/server/models/Document.js index 1d41f1ea..32270207 100644 --- a/server/models/Document.js +++ b/server/models/Document.js @@ -221,6 +221,10 @@ Document.addHook('afterUpdate', model => // Instance methods +Document.prototype.getTimestamp = function() { + return Math.round(new Date(this.updatedAt).getTime() / 1000); +}; + Document.prototype.getSummary = function() { const value = Markdown.deserialize(this.text); const plain = Plain.serialize(value);