Merge pull request #431 from outline/jori/slack-no-results

Added no results text for Slack slash command
This commit is contained in:
Jori Lallo 2017-11-22 12:11:54 -08:00 committed by GitHub
commit 8b2f6f193f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 17 deletions

View File

@ -26,24 +26,30 @@ router.post('hooks.slack', async ctx => {
limit: 5,
});
const results = [];
let number = 1;
for (const document of documents) {
results.push(
`${number}. <${process.env.URL}${document.getUrl()}|${document.title}>`
);
number += 1;
}
if (documents) {
const results = [];
let number = 1;
for (const document of documents) {
results.push(
`${number}. <${process.env.URL}${document.getUrl()}|${document.title}>`
);
number += 1;
}
ctx.body = {
text: 'Search results:',
attachments: [
{
text: results.join('\n'),
color: '#3AA3E3',
},
],
};
ctx.body = {
text: 'Search results:',
attachments: [
{
text: results.join('\n'),
color: '#3AA3E3',
},
],
};
} else {
ctx.body = {
text: 'No search results',
};
}
});
export default router;