|
|
@@ -3,11 +3,10 @@ const {
|
|
|
} = require('@growi/slack');
|
|
|
const { parse, format } = require('date-fns');
|
|
|
const axios = require('axios');
|
|
|
-const logger = require('@alias/logger')('growi:service:SlackBotService');
|
|
|
-const mongoose = require('mongoose');
|
|
|
-const { reshapeContentsBody } = require('@growi/slack');
|
|
|
+const logger = require('@alias/logger')('growi:service:SlackBotService:togetter');
|
|
|
|
|
|
module.exports = (crowi) => {
|
|
|
+ const createPageInGrowi = require('../../util/createPageInGrowi')(crowi);
|
|
|
const BaseSlackCommandHandler = require('./slack-command-handler');
|
|
|
const handler = new BaseSlackCommandHandler();
|
|
|
|
|
|
@@ -54,6 +53,8 @@ module.exports = (crowi) => {
|
|
|
await this.togetterCreatePageAndSendPreview(client, payload, path, channel, contentsBody);
|
|
|
}
|
|
|
catch (err) {
|
|
|
+ logger.error(err);
|
|
|
+ // upcoming GW-6853 will change: just throw Error() here and handle in slackbot.js
|
|
|
await client.chat.postMessage({
|
|
|
channel: payload.user.id,
|
|
|
text: err.message,
|
|
|
@@ -143,7 +144,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
handler.togetterCreatePageAndSendPreview = async function(client, payload, path, channel, contentsBody) {
|
|
|
try {
|
|
|
- await this.MUSTMOVETOUTILcreatePage(client, payload, path, channel, contentsBody);
|
|
|
+ await createPageInGrowi(client, payload, path, channel, contentsBody);
|
|
|
// send preview to dm
|
|
|
await client.chat.postMessage({
|
|
|
channel: payload.user.id,
|
|
|
@@ -166,38 +167,6 @@ module.exports = (crowi) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- handler.MUSTMOVETOUTILcreatePage = async function(client, payload, path, channelId, contentsBody) {
|
|
|
- const Page = crowi.model('Page');
|
|
|
- const pathUtils = require('growi-commons').pathUtils;
|
|
|
- const reshapedContentsBody = reshapeContentsBody(contentsBody);
|
|
|
- try {
|
|
|
- // sanitize path
|
|
|
- const sanitizedPath = crowi.xss.process(path);
|
|
|
- const normalizedPath = pathUtils.normalizePath(sanitizedPath);
|
|
|
-
|
|
|
- // generate a dummy id because Operation to create a page needs ObjectId
|
|
|
- const dummyObjectIdOfUser = new mongoose.Types.ObjectId();
|
|
|
- const page = await Page.create(normalizedPath, reshapedContentsBody, dummyObjectIdOfUser, {});
|
|
|
-
|
|
|
- // Send a message when page creation is complete
|
|
|
- const growiUri = crowi.appService.getSiteUrl();
|
|
|
- await client.chat.postEphemeral({
|
|
|
- channel: channelId,
|
|
|
- user: payload.user.id,
|
|
|
- text: `The page <${decodeURI(`${growiUri}/${page._id} | ${decodeURI(growiUri + normalizedPath)}`)}> has been created.`,
|
|
|
- });
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- client.chat.postMessage({
|
|
|
- channel: payload.user.id,
|
|
|
- blocks: [
|
|
|
- markdownSectionBlock(`Cannot create new page to existed path\n *Contents* :memo:\n ${reshapedContentsBody}`)],
|
|
|
- });
|
|
|
- logger.error('Failed to create page in GROWI.');
|
|
|
- throw err;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
handler.togetterMessageBlocks = function(messages, body, args, limit) {
|
|
|
return [
|
|
|
markdownSectionBlock('Select the oldest and latest datetime of the messages to use.'),
|