@xpr/nestjs-slack 1.0.1 → 1.0.2
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 +4 -4
- package/decorators.js +8 -8
- package/license +21 -0
- package/package.json +3 -2
- package/readme.md +8 -12
- package/slack.d.ts +2 -2
- package/slack.js +2 -2
- package/utils.d.ts +1 -1
- package/utils.js +8 -8
package/decorators.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ActionConstraints, OptionsConstraints, ShortcutConstraints, ViewConstraints } from
|
|
2
|
-
import { type Pattern } from
|
|
3
|
-
import type { AllMiddlewareArgs, AnyMiddlewareArgs, SlackActionMiddlewareArgs, SlackCommandMiddlewareArgs, SlackEventMiddlewareArgs, SlackOptionsMiddlewareArgs, SlackShortcutMiddlewareArgs, SlackViewMiddlewareArgs } from
|
|
1
|
+
import { ActionConstraints, OptionsConstraints, ShortcutConstraints, ViewConstraints } from "@slack/bolt";
|
|
2
|
+
import { type Pattern } from "./utils";
|
|
3
|
+
import type { AllMiddlewareArgs, AnyMiddlewareArgs, SlackActionMiddlewareArgs, SlackCommandMiddlewareArgs, SlackEventMiddlewareArgs, SlackOptionsMiddlewareArgs, SlackShortcutMiddlewareArgs, SlackViewMiddlewareArgs } from "@slack/bolt/dist/types";
|
|
4
4
|
export { Pattern };
|
|
5
5
|
export type EndpointArgs<T extends AnyMiddlewareArgs> = T & AllMiddlewareArgs;
|
|
6
6
|
/**
|
|
@@ -98,7 +98,7 @@ export type OptionId = OptionsConstraints;
|
|
|
98
98
|
* @param optionId
|
|
99
99
|
*/
|
|
100
100
|
export declare function SlackOption(optionId: OptionId): MethodDecorator;
|
|
101
|
-
export type SlackMessageArgs = EndpointArgs<SlackEventMiddlewareArgs<
|
|
101
|
+
export type SlackMessageArgs = EndpointArgs<SlackEventMiddlewareArgs<"message">>;
|
|
102
102
|
/**
|
|
103
103
|
* Decorator for message events
|
|
104
104
|
*
|
package/decorators.js
CHANGED
|
@@ -15,13 +15,13 @@ const utils_1 = require("./utils");
|
|
|
15
15
|
* @see https://tools.slack.dev/bolt-js/reference/
|
|
16
16
|
*/
|
|
17
17
|
exports.EventTypes = {
|
|
18
|
-
Event:
|
|
19
|
-
Shortcut:
|
|
20
|
-
Command:
|
|
21
|
-
Action:
|
|
22
|
-
View:
|
|
23
|
-
Option:
|
|
24
|
-
Message:
|
|
18
|
+
Event: "event",
|
|
19
|
+
Shortcut: "shortcut",
|
|
20
|
+
Command: "command",
|
|
21
|
+
Action: "action",
|
|
22
|
+
View: "view",
|
|
23
|
+
Option: "option",
|
|
24
|
+
Message: "message",
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Decorator for Slack controller
|
|
@@ -89,6 +89,6 @@ function SlackOption(optionId) {
|
|
|
89
89
|
* @see reference https://api.slack.com/events/message
|
|
90
90
|
* @param pattern
|
|
91
91
|
*/
|
|
92
|
-
function SlackMessage(pattern =
|
|
92
|
+
function SlackMessage(pattern = "*") {
|
|
93
93
|
return (0, utils_1.eventDecorator)(exports.EventTypes.Message, pattern);
|
|
94
94
|
}
|
package/license
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 to Ziv Perry.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to delal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpr/nestjs-slack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "NestJS server implementation of the Slack Assistant",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"files": [
|
|
43
43
|
"*.js",
|
|
44
44
|
"*.d.ts",
|
|
45
|
-
"readme.md"
|
|
45
|
+
"readme.md",
|
|
46
|
+
"license"
|
|
46
47
|
],
|
|
47
48
|
"release": {
|
|
48
49
|
"extends": "semantic-release-monorepo",
|
package/readme.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @xpr/nestjs-slack
|
|
2
2
|
|
|
3
|
-
A NestJS microservice transport and decorators for
|
|
3
|
+
A NestJS microservice transport and decorators for
|
|
4
|
+
[Slack Bolt Apps](https://github.com/slackapi/bolt-js).
|
|
4
5
|
|
|
5
6
|
### Usage
|
|
6
7
|
|
|
@@ -31,27 +32,22 @@ await app.listen();
|
|
|
31
32
|
Example of a Slack controller with listener for action and a command.
|
|
32
33
|
|
|
33
34
|
```ts
|
|
34
|
-
import {
|
|
35
|
-
SlackAction,
|
|
36
|
-
SlackCommand,
|
|
37
|
-
SlackController,
|
|
38
|
-
} from '@xpr/nestjs-slack';
|
|
35
|
+
import { SlackAction, SlackCommand, SlackController } from "@xpr/nestjs-slack";
|
|
39
36
|
|
|
40
37
|
@SlackController()
|
|
41
38
|
export class MyController {
|
|
42
|
-
|
|
43
|
-
@SlackAction('button-action')
|
|
39
|
+
@SlackAction("button-action")
|
|
44
40
|
async onAction({ ack, respond, payload }: SlackActionMiddlewareArgs) {
|
|
45
41
|
await ack();
|
|
46
42
|
await respond(`Button clicked! with payload ${JSON.stringify(payload)}`);
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
@SlackCommand(
|
|
45
|
+
@SlackCommand("/ping")
|
|
50
46
|
async onPing({ ack, respond }: SlackCommandMiddlewareArgs) {
|
|
51
47
|
await ack();
|
|
52
48
|
await respond({
|
|
53
|
-
text:
|
|
54
|
-
response_type:
|
|
49
|
+
text: "pong!",
|
|
50
|
+
response_type: "in_channel",
|
|
55
51
|
});
|
|
56
52
|
}
|
|
57
53
|
}
|
|
@@ -63,4 +59,4 @@ export class MyController {
|
|
|
63
59
|
|
|
64
60
|
## Decorators
|
|
65
61
|
|
|
66
|
-
See [source file](./decorators.ts).
|
|
62
|
+
See [source file](./decorators.ts).
|
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
|
@@ -22,7 +22,7 @@ class Slack extends microservices_1.Server {
|
|
|
22
22
|
this.#app && (await this.#app.stop());
|
|
23
23
|
}
|
|
24
24
|
on() {
|
|
25
|
-
throw new Error(
|
|
25
|
+
throw new Error("Use SlackEvent decorator to register events");
|
|
26
26
|
}
|
|
27
27
|
unwrap() {
|
|
28
28
|
return this.#app;
|
|
@@ -69,7 +69,7 @@ class Slack extends microservices_1.Server {
|
|
|
69
69
|
this.options.slack.logger = (0, utils_1.adjustLogger)(this.logger);
|
|
70
70
|
}
|
|
71
71
|
this.#app = new bolt_1.App(this.options.slack);
|
|
72
|
-
this.logger.log(
|
|
72
|
+
this.logger.log("Bolt app created");
|
|
73
73
|
}
|
|
74
74
|
return this.#app;
|
|
75
75
|
}
|
package/utils.d.ts
CHANGED
package/utils.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.adjustLogger = adjustLogger;
|
|
|
6
6
|
const microservices_1 = require("@nestjs/microservices");
|
|
7
7
|
const bolt_1 = require("@slack/bolt");
|
|
8
8
|
const normalizePattern = (pattern) => {
|
|
9
|
-
if (typeof pattern ===
|
|
9
|
+
if (typeof pattern === "string") {
|
|
10
10
|
return pattern;
|
|
11
11
|
}
|
|
12
12
|
if (pattern instanceof RegExp) {
|
|
@@ -39,29 +39,29 @@ function messageDecorator(type, pattern) {
|
|
|
39
39
|
function adjustLogger(logger) {
|
|
40
40
|
// this patch required to support NestJS logger that not use the standard "info"
|
|
41
41
|
// and use "log" instead
|
|
42
|
-
if (logger[
|
|
43
|
-
logger[
|
|
42
|
+
if (logger["log"] && !logger["info"]) {
|
|
43
|
+
logger["info"] = logger["log"].bind(logger);
|
|
44
44
|
}
|
|
45
45
|
// minimal logger interface required by @slack/bolt library
|
|
46
|
-
for (const method of [
|
|
47
|
-
if (typeof logger[method] !==
|
|
46
|
+
for (const method of ["debug", "info", "warn", "error"]) {
|
|
47
|
+
if (typeof logger[method] !== "function") {
|
|
48
48
|
throw new Error(`Logger must implement "${method}" method`);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
// add compatibility with @slack/bolt library
|
|
52
|
-
if (!logger[
|
|
52
|
+
if (!logger["setLevel"]) {
|
|
53
53
|
logger.setLevel = () => {
|
|
54
54
|
// don't allow library to set the level
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
if (!logger[
|
|
57
|
+
if (!logger["getLevel"]) {
|
|
58
58
|
logger.getLevel = () => {
|
|
59
59
|
// always return the lowest supported level (by library, not real logger)
|
|
60
60
|
// to avoid filtering log messages by library instead of real logger
|
|
61
61
|
return bolt_1.LogLevel.DEBUG;
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
if (!logger[
|
|
64
|
+
if (!logger["setName"]) {
|
|
65
65
|
logger.setName = (name) => {
|
|
66
66
|
// search for all possible setName/setContext methods, use "noop" if none
|
|
67
67
|
(logger.setName ?? logger.setContext ?? ((i) => i))(name);
|