|
@@ -114,6 +114,11 @@ class BoltService {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ this.bolt.view('createPage', async({ ack, view }) => {
|
|
|
|
|
+ await ack();
|
|
|
|
|
+ return this.createPageInGrowi(view);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
this.bolt.action('button_click', async({ body, ack, say }) => {
|
|
this.bolt.action('button_click', async({ body, ack, say }) => {
|
|
|
await ack();
|
|
await ack();
|
|
|
await say('clicked the button');
|
|
await say('clicked the button');
|
|
@@ -127,7 +132,7 @@ class BoltService {
|
|
|
channel: command.channel_id,
|
|
channel: command.channel_id,
|
|
|
user: command.user_id,
|
|
user: command.user_id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock('*コマンドが存在しません。*\n Hint\n `/growi [command] [keyword]`'),
|
|
|
|
|
|
|
+ this.generateMarkdownSectionBlock('*No command.*\n Hint\n `/growi [command] [keyword]`'),
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -140,7 +145,7 @@ class BoltService {
|
|
|
channel: command.channel_id,
|
|
channel: command.channel_id,
|
|
|
user: command.user_id,
|
|
user: command.user_id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock('*キーワードを入力してください。*\n Hint\n `/growi search [keyword]`'),
|
|
|
|
|
|
|
+ this.generateMarkdownSectionBlock('*Input keywords.*\n Hint\n `/growi search [keyword]`'),
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -158,7 +163,7 @@ class BoltService {
|
|
|
channel: command.channel_id,
|
|
channel: command.channel_id,
|
|
|
user: command.user_id,
|
|
user: command.user_id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock('*キーワードに該当するページは存在しません。*'),
|
|
|
|
|
|
|
+ this.generateMarkdownSectionBlock('*No page that match your keywords.*'),
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -172,7 +177,7 @@ class BoltService {
|
|
|
channel: command.channel_id,
|
|
channel: command.channel_id,
|
|
|
user: command.user_id,
|
|
user: command.user_id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock('検索結果 10 件'),
|
|
|
|
|
|
|
+ this.generateMarkdownSectionBlock('10 results.'),
|
|
|
this.generateMarkdownSectionBlock(`${resultPaths.join('\n')}`),
|
|
this.generateMarkdownSectionBlock(`${resultPaths.join('\n')}`),
|
|
|
{
|
|
{
|
|
|
type: 'actions',
|
|
type: 'actions',
|
|
@@ -181,7 +186,7 @@ class BoltService {
|
|
|
type: 'button',
|
|
type: 'button',
|
|
|
text: {
|
|
text: {
|
|
|
type: 'plain_text',
|
|
type: 'plain_text',
|
|
|
- text: '検索結果をこのチャンネルに共有する',
|
|
|
|
|
|
|
+ text: 'Share the results in this channel.',
|
|
|
},
|
|
},
|
|
|
style: 'primary',
|
|
style: 'primary',
|
|
|
action_id: 'button_click',
|
|
action_id: 'button_click',
|
|
@@ -197,14 +202,23 @@ class BoltService {
|
|
|
channel: command.channel_id,
|
|
channel: command.channel_id,
|
|
|
user: command.user_id,
|
|
user: command.user_id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock('*検索に失敗しました。*\n Hint\n `/growi search [keyword]`'),
|
|
|
|
|
|
|
+ this.generateMarkdownSectionBlock('*Failed to search.*\n Hint\n `/growi search [keyword]`'),
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async createModal(command, client, body) {
|
|
async createModal(command, client, body) {
|
|
|
|
|
+ const User = this.crowi.model('User');
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
|
|
+ const slackUser = await User.findUserByUsername('slackUser');
|
|
|
|
|
+
|
|
|
|
|
+ // if "slackUser" is null, don't show create Modal
|
|
|
|
|
+ if (slackUser == null) {
|
|
|
|
|
+ throw new Error('userNull');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
await client.views.open({
|
|
await client.views.open({
|
|
|
trigger_id: body.trigger_id,
|
|
trigger_id: body.trigger_id,
|
|
|
|
|
|
|
@@ -224,25 +238,60 @@ class BoltService {
|
|
|
text: 'Cancel',
|
|
text: 'Cancel',
|
|
|
},
|
|
},
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock('ページを作成します'),
|
|
|
|
|
|
|
+ this.generateMarkdownSectionBlock('Create new page.'),
|
|
|
this.generateInputSectionBlock('path', 'Path', 'path_input', false, '/path'),
|
|
this.generateInputSectionBlock('path', 'Path', 'path_input', false, '/path'),
|
|
|
this.generateInputSectionBlock('contents', 'Contents', 'contents_input', true, 'Input with Markdown...'),
|
|
this.generateInputSectionBlock('contents', 'Contents', 'contents_input', true, 'Input with Markdown...'),
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- catch {
|
|
|
|
|
|
|
+ catch (e) {
|
|
|
|
|
+ if (e instanceof Error) {
|
|
|
|
|
+ return this.client.chat.postEphemeral({
|
|
|
|
|
+ channel: command.channel_id,
|
|
|
|
|
+ user: command.user_id,
|
|
|
|
|
+ blocks: [
|
|
|
|
|
+ this.generateMarkdownSectionBlock('*slackUser does not exist.*'),
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
logger.error('Failed to create page.');
|
|
logger.error('Failed to create page.');
|
|
|
await this.client.chat.postEphemeral({
|
|
await this.client.chat.postEphemeral({
|
|
|
channel: command.channel_id,
|
|
channel: command.channel_id,
|
|
|
user: command.user_id,
|
|
user: command.user_id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock('*ページ作成に失敗しました。*\n Hint\n `/growi create`'),
|
|
|
|
|
|
|
+ this.generateMarkdownSectionBlock('*Failed to create new page.*\n Hint\n `/growi create`'),
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Submit action in create Modal
|
|
|
|
|
+ async createPageInGrowi(view) {
|
|
|
|
|
+ const User = this.crowi.model('User');
|
|
|
|
|
+ const Page = this.crowi.model('Page');
|
|
|
|
|
+ const pathUtils = require('growi-commons').pathUtils;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // search "slackUser" to create page in slack
|
|
|
|
|
+ const slackUser = await User.findUserByUsername('slackUser');
|
|
|
|
|
+
|
|
|
|
|
+ let path = view.state.values.path.path_input.value;
|
|
|
|
|
+ const body = view.state.values.contents.contents_input.value;
|
|
|
|
|
+
|
|
|
|
|
+ // sanitize path
|
|
|
|
|
+ path = this.crowi.xss.process(path);
|
|
|
|
|
+ path = pathUtils.normalizePath(path);
|
|
|
|
|
+
|
|
|
|
|
+ const user = slackUser._id;
|
|
|
|
|
+ return Page.create(path, body, user, {});
|
|
|
|
|
+ }
|
|
|
|
|
+ catch {
|
|
|
|
|
+ logger.error('Failed to create page in GROWI.');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
generateMarkdownSectionBlock(blocks) {
|
|
generateMarkdownSectionBlock(blocks) {
|
|
|
return {
|
|
return {
|
|
|
type: 'section',
|
|
type: 'section',
|