2018-04-04 03:36:25 +00:00
|
|
|
// @flow
|
2019-01-06 08:05:50 +00:00
|
|
|
import { Document, Team } from '../models';
|
2018-04-04 03:36:25 +00:00
|
|
|
|
2019-02-20 06:42:13 +00:00
|
|
|
type Action = {
|
|
|
|
type: string,
|
|
|
|
text: string,
|
|
|
|
name: string,
|
|
|
|
value: string,
|
|
|
|
};
|
|
|
|
|
2019-04-18 02:11:23 +00:00
|
|
|
export default function present(
|
2019-02-20 06:42:13 +00:00
|
|
|
document: Document,
|
|
|
|
team: Team,
|
|
|
|
context?: string,
|
|
|
|
actions?: Action[]
|
|
|
|
) {
|
2018-08-05 07:34:08 +00:00
|
|
|
// the context contains <b> tags around search terms, we convert them here
|
|
|
|
// to the markdown format that slack expects to receive.
|
2018-08-05 07:51:47 +00:00
|
|
|
const text = context
|
2018-08-05 18:12:59 +00:00
|
|
|
? context.replace(/<\/?b>/g, '*').replace('\n', '')
|
2018-08-05 07:51:47 +00:00
|
|
|
: document.getSummary();
|
2018-08-05 07:34:08 +00:00
|
|
|
|
2018-04-04 03:36:25 +00:00
|
|
|
return {
|
|
|
|
color: document.collection.color,
|
|
|
|
title: document.title,
|
2019-01-06 08:05:50 +00:00
|
|
|
title_link: `${team.url}${document.url}`,
|
2018-04-04 03:36:25 +00:00
|
|
|
footer: document.collection.name,
|
2019-02-20 06:42:13 +00:00
|
|
|
callback_id: document.id,
|
2018-08-05 07:34:08 +00:00
|
|
|
text,
|
2018-04-04 03:36:25 +00:00
|
|
|
ts: document.getTimestamp(),
|
2019-02-20 06:42:13 +00:00
|
|
|
actions,
|
2018-04-04 03:36:25 +00:00
|
|
|
};
|
|
|
|
}
|