Post to Slack (#603)

* Migrations

* WIP: Integration model, slack perms / hooks

* So so rough it pains me. Building this new model is revealing just how much needs to be refactored

* Working connect and post

* Cleanup UI, upating documents

* Show when slack command is connected

* stash

* 💚

* Add documents.update trigger

* Authorization, tidying

* Fixed integration policy

* pick integration presenter keys
This commit is contained in:
Tom Moor
2018-04-03 20:36:25 -07:00
committed by GitHub
parent 17900c6a11
commit 44cb509ebf
38 changed files with 665 additions and 105 deletions

22
server/services/index.js Normal file
View File

@@ -0,0 +1,22 @@
// @flow
import fs from 'fs-extra';
import path from 'path';
const services = {};
fs
.readdirSync(__dirname)
.filter(file => file.indexOf('.') !== 0 && file !== path.basename(__filename))
.forEach(name => {
const servicePath = path.join(__dirname, name);
// $FlowIssue
const pkg = require(path.join(servicePath, 'package.json'));
// $FlowIssue
const hooks = require(servicePath).default;
services[pkg.name] = {
...pkg,
...hooks,
};
});
export default services;

View File

@@ -0,0 +1,43 @@
// @flow
import type { Event } from '../../events';
import { Document, Integration } from '../../models';
import { presentSlackAttachment } from '../../presenters';
const Slack = {
on: async (event: Event) => {
if (event.name !== 'documents.publish' && event.name !== 'documents.update')
return;
const document = await Document.findById(event.model.id);
if (!document) return;
const integration = await Integration.findOne({
where: {
teamId: document.teamId,
serviceId: 'slack',
collectionId: document.atlasId,
type: 'post',
},
});
if (!integration) return;
let text = `${document.createdBy.name} published a new document`;
if (event.name === 'documents.update') {
text = `${document.createdBy.name} updated a document`;
}
await fetch(integration.settings.url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text,
attachments: [presentSlackAttachment(document)],
}),
});
},
};
export default Slack;

View File

@@ -0,0 +1,4 @@
{
"name": "slack",
"description": "Hook up your Slack to your Outline."
}