|
|
@@ -1,5 +1,5 @@
|
|
|
import { Inject, Service } from '@tsed/di';
|
|
|
-import { WebClient, LogLevel } from '@slack/web-api';
|
|
|
+import { WebClient, LogLevel, Block } from '@slack/web-api';
|
|
|
import { generateInputSectionBlock, GrowiCommand, generateMarkdownSectionBlock } from '@growi/slack';
|
|
|
import { AuthorizeResult } from '@slack/oauth';
|
|
|
import { GrowiCommandProcessor } from '~/interfaces/slack-to-growi/growi-command-processor';
|
|
|
@@ -48,6 +48,18 @@ export class RegisterService implements GrowiCommandProcessor {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async replyToSlack(client: WebClient, channel: string, user: string, text: string, blocks: Array<Block>): Promise<void> {
|
|
|
+ await client.chat.postEphemeral({
|
|
|
+ channel,
|
|
|
+ user,
|
|
|
+ // Recommended including 'text' to provide a fallback when using blocks
|
|
|
+ // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
|
|
|
+ text,
|
|
|
+ blocks,
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
async insertOrderRecord(
|
|
|
installation: Installation | undefined,
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
@@ -68,18 +80,10 @@ export class RegisterService implements GrowiCommandProcessor {
|
|
|
}
|
|
|
catch (error) {
|
|
|
const invalidErrorMsg = 'Please enter a valid URL';
|
|
|
-
|
|
|
- await client.chat.postEphemeral({
|
|
|
- channel,
|
|
|
- user: payload.user.id,
|
|
|
- // Recommended including 'text' to provide a fallback when using blocks
|
|
|
- // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
|
|
|
- text: 'Invalid URL',
|
|
|
- blocks: [
|
|
|
- generateMarkdownSectionBlock(invalidErrorMsg),
|
|
|
- ],
|
|
|
- });
|
|
|
-
|
|
|
+ const blocks = [
|
|
|
+ generateMarkdownSectionBlock(invalidErrorMsg),
|
|
|
+ ];
|
|
|
+ await this.replyToSlack(client, channel, payload.user.id, 'Invalid URL', blocks);
|
|
|
throw new InvalidUrlError(growiUrl);
|
|
|
}
|
|
|
|
|
|
@@ -88,18 +92,6 @@ export class RegisterService implements GrowiCommandProcessor {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- async replyToSlack(client: WebClient, channel: string, user: string, text: string, blocks: any): Promise<void> {
|
|
|
- await client.chat.postEphemeral({
|
|
|
- channel,
|
|
|
- user,
|
|
|
- // Recommended including 'text' to provide a fallback when using blocks
|
|
|
- // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
|
|
|
- text,
|
|
|
- blocks,
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
async notifyServerUriToSlack(
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
botToken: string | undefined, payload: any,
|
|
|
@@ -116,16 +108,6 @@ export class RegisterService implements GrowiCommandProcessor {
|
|
|
generateMarkdownSectionBlock('Successfully registered with the proxy! Please check test connection in your GROWI'),
|
|
|
];
|
|
|
await this.replyToSlack(client, channel, payload.user.id, 'Proxy URL', blocks);
|
|
|
- // await client.chat.postEphemeral({
|
|
|
- // channel,
|
|
|
- // user: payload.user.id,
|
|
|
- // // Recommended including 'text' to provide a fallback when using blocks
|
|
|
- // // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
|
|
|
- // text: 'Proxy URL',
|
|
|
- // blocks: [
|
|
|
- // generateMarkdownSectionBlock('Successfully registered with the proxy! Please check test connection in your GROWI'),
|
|
|
- // ],
|
|
|
- // });
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
@@ -135,19 +117,7 @@ export class RegisterService implements GrowiCommandProcessor {
|
|
|
generateMarkdownSectionBlock(`Proxy URL: ${serverUri}`),
|
|
|
];
|
|
|
await this.replyToSlack(client, channel, payload.user.id, 'Proxy URL', blocks);
|
|
|
-
|
|
|
- // await client.chat.postEphemeral({
|
|
|
- // channel,
|
|
|
- // user: payload.user.id,
|
|
|
- // // Recommended including 'text' to provide a fallback when using blocks
|
|
|
- // // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
|
|
|
- // text: 'Proxy URL',
|
|
|
- // blocks: [
|
|
|
- // generateMarkdownSectionBlock('Please enter and update the following Proxy URL to slack bot setting form in your GROWI'),
|
|
|
- // generateMarkdownSectionBlock(`Proxy URL: ${serverUri}`),
|
|
|
- // ],
|
|
|
- // });
|
|
|
- // return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
}
|