|
@@ -87,29 +87,12 @@ class SlackBotService extends S2sMessageHandlable {
|
|
|
user: body.user_id,
|
|
user: body.user_id,
|
|
|
text: 'No command',
|
|
text: 'No command',
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- B.generateMarkdownSectionBlock('*No command.*\n Hint\n `/growi [command] [keyword]`'),
|
|
|
|
|
|
|
+ B.markdownSectionBlock('*No command.*\n Hint\n `/growi [command] [keyword]`'),
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async togetterCommand(client, body, args, limit = 10) {
|
|
|
|
|
- // TODO GW-6721 Get the time from args
|
|
|
|
|
- const reusult = await client.conversations.history({
|
|
|
|
|
- channel: body.channel_id,
|
|
|
|
|
- limit,
|
|
|
|
|
- });
|
|
|
|
|
- console.log(reusult);
|
|
|
|
|
- // Checkbox Message を返す
|
|
|
|
|
- client.chat.postEphemeral({
|
|
|
|
|
- channel: body.channel_id,
|
|
|
|
|
- user: body.user_id,
|
|
|
|
|
- text: 'Select messages to use.',
|
|
|
|
|
- blocks: this.togetterMessageBlocks(),
|
|
|
|
|
- });
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
generatePageLinkMrkdwn(pathname, href) {
|
|
generatePageLinkMrkdwn(pathname, href) {
|
|
|
return `<${decodeURI(href)} | ${decodeURI(pathname)}>`;
|
|
return `<${decodeURI(href)} | ${decodeURI(pathname)}>`;
|
|
|
}
|
|
}
|
|
@@ -149,7 +132,7 @@ class SlackBotService extends S2sMessageHandlable {
|
|
|
channel: channelId,
|
|
channel: channelId,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
{ type: 'divider' },
|
|
{ type: 'divider' },
|
|
|
- B.generateMarkdownSectionBlock(`${this.appendSpeechBaloon(`*${this.generatePageLinkMrkdwn(pathname, href)}*`, commentCount)}`),
|
|
|
|
|
|
|
+ B.markdownSectionBlock(`${this.appendSpeechBaloon(`*${this.generatePageLinkMrkdwn(pathname, href)}*`, commentCount)}`),
|
|
|
{
|
|
{
|
|
|
type: 'context',
|
|
type: 'context',
|
|
|
elements: [
|
|
elements: [
|
|
@@ -200,151 +183,13 @@ class SlackBotService extends S2sMessageHandlable {
|
|
|
client.chat.postMessage({
|
|
client.chat.postMessage({
|
|
|
channel: payload.user.id,
|
|
channel: payload.user.id,
|
|
|
blocks: [
|
|
blocks: [
|
|
|
- B.generateMarkdownSectionBlock(`Cannot create new page to existed path\n *Contents* :memo:\n ${contentsBody}`)],
|
|
|
|
|
|
|
+ B.markdownSectionBlock(`Cannot create new page to existed path\n *Contents* :memo:\n ${contentsBody}`)],
|
|
|
});
|
|
});
|
|
|
logger.error('Failed to create page in GROWI.');
|
|
logger.error('Failed to create page in GROWI.');
|
|
|
throw err;
|
|
throw err;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- generateMarkdownSectionBlock(text) {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'section',
|
|
|
|
|
- text: {
|
|
|
|
|
- type: 'mrkdwn',
|
|
|
|
|
- text,
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- divider() {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'divider',
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- generateInputSectionBlock(blockId, labelText, actionId, isMultiline, placeholder) {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'input',
|
|
|
|
|
- block_id: blockId,
|
|
|
|
|
- label: {
|
|
|
|
|
- type: 'plain_text',
|
|
|
|
|
- text: labelText,
|
|
|
|
|
- },
|
|
|
|
|
- element: {
|
|
|
|
|
- type: 'plain_text_input',
|
|
|
|
|
- action_id: actionId,
|
|
|
|
|
- multiline: isMultiline,
|
|
|
|
|
- placeholder: {
|
|
|
|
|
- type: 'plain_text',
|
|
|
|
|
- text: placeholder,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- togetterMessageBlocks() {
|
|
|
|
|
- return [
|
|
|
|
|
- this.inputBlock(this.togetterCheckboxesElement(), 'selected_messages', 'Select massages to use.'),
|
|
|
|
|
- this.actionsBlock(this.buttonElement('Show more', 'togetterShowMore')),
|
|
|
|
|
- this.inputBlock(this.togetterInputBlockElement('page_path', '/'), 'page_path', 'Page path'),
|
|
|
|
|
- this.actionsBlock(this.buttonElement('Cancel', 'togetterCancelPageCreation'), this.buttonElement('Create page', 'togetterCreatePage', 'primary')),
|
|
|
|
|
- ];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- actionsBlock(...elements) {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'actions',
|
|
|
|
|
- elements: [
|
|
|
|
|
- ...elements,
|
|
|
|
|
- ],
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- inputBlock(element, blockId, labelText) {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'input',
|
|
|
|
|
- block_id: blockId,
|
|
|
|
|
- element,
|
|
|
|
|
- label: {
|
|
|
|
|
- type: 'plain_text',
|
|
|
|
|
- text: labelText,
|
|
|
|
|
- emoji: true,
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Button element
|
|
|
|
|
- * https://api.slack.com/reference/block-kit/block-elements#button
|
|
|
|
|
- */
|
|
|
|
|
- buttonElement(text, actionId, style = undefined) {
|
|
|
|
|
- const button = {
|
|
|
|
|
- type: 'button',
|
|
|
|
|
- text: {
|
|
|
|
|
- type: 'plain_text',
|
|
|
|
|
- text,
|
|
|
|
|
- },
|
|
|
|
|
- action_id: actionId,
|
|
|
|
|
- };
|
|
|
|
|
- if (style === 'primary' || style === 'danger') {
|
|
|
|
|
- button.style = style;
|
|
|
|
|
- }
|
|
|
|
|
- return button;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- togetterCheckboxesElement() {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'checkboxes',
|
|
|
|
|
- options: this.togetterCheckboxesElementOptions(),
|
|
|
|
|
- action_id: 'checkboxes_changed',
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- togetterCheckboxesElementOptions() {
|
|
|
|
|
- // options を conversations.history の結果でインクリメント
|
|
|
|
|
- const options = [];
|
|
|
|
|
- // 仮置き
|
|
|
|
|
- for (let i = 0; i < 10; i++) {
|
|
|
|
|
- const option = this.checkboxesElementOption('*username* 12:00PM', 'sample slack messages ... :star:', `selected-${i}`);
|
|
|
|
|
- options.push(option);
|
|
|
|
|
- }
|
|
|
|
|
- return options;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Option object
|
|
|
|
|
- * https://api.slack.com/reference/block-kit/composition-objects#option
|
|
|
|
|
- */
|
|
|
|
|
- checkboxesElementOption(text, description, value) {
|
|
|
|
|
- return {
|
|
|
|
|
- text: {
|
|
|
|
|
- type: 'mrkdwn',
|
|
|
|
|
- text,
|
|
|
|
|
- },
|
|
|
|
|
- description: {
|
|
|
|
|
- type: 'mrkdwn',
|
|
|
|
|
- text: description,
|
|
|
|
|
- },
|
|
|
|
|
- value,
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Plain-text input element
|
|
|
|
|
- * https://api.slack.com/reference/block-kit/block-elements#input
|
|
|
|
|
- */
|
|
|
|
|
- togetterInputBlockElement(actionId, placeholderText = 'Write something ...') {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'plain_text_input',
|
|
|
|
|
- placeholder: {
|
|
|
|
|
- type: 'plain_text',
|
|
|
|
|
- text: placeholderText,
|
|
|
|
|
- },
|
|
|
|
|
- action_id: actionId,
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = SlackBotService;
|
|
module.exports = SlackBotService;
|