@xpr/nestjs-slack 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decorators.d.ts +6 -9
- package/decorators.js +16 -15
- package/package.json +2 -1
- package/slack.d.ts +2 -2
- package/slack.js +3 -4
package/decorators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ActionConstraints, OptionsConstraints, ShortcutConstraints, ViewConstraints } from
|
|
2
|
-
import { type Pattern } from
|
|
1
|
+
import { ActionConstraints, OptionsConstraints, ShortcutConstraints, ViewConstraints } from '@slack/bolt';
|
|
2
|
+
import { type Pattern } from './utils';
|
|
3
3
|
export { Pattern };
|
|
4
4
|
/**
|
|
5
5
|
* @see https://tools.slack.dev/bolt-js/reference/
|
|
@@ -12,12 +12,15 @@ export declare const EventTypes: {
|
|
|
12
12
|
View: string;
|
|
13
13
|
Option: string;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Decorator for Slack controller
|
|
17
|
+
*/
|
|
18
|
+
export declare function SlackController(): ClassDecorator;
|
|
15
19
|
/**
|
|
16
20
|
* Decorator for event events
|
|
17
21
|
* @see guide https://tools.slack.dev/bolt-js/concepts/event-listening
|
|
18
22
|
* @see api https://api.slack.com/apis/events-api
|
|
19
23
|
* @param event
|
|
20
|
-
* @constructor
|
|
21
24
|
*/
|
|
22
25
|
export declare function SlackEvent(event: string): MethodDecorator;
|
|
23
26
|
export type ShortCutId = Pattern | ShortcutConstraints;
|
|
@@ -26,7 +29,6 @@ export type ShortCutId = Pattern | ShortcutConstraints;
|
|
|
26
29
|
* @see guide https://tools.slack.dev/bolt-js/concepts/shortcuts
|
|
27
30
|
* @see api https://api.slack.com/interactivity/shortcuts
|
|
28
31
|
* @param shortcutId
|
|
29
|
-
* @constructor
|
|
30
32
|
*/
|
|
31
33
|
export declare function SlackShortcut(shortcutId: ShortCutId): MethodDecorator;
|
|
32
34
|
/**
|
|
@@ -34,7 +36,6 @@ export declare function SlackShortcut(shortcutId: ShortCutId): MethodDecorator;
|
|
|
34
36
|
* @see guide https://tools.slack.dev/bolt-js/concepts/commands
|
|
35
37
|
* @see api https://api.slack.com/interactivity/slash-commands
|
|
36
38
|
* @param commandId
|
|
37
|
-
* @constructor
|
|
38
39
|
*/
|
|
39
40
|
export declare function SlackCommand(commandId: Pattern): MethodDecorator;
|
|
40
41
|
export type ActionId = Pattern | ActionConstraints;
|
|
@@ -42,7 +43,6 @@ export type ActionId = Pattern | ActionConstraints;
|
|
|
42
43
|
* Decorator for action events
|
|
43
44
|
* @see guide https://tools.slack.dev/bolt-js/concepts/actions
|
|
44
45
|
* @param actionId
|
|
45
|
-
* @constructor
|
|
46
46
|
*/
|
|
47
47
|
export declare function SlackAction(actionId: ActionId): MethodDecorator;
|
|
48
48
|
export type ViewId = Pattern | ViewConstraints;
|
|
@@ -50,7 +50,6 @@ export type ViewId = Pattern | ViewConstraints;
|
|
|
50
50
|
* Decorator for view events
|
|
51
51
|
* @see guide https://tools.slack.dev/bolt-js/concepts/view-submissions
|
|
52
52
|
* @param viewId
|
|
53
|
-
* @constructor
|
|
54
53
|
*/
|
|
55
54
|
export declare function SlackView(viewId: ViewId): MethodDecorator;
|
|
56
55
|
export type OptionId = OptionsConstraints;
|
|
@@ -58,7 +57,6 @@ export type OptionId = OptionsConstraints;
|
|
|
58
57
|
* Decorator for options events
|
|
59
58
|
* @see guide https://tools.slack.dev/bolt-js/concepts/options
|
|
60
59
|
* @param optionId
|
|
61
|
-
* @constructor
|
|
62
60
|
*/
|
|
63
61
|
export declare function SlackOption(optionId: OptionId): MethodDecorator;
|
|
64
62
|
/**
|
|
@@ -67,6 +65,5 @@ export declare function SlackOption(optionId: OptionId): MethodDecorator;
|
|
|
67
65
|
* @see guide https://tools.slack.dev/bolt-js/concepts/message-listening
|
|
68
66
|
* @see reference https://api.slack.com/events/message
|
|
69
67
|
* @param pattern
|
|
70
|
-
* @constructor
|
|
71
68
|
*/
|
|
72
69
|
export declare function SlackMessage(pattern?: Pattern): MethodDecorator;
|
package/decorators.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventTypes = void 0;
|
|
4
|
+
exports.SlackController = SlackController;
|
|
4
5
|
exports.SlackEvent = SlackEvent;
|
|
5
6
|
exports.SlackShortcut = SlackShortcut;
|
|
6
7
|
exports.SlackCommand = SlackCommand;
|
|
@@ -8,24 +9,30 @@ exports.SlackAction = SlackAction;
|
|
|
8
9
|
exports.SlackView = SlackView;
|
|
9
10
|
exports.SlackOption = SlackOption;
|
|
10
11
|
exports.SlackMessage = SlackMessage;
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
11
13
|
const utils_1 = require("./utils");
|
|
12
14
|
/**
|
|
13
15
|
* @see https://tools.slack.dev/bolt-js/reference/
|
|
14
16
|
*/
|
|
15
17
|
exports.EventTypes = {
|
|
16
|
-
Event:
|
|
17
|
-
Shortcut:
|
|
18
|
-
Command:
|
|
19
|
-
Action:
|
|
20
|
-
View:
|
|
21
|
-
Option:
|
|
18
|
+
Event: 'event',
|
|
19
|
+
Shortcut: 'shortcut',
|
|
20
|
+
Command: 'command',
|
|
21
|
+
Action: 'action',
|
|
22
|
+
View: 'view',
|
|
23
|
+
Option: 'option',
|
|
22
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Decorator for Slack controller
|
|
27
|
+
*/
|
|
28
|
+
function SlackController() {
|
|
29
|
+
return (target) => (0, common_1.Controller)()(target);
|
|
30
|
+
}
|
|
23
31
|
/**
|
|
24
32
|
* Decorator for event events
|
|
25
33
|
* @see guide https://tools.slack.dev/bolt-js/concepts/event-listening
|
|
26
34
|
* @see api https://api.slack.com/apis/events-api
|
|
27
35
|
* @param event
|
|
28
|
-
* @constructor
|
|
29
36
|
*/
|
|
30
37
|
function SlackEvent(event) {
|
|
31
38
|
// todo input validation (types for event)
|
|
@@ -36,7 +43,6 @@ function SlackEvent(event) {
|
|
|
36
43
|
* @see guide https://tools.slack.dev/bolt-js/concepts/shortcuts
|
|
37
44
|
* @see api https://api.slack.com/interactivity/shortcuts
|
|
38
45
|
* @param shortcutId
|
|
39
|
-
* @constructor
|
|
40
46
|
*/
|
|
41
47
|
function SlackShortcut(shortcutId) {
|
|
42
48
|
return (0, utils_1.eventDecorator)(exports.EventTypes.Shortcut, shortcutId);
|
|
@@ -46,7 +52,6 @@ function SlackShortcut(shortcutId) {
|
|
|
46
52
|
* @see guide https://tools.slack.dev/bolt-js/concepts/commands
|
|
47
53
|
* @see api https://api.slack.com/interactivity/slash-commands
|
|
48
54
|
* @param commandId
|
|
49
|
-
* @constructor
|
|
50
55
|
*/
|
|
51
56
|
function SlackCommand(commandId) {
|
|
52
57
|
// todo input validation command must start with / etc.
|
|
@@ -56,7 +61,6 @@ function SlackCommand(commandId) {
|
|
|
56
61
|
* Decorator for action events
|
|
57
62
|
* @see guide https://tools.slack.dev/bolt-js/concepts/actions
|
|
58
63
|
* @param actionId
|
|
59
|
-
* @constructor
|
|
60
64
|
*/
|
|
61
65
|
function SlackAction(actionId) {
|
|
62
66
|
return (0, utils_1.eventDecorator)(exports.EventTypes.Action, actionId);
|
|
@@ -65,7 +69,6 @@ function SlackAction(actionId) {
|
|
|
65
69
|
* Decorator for view events
|
|
66
70
|
* @see guide https://tools.slack.dev/bolt-js/concepts/view-submissions
|
|
67
71
|
* @param viewId
|
|
68
|
-
* @constructor
|
|
69
72
|
*/
|
|
70
73
|
function SlackView(viewId) {
|
|
71
74
|
return (0, utils_1.eventDecorator)(exports.EventTypes.View, viewId);
|
|
@@ -74,7 +77,6 @@ function SlackView(viewId) {
|
|
|
74
77
|
* Decorator for options events
|
|
75
78
|
* @see guide https://tools.slack.dev/bolt-js/concepts/options
|
|
76
79
|
* @param optionId
|
|
77
|
-
* @constructor
|
|
78
80
|
*/
|
|
79
81
|
function SlackOption(optionId) {
|
|
80
82
|
return (0, utils_1.eventDecorator)(exports.EventTypes.Option, optionId);
|
|
@@ -85,8 +87,7 @@ function SlackOption(optionId) {
|
|
|
85
87
|
* @see guide https://tools.slack.dev/bolt-js/concepts/message-listening
|
|
86
88
|
* @see reference https://api.slack.com/events/message
|
|
87
89
|
* @param pattern
|
|
88
|
-
* @constructor
|
|
89
90
|
*/
|
|
90
|
-
function SlackMessage(pattern =
|
|
91
|
-
return (0, utils_1.messageDecorator)(
|
|
91
|
+
function SlackMessage(pattern = '*') {
|
|
92
|
+
return (0, utils_1.messageDecorator)('message', pattern);
|
|
92
93
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpr/nestjs-slack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "NestJS server implementation of the Slack Assistant",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@types/node": "^22.10.6"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
+
"@nestjs/common": "^11.0.1",
|
|
31
32
|
"@nestjs/microservices": ">=11.0.13",
|
|
32
33
|
"@slack/bolt": ">=4.2.1",
|
|
33
34
|
"reflect-metadata": ">=0.2.2"
|
package/slack.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CustomTransportStrategy, type MessageHandler, Server } from
|
|
2
|
-
import { App, type AppOptions } from
|
|
1
|
+
import { type CustomTransportStrategy, type MessageHandler, Server } from '@nestjs/microservices';
|
|
2
|
+
import { App, type AppOptions } from '@slack/bolt';
|
|
3
3
|
export type SlackOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Slack application options with required types
|
package/slack.js
CHANGED
|
@@ -14,8 +14,6 @@ class Slack extends microservices_1.Server {
|
|
|
14
14
|
async listen(callback) {
|
|
15
15
|
for (const handler of this.getHandlers().values()) {
|
|
16
16
|
this.register(handler);
|
|
17
|
-
const { type, event } = handler.extras;
|
|
18
|
-
this.logger.log(`Handler [${type}] registered with (${event})`);
|
|
19
17
|
}
|
|
20
18
|
await this.app().start();
|
|
21
19
|
callback();
|
|
@@ -24,7 +22,7 @@ class Slack extends microservices_1.Server {
|
|
|
24
22
|
this.#app && (await this.#app.stop());
|
|
25
23
|
}
|
|
26
24
|
on() {
|
|
27
|
-
throw new Error(
|
|
25
|
+
throw new Error('Use SlackEvent decorator to register events');
|
|
28
26
|
}
|
|
29
27
|
unwrap() {
|
|
30
28
|
return this.#app;
|
|
@@ -36,6 +34,7 @@ class Slack extends microservices_1.Server {
|
|
|
36
34
|
*/
|
|
37
35
|
register(handler) {
|
|
38
36
|
const { type, event } = handler.extras;
|
|
37
|
+
this.logger.log(`Registering handler of type [${type}] with (${event})`);
|
|
39
38
|
switch (type) {
|
|
40
39
|
case decorators_1.EventTypes.Shortcut:
|
|
41
40
|
return this.app().shortcut(event, handler);
|
|
@@ -61,7 +60,7 @@ class Slack extends microservices_1.Server {
|
|
|
61
60
|
this.options.slack.logger = (0, utils_1.adjustLogger)(this.logger);
|
|
62
61
|
}
|
|
63
62
|
this.#app = new bolt_1.App(this.options.slack);
|
|
64
|
-
this.logger.log(
|
|
63
|
+
this.logger.log('Bolt app created');
|
|
65
64
|
}
|
|
66
65
|
return this.#app;
|
|
67
66
|
}
|