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:
22
server/services/index.js
Normal file
22
server/services/index.js
Normal 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;
|
||||
43
server/services/slack/index.js
Normal file
43
server/services/slack/index.js
Normal 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;
|
||||
4
server/services/slack/package.json
Normal file
4
server/services/slack/package.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "slack",
|
||||
"description": "Hook up your Slack to your Outline."
|
||||
}
|
||||
Reference in New Issue
Block a user