|
@@ -155,24 +155,31 @@ class SlackBotService extends S2sMessageHandlable {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Submit action in create Modal
|
|
// Submit action in create Modal
|
|
|
- async createPageInGrowi(client, payload) {
|
|
|
|
|
|
|
+ async createPage(client, payload, contentsBody) {
|
|
|
const Page = this.crowi.model('Page');
|
|
const Page = this.crowi.model('Page');
|
|
|
const pathUtils = require('growi-commons').pathUtils;
|
|
const pathUtils = require('growi-commons').pathUtils;
|
|
|
- const contentsBody = reshapeContentsBody(payload.view.state.values.contents.contents_input.value);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const reshapedContentsBody = reshapeContentsBody(contentsBody);
|
|
|
|
|
+ let path = '';
|
|
|
|
|
+ let channelId = '';
|
|
|
try {
|
|
try {
|
|
|
- let path = payload.view.state.values.path.path_input.value;
|
|
|
|
|
|
|
+ if (payload.type === 'block_actions' && payload.actions[0].action_id === 'togetterCreatePage') {
|
|
|
|
|
+ path = payload.state.values.page_path.page_path.value;
|
|
|
|
|
+ channelId = payload.channel.id;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ path = payload.view.state.values.path.path_input.value;
|
|
|
|
|
+ channelId = JSON.parse(payload.view.private_metadata).channelId;
|
|
|
|
|
+ }
|
|
|
// sanitize path
|
|
// sanitize path
|
|
|
path = this.crowi.xss.process(path);
|
|
path = this.crowi.xss.process(path);
|
|
|
path = pathUtils.normalizePath(path);
|
|
path = pathUtils.normalizePath(path);
|
|
|
|
|
|
|
|
// generate a dummy id because Operation to create a page needs ObjectId
|
|
// generate a dummy id because Operation to create a page needs ObjectId
|
|
|
const dummyObjectIdOfUser = new mongoose.Types.ObjectId();
|
|
const dummyObjectIdOfUser = new mongoose.Types.ObjectId();
|
|
|
- const page = await Page.create(path, contentsBody, dummyObjectIdOfUser, {});
|
|
|
|
|
|
|
+ const page = await Page.create(path, reshapedContentsBody, dummyObjectIdOfUser, {});
|
|
|
|
|
|
|
|
// Send a message when page creation is complete
|
|
// Send a message when page creation is complete
|
|
|
const growiUri = this.crowi.appService.getSiteUrl();
|
|
const growiUri = this.crowi.appService.getSiteUrl();
|
|
|
- const channelId = JSON.parse(payload.view.private_metadata).channelId;
|
|
|
|
|
await client.chat.postEphemeral({
|
|
await client.chat.postEphemeral({
|
|
|
channel: channelId,
|
|
channel: channelId,
|
|
|
user: payload.user.id,
|
|
user: payload.user.id,
|
|
@@ -183,13 +190,34 @@ class SlackBotService extends S2sMessageHandlable {
|
|
|
client.chat.postMessage({
|
|
client.chat.postMessage({
|
|
|
channel: payload.user.id,
|
|
channel: payload.user.id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- markdownSectionBlock(`Cannot create new page to existed path\n *Contents* :memo:\n ${contentsBody}`)],
|
|
|
|
|
|
|
+ markdownSectionBlock(`Cannot create new page to existed path\n *Contents* :memo:\n ${reshapedContentsBody}`)],
|
|
|
});
|
|
});
|
|
|
logger.error('Failed to create page in GROWI.');
|
|
logger.error('Failed to create page in GROWI.');
|
|
|
throw err;
|
|
throw err;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async createPageInGrowi(client, payload) {
|
|
|
|
|
+ const contentsBody = payload.view.state.values.contents.contents_input.value;
|
|
|
|
|
+ await this.createPage(client, payload, contentsBody);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async togetterCreatePageInGrowi(client, payload) {
|
|
|
|
|
+ const { response_url: responseUrl } = payload;
|
|
|
|
|
+ const selectedOptions = payload.state.values.selected_messages.checkboxes_changed.selected_options;
|
|
|
|
|
+ const messages = selectedOptions.map((option) => {
|
|
|
|
|
+ const header = option.text.text.concat('\n');
|
|
|
|
|
+ const body = option.description.text.concat('\n');
|
|
|
|
|
+ return header.concat(body);
|
|
|
|
|
+ });
|
|
|
|
|
+ const contentsBody = messages.join('');
|
|
|
|
|
+ // dismiss
|
|
|
|
|
+ axios.post(responseUrl, {
|
|
|
|
|
+ delete_original: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await this.createPage(client, payload, contentsBody);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = SlackBotService;
|
|
module.exports = SlackBotService;
|