slack.ts 0.0.1 → 0.0.3
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/README.md +8 -3
- package/dist/api/index.d.ts +25 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +5 -1
- package/dist/api/web/apps.d.ts +6 -0
- package/dist/api/web/apps.d.ts.map +1 -0
- package/dist/api/web/apps.js +1 -0
- package/dist/api/web/chat.d.ts +7 -6
- package/dist/api/web/chat.d.ts.map +1 -1
- package/dist/api/web/conversations.d.ts +4 -4
- package/dist/api/web/files.d.ts +45 -0
- package/dist/api/web/files.d.ts.map +1 -0
- package/dist/api/web/files.js +1 -0
- package/dist/client.d.ts +48 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +71 -11
- package/dist/events/receivers/dummy.d.ts +7 -0
- package/dist/events/receivers/dummy.d.ts.map +1 -0
- package/dist/events/receivers/dummy.js +7 -0
- package/dist/events/receivers/socket.d.ts +15 -0
- package/dist/events/receivers/socket.d.ts.map +1 -0
- package/dist/events/receivers/socket.js +51 -0
- package/dist/events/types/events.d.ts +12 -0
- package/dist/events/types/events.d.ts.map +1 -0
- package/dist/events/types/events.js +1 -0
- package/dist/events/types/index.d.ts +32 -0
- package/dist/events/types/index.d.ts.map +1 -0
- package/dist/events/types/index.js +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/resources/channel.d.ts +17 -9
- package/dist/resources/channel.d.ts.map +1 -1
- package/dist/resources/channel.js +12 -18
- package/dist/resources/message.d.ts +23 -5
- package/dist/resources/message.d.ts.map +1 -1
- package/dist/resources/message.js +26 -11
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +13 -0
- package/dist/utils/messaging.d.ts +28 -0
- package/dist/utils/messaging.d.ts.map +1 -0
- package/dist/utils/messaging.js +36 -0
- package/dist/utils/typing.d.ts +2 -0
- package/dist/utils/typing.d.ts.map +1 -0
- package/dist/utils/typing.js +1 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -8,9 +8,14 @@ An opinionated Slack API library with full TypeScript support.
|
|
|
8
8
|
import { App } from 'slack.ts'
|
|
9
9
|
|
|
10
10
|
const app = new App({
|
|
11
|
-
token: process.env.SLACK_BOT_TOKEN
|
|
11
|
+
token: process.env.SLACK_BOT_TOKEN,
|
|
12
|
+
receiver: { type: 'socket', appToken: process.env.SLACK_APP_TOKEN! },
|
|
12
13
|
})
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
app.message(async ({ message }) => {
|
|
16
|
+
if (message.user === process.env.SLACK_USER_ID) return
|
|
17
|
+
await message.reply("I'm always listening :eyes:")
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
await app.start()
|
|
16
21
|
```
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,26 +1,40 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AppsConnectionsOpenParams, AppsConnectionsOpenResponse } from "./web/apps.js";
|
|
2
|
+
import type { AuthTestParams, AuthTestResponse } from "./web/auth.js";
|
|
3
|
+
import type { ChatPostMessageParams, ChatPostMessageResponse } from "./web/chat.js";
|
|
4
|
+
import type { ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from "./web/conversations.js";
|
|
5
|
+
import type { FilesCompleteUploadExternalParams, FilesCompleteUploadExternalResponse, FilesGetUploadURLExternalParams, FilesGetUploadURLExternalResponse } from "./web/files.js";
|
|
4
6
|
export interface SlackWebAPIMap {
|
|
5
|
-
|
|
7
|
+
"apps.connections.open": {
|
|
8
|
+
params: AppsConnectionsOpenParams;
|
|
9
|
+
response: AppsConnectionsOpenResponse;
|
|
10
|
+
};
|
|
11
|
+
"auth.test": {
|
|
6
12
|
params: AuthTestParams;
|
|
7
13
|
response: AuthTestResponse;
|
|
8
14
|
};
|
|
9
|
-
|
|
15
|
+
"chat.postMessage": {
|
|
10
16
|
params: ChatPostMessageParams;
|
|
11
17
|
response: ChatPostMessageResponse;
|
|
12
18
|
};
|
|
13
|
-
|
|
19
|
+
"conversations.info": {
|
|
14
20
|
params: ConversationsInfoParams;
|
|
15
21
|
response: ConversationsInfoResponse;
|
|
16
22
|
};
|
|
17
|
-
|
|
23
|
+
"conversations.replies": {
|
|
18
24
|
params: ConversationsRepliesParams;
|
|
19
25
|
response: ConversationsRepliesResponse;
|
|
20
26
|
};
|
|
27
|
+
"files.completeUploadExternal": {
|
|
28
|
+
params: FilesCompleteUploadExternalParams;
|
|
29
|
+
response: FilesCompleteUploadExternalResponse;
|
|
30
|
+
};
|
|
31
|
+
"files.getUploadURLExternal": {
|
|
32
|
+
params: FilesGetUploadURLExternalParams;
|
|
33
|
+
response: FilesGetUploadURLExternalResponse;
|
|
34
|
+
};
|
|
21
35
|
}
|
|
22
36
|
export type SlackAPIMethod = keyof SlackWebAPIMap;
|
|
23
|
-
export type SlackAPIParams<Method extends SlackAPIMethod> = SlackWebAPIMap[Method][
|
|
37
|
+
export type SlackAPIParams<Method extends SlackAPIMethod> = SlackWebAPIMap[Method]["params"] & {
|
|
24
38
|
token?: string;
|
|
25
39
|
};
|
|
26
40
|
export type SlackAPIResponse<Method extends SlackAPIMethod> = {
|
|
@@ -28,5 +42,6 @@ export type SlackAPIResponse<Method extends SlackAPIMethod> = {
|
|
|
28
42
|
error: string;
|
|
29
43
|
} | ({
|
|
30
44
|
ok: true;
|
|
31
|
-
} & SlackWebAPIMap[Method][
|
|
32
|
-
|
|
45
|
+
} & SlackWebAPIMap[Method]["response"]);
|
|
46
|
+
export declare const POST_METHODS: SlackAPIMethod[];
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EACX,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxF,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EACX,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EACX,iCAAiC,EACjC,mCAAmC,EACnC,+BAA+B,EAC/B,iCAAiC,EACjC,MAAM,aAAa,CAAA;AAEpB,MAAM,WAAW,cAAc;IAC9B,uBAAuB,EAAE;QACxB,MAAM,EAAE,yBAAyB,CAAA;QACjC,QAAQ,EAAE,2BAA2B,CAAA;KACrC,CAAA;IACD,WAAW,EAAE;QACZ,MAAM,EAAE,cAAc,CAAA;QACtB,QAAQ,EAAE,gBAAgB,CAAA;KAC1B,CAAA;IACD,kBAAkB,EAAE;QACnB,MAAM,EAAE,qBAAqB,CAAA;QAC7B,QAAQ,EAAE,uBAAuB,CAAA;KACjC,CAAA;IACD,oBAAoB,EAAE;QACrB,MAAM,EAAE,uBAAuB,CAAA;QAC/B,QAAQ,EAAE,yBAAyB,CAAA;KACnC,CAAA;IACD,uBAAuB,EAAE;QACxB,MAAM,EAAE,0BAA0B,CAAA;QAClC,QAAQ,EAAE,4BAA4B,CAAA;KACtC,CAAA;IACD,8BAA8B,EAAE;QAC/B,MAAM,EAAE,iCAAiC,CAAA;QACzC,QAAQ,EAAE,mCAAmC,CAAA;KAC7C,CAAA;IACD,4BAA4B,EAAE;QAC7B,MAAM,EAAE,+BAA+B,CAAA;QACvC,QAAQ,EAAE,iCAAiC,CAAA;KAC3C,CAAA;CACD;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,cAAc,CAAA;AACjD,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,cAAc,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG;IAC9F,KAAK,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AACD,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,cAAc,IACvD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC5B,CAAC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;AAEtD,eAAO,MAAM,YAAY,EAAE,cAAc,EAIxC,CAAA"}
|
package/dist/api/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps.d.ts","sourceRoot":"","sources":["../../../src/api/web/apps.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;CAAG;AAE7C,MAAM,WAAW,2BAA2B;IAC3C,GAAG,EAAE,MAAM,CAAA;CACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/api/web/chat.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { KnownBlock } from "@slack/types";
|
|
2
|
+
import type { Attachment, NormalMessage } from "../types/message.js";
|
|
2
3
|
interface MarkdownMessage {
|
|
3
4
|
markdown_text: string;
|
|
4
5
|
blocks?: never;
|
|
@@ -6,22 +7,22 @@ interface MarkdownMessage {
|
|
|
6
7
|
}
|
|
7
8
|
type TextMessage = {
|
|
8
9
|
markdown_text?: never;
|
|
9
|
-
blocks?:
|
|
10
|
+
blocks?: KnownBlock[];
|
|
10
11
|
text?: string;
|
|
11
12
|
} & ({
|
|
12
|
-
blocks:
|
|
13
|
+
blocks: KnownBlock[];
|
|
13
14
|
} | {
|
|
14
15
|
text: string;
|
|
15
16
|
});
|
|
16
17
|
export type ChatPostMessageParams = {
|
|
17
18
|
channel: string;
|
|
18
|
-
attachments?:
|
|
19
|
+
attachments?: Attachment[];
|
|
19
20
|
icon_emoji?: string;
|
|
20
21
|
icon_url?: string;
|
|
21
22
|
link_names?: boolean;
|
|
22
23
|
metadata?: unknown;
|
|
23
24
|
mrkdwn?: boolean;
|
|
24
|
-
parse?:
|
|
25
|
+
parse?: "none" | "full";
|
|
25
26
|
reply_broadcast?: boolean;
|
|
26
27
|
thread_ts?: string;
|
|
27
28
|
unfurl_links?: boolean;
|
|
@@ -34,4 +35,4 @@ export interface ChatPostMessageResponse {
|
|
|
34
35
|
message: NormalMessage;
|
|
35
36
|
}
|
|
36
37
|
export {};
|
|
37
|
-
//# sourceMappingURL=chat.d.ts.map
|
|
38
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/api/web/chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/api/web/chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEjE,UAAU,eAAe;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,IAAI,CAAC,EAAE,KAAK,CAAA;CACZ;AAED,KAAK,WAAW,GAAG;IAClB,aAAa,CAAC,EAAE,KAAK,CAAA;IACrB,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,CAAC;IAAE,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEjD,MAAM,MAAM,qBAAqB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,CAAC,eAAe,GAAG,WAAW,CAAC,CAAA;AAEnC,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,MAAM,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,aAAa,CAAA;CACtB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CursorPaginationParams, CursorPaginationResponse, TimestampPaginationParams } from
|
|
2
|
-
import type { Conversation } from
|
|
3
|
-
import type { AnyMessage } from
|
|
1
|
+
import type { CursorPaginationParams, CursorPaginationResponse, TimestampPaginationParams } from "../types/api.js";
|
|
2
|
+
import type { Conversation } from "../types/conversation.js";
|
|
3
|
+
import type { AnyMessage } from "../types/message.js";
|
|
4
4
|
export interface ConversationsInfoParams {
|
|
5
5
|
/** Conversation ID to learn more about */
|
|
6
6
|
channel: string;
|
|
@@ -36,4 +36,4 @@ export interface ConversationsRepliesParams extends CursorPaginationParams, Time
|
|
|
36
36
|
export interface ConversationsRepliesResponse extends CursorPaginationResponse {
|
|
37
37
|
messages: AnyMessage[];
|
|
38
38
|
}
|
|
39
|
-
//# sourceMappingURL=conversations.d.ts.map
|
|
39
|
+
//# sourceMappingURL=conversations.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { KnownBlock } from '@slack/types';
|
|
2
|
+
interface CompleteUploadFile {
|
|
3
|
+
id: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FilesCompleteUploadExternalParams {
|
|
7
|
+
/** Array of file ids and their corresponding (optional) titles. */
|
|
8
|
+
files: CompleteUploadFile[];
|
|
9
|
+
/** Channel ID where the file will be shared. If not specified the file will be private. */
|
|
10
|
+
channel_id?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Provide another message's `ts` value to upload this file as a reply. Never use a reply's `ts`
|
|
13
|
+
* value; use its parent instead. Also make sure to provide only one channel when using
|
|
14
|
+
* 'thread_ts'
|
|
15
|
+
*/
|
|
16
|
+
thread_ts?: string;
|
|
17
|
+
/** Comma-separated string of channel IDs or user IDs where the file will be shared. */
|
|
18
|
+
channels?: string;
|
|
19
|
+
/** The message text introducing the file in specified channels. */
|
|
20
|
+
initial_comment?: string;
|
|
21
|
+
/**
|
|
22
|
+
* A JSON-based array of structured rich text blocks, presented as a URL-encoded string. If the
|
|
23
|
+
* `initial_comment` field is provided, the `blocks` field is ignored
|
|
24
|
+
*/
|
|
25
|
+
blocks?: KnownBlock[];
|
|
26
|
+
}
|
|
27
|
+
export interface FilesCompleteUploadExternalResponse {
|
|
28
|
+
files: CompleteUploadFile[];
|
|
29
|
+
}
|
|
30
|
+
export interface FilesGetUploadURLExternalParams {
|
|
31
|
+
/** Size in bytes of the file being uploaded. */
|
|
32
|
+
length: number;
|
|
33
|
+
/** Name of the file being uploaded. */
|
|
34
|
+
filename: string;
|
|
35
|
+
/** Syntax type of the snippet being uploaded. */
|
|
36
|
+
snippet_type?: string;
|
|
37
|
+
/** Description of image for screen-reader. */
|
|
38
|
+
alt_txt?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface FilesGetUploadURLExternalResponse {
|
|
41
|
+
upload_url: string;
|
|
42
|
+
file_id: string;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/api/web/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,UAAU,kBAAkB;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,iCAAiC;IACjD,mEAAmE;IACnE,KAAK,EAAE,kBAAkB,EAAE,CAAA;IAE3B,2FAA2F;IAC3F,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;CACrB;AAED,MAAM,WAAW,mCAAmC;IACnD,KAAK,EAAE,kBAAkB,EAAE,CAAA;CAC3B;AAED,MAAM,WAAW,+BAA+B;IAC/C,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAA;IAEd,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAA;IAEhB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,iCAAiC;IACjD,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,54 @@
|
|
|
1
|
-
import { ChannelRef } from
|
|
2
|
-
import type
|
|
1
|
+
import { ChannelRef } from "./resources/channel.js";
|
|
2
|
+
import { type SlackAPIMethod, type SlackAPIParams, type SlackAPIResponse } from "./api/index.js";
|
|
3
|
+
import { type SocketEventsReceiverOptions } from "./events/receivers/socket.js";
|
|
4
|
+
import type { DistributiveOmit } from "./utils/typing.js";
|
|
5
|
+
import type { AllEvents, EventWrapper } from "./events/types/index.js";
|
|
6
|
+
import { type MessageInstance } from "./resources/message.js";
|
|
7
|
+
import type { MessageEvent } from "./events/types/events.js";
|
|
8
|
+
type ReceiverOptions = ({
|
|
9
|
+
type: "socket";
|
|
10
|
+
} & DistributiveOmit<SocketEventsReceiverOptions, "client">) | {
|
|
11
|
+
type: "dummy";
|
|
12
|
+
options?: never;
|
|
13
|
+
};
|
|
3
14
|
interface AppOptions {
|
|
4
15
|
token?: string;
|
|
16
|
+
receiver?: ReceiverOptions;
|
|
5
17
|
}
|
|
18
|
+
type MessageCallbackData = {
|
|
19
|
+
message: MessageInstance;
|
|
20
|
+
client: App;
|
|
21
|
+
event: EventWrapper<MessageEvent>;
|
|
22
|
+
};
|
|
23
|
+
type MessageCallback = (data: MessageCallbackData) => unknown;
|
|
24
|
+
type EventCallbackData<Event extends AllEvents> = {
|
|
25
|
+
client: App;
|
|
26
|
+
event: EventWrapper<Event>;
|
|
27
|
+
};
|
|
28
|
+
type EventCallback<Event extends AllEvents> = (data: EventCallbackData<Event>) => unknown;
|
|
6
29
|
export declare class App {
|
|
7
30
|
#private;
|
|
8
|
-
|
|
31
|
+
private messageCallbacks;
|
|
32
|
+
private eventCallbacks;
|
|
33
|
+
constructor({ token, receiver }?: AppOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Registers a callback for `message` events.
|
|
36
|
+
*
|
|
37
|
+
* @param callback Function to execute when a new message is received
|
|
38
|
+
*/
|
|
39
|
+
message(callback: MessageCallback): void;
|
|
40
|
+
/**
|
|
41
|
+
* Registers a callback for a given type of event.
|
|
42
|
+
*
|
|
43
|
+
* @param type Type of event to register
|
|
44
|
+
* @param callback Function to execute when the event is received
|
|
45
|
+
*/
|
|
46
|
+
event<Event extends AllEvents>(type: Event["type"], callback: EventCallback<Event>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Starts the event receiver. If you don't use the events, interactions, and slash command APIs,
|
|
49
|
+
* you don't need to call this function.
|
|
50
|
+
*/
|
|
51
|
+
start(): Promise<void>;
|
|
9
52
|
/**
|
|
10
53
|
* Gets a channel reference object. You can use this object to call API methods, or `await` it to
|
|
11
54
|
* fetch channel details.
|
|
@@ -22,9 +65,9 @@ export declare class App {
|
|
|
22
65
|
* @param [method='GET'] The HTTP method for the request. Default is `'GET'`
|
|
23
66
|
* @returns The response from the API call
|
|
24
67
|
*/
|
|
25
|
-
request<Method extends SlackAPIMethod>(endpoint: Method, params: SlackAPIParams<Method>, method?:
|
|
68
|
+
request<Method extends SlackAPIMethod>(endpoint: Method, params: SlackAPIParams<Method>, method?: "GET" | "POST"): Promise<SlackAPIResponse<Method> & {
|
|
26
69
|
ok: true;
|
|
27
70
|
}>;
|
|
28
71
|
}
|
|
29
72
|
export {};
|
|
30
|
-
//# sourceMappingURL=client.d.ts.map
|
|
73
|
+
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,MAAM,OAAO,CAAA;AACd,OAAO,EAAwB,KAAK,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAiC,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE5F,OAAO,EAAW,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAGzD,KAAK,eAAe,GACjB,CAAC;IACD,IAAI,EAAE,QAAQ,CAAA;CACb,GAAG,gBAAgB,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAAC,GAC5D;IACA,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAEJ,UAAU,UAAU;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,eAAe,CAAA;CAC1B;AAED,KAAK,mBAAmB,GAAG;IAC1B,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,GAAG,CAAA;IACX,KAAK,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;CACjC,CAAA;AACD,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,mBAAmB,KAAK,OAAO,CAAA;AAE7D,KAAK,iBAAiB,CAAC,KAAK,SAAS,SAAS,IAAI;IACjD,MAAM,EAAE,GAAG,CAAA;IACX,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAA;CAC1B,CAAA;AACD,KAAK,aAAa,CAAC,KAAK,SAAS,SAAS,IAAI,CAAC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,KAAK,OAAO,CAAA;AAEzF,qBAAa,GAAG;;IAIf,OAAO,CAAC,gBAAgB,CAAwB;IAChD,OAAO,CAAC,cAAc,CAA0E;gBAEpF,EAAE,KAAK,EAAE,QAA4B,EAAE,GAAE,UAAe;IAsCpE;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,eAAe;IAIjC;;;;;OAKG;IACH,KAAK,CAAC,KAAK,SAAS,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC;IAKlF;;;OAGG;IACG,KAAK;IAIX;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM;IAIlB;;;;;;;OAOG;IACG,OAAO,CAAC,MAAM,SAAS,cAAc,EAC1C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,EAC9B,MAAM,GAAE,KAAK,GAAG,MAAyD,GACvE,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,CAAC;CAgCnD"}
|
package/dist/client.js
CHANGED
|
@@ -1,10 +1,70 @@
|
|
|
1
|
-
import { sleep } from
|
|
2
|
-
import { ChannelRef } from
|
|
3
|
-
import { SlackWebAPIError, SlackWebAPIPlatformError } from
|
|
1
|
+
import { sleep } from "./utils/index.js";
|
|
2
|
+
import { ChannelRef } from "./resources/channel.js";
|
|
3
|
+
import { SlackWebAPIError, SlackWebAPIPlatformError } from "./error.js";
|
|
4
|
+
import { POST_METHODS, } from "./api/index.js";
|
|
5
|
+
import { SocketEventsReceiver } from "./events/receivers/socket.js";
|
|
6
|
+
import { DummyReceiver } from "./events/receivers/dummy.js";
|
|
7
|
+
import { Message } from "./resources/message.js";
|
|
4
8
|
export class App {
|
|
5
9
|
#token;
|
|
6
|
-
|
|
10
|
+
#receiver;
|
|
11
|
+
messageCallbacks = [];
|
|
12
|
+
eventCallbacks = {};
|
|
13
|
+
constructor({ token, receiver = { type: "dummy" } } = {}) {
|
|
7
14
|
this.#token = token;
|
|
15
|
+
switch (receiver.type) {
|
|
16
|
+
case "socket":
|
|
17
|
+
this.#receiver = new SocketEventsReceiver({ ...receiver, client: this });
|
|
18
|
+
break;
|
|
19
|
+
default:
|
|
20
|
+
this.#receiver = new DummyReceiver();
|
|
21
|
+
}
|
|
22
|
+
this.#receiver.on("event", this.#onEvent.bind(this));
|
|
23
|
+
}
|
|
24
|
+
async #onEvent(event) {
|
|
25
|
+
const data = {
|
|
26
|
+
client: this,
|
|
27
|
+
event,
|
|
28
|
+
};
|
|
29
|
+
for (const callback of this.eventCallbacks[event.event.type] ?? []) {
|
|
30
|
+
callback(data);
|
|
31
|
+
}
|
|
32
|
+
if (event.event.type === "message") {
|
|
33
|
+
const data = {
|
|
34
|
+
message: new Message(this, event.event.channel, event.event.ts, event.event),
|
|
35
|
+
client: this,
|
|
36
|
+
event: event,
|
|
37
|
+
};
|
|
38
|
+
for (const callback of this.messageCallbacks) {
|
|
39
|
+
callback(data);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Registers a callback for `message` events.
|
|
45
|
+
*
|
|
46
|
+
* @param callback Function to execute when a new message is received
|
|
47
|
+
*/
|
|
48
|
+
message(callback) {
|
|
49
|
+
this.messageCallbacks.push(callback);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Registers a callback for a given type of event.
|
|
53
|
+
*
|
|
54
|
+
* @param type Type of event to register
|
|
55
|
+
* @param callback Function to execute when the event is received
|
|
56
|
+
*/
|
|
57
|
+
event(type, callback) {
|
|
58
|
+
if (!this.eventCallbacks[type])
|
|
59
|
+
this.eventCallbacks[type] = [];
|
|
60
|
+
this.eventCallbacks[type].push(callback);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Starts the event receiver. If you don't use the events, interactions, and slash command APIs,
|
|
64
|
+
* you don't need to call this function.
|
|
65
|
+
*/
|
|
66
|
+
async start() {
|
|
67
|
+
await this.#receiver.start();
|
|
8
68
|
}
|
|
9
69
|
/**
|
|
10
70
|
* Gets a channel reference object. You can use this object to call API methods, or `await` it to
|
|
@@ -24,27 +84,27 @@ export class App {
|
|
|
24
84
|
* @param [method='GET'] The HTTP method for the request. Default is `'GET'`
|
|
25
85
|
* @returns The response from the API call
|
|
26
86
|
*/
|
|
27
|
-
async request(endpoint, params, method =
|
|
28
|
-
const body = method !==
|
|
87
|
+
async request(endpoint, params, method = POST_METHODS.includes(endpoint) ? "POST" : "GET") {
|
|
88
|
+
const body = method !== "GET" ? JSON.stringify(params) : undefined;
|
|
29
89
|
const url = new URL(`https://slack.com/api/${endpoint}`);
|
|
30
|
-
if (method ===
|
|
90
|
+
if (method === "GET" && params) {
|
|
31
91
|
for (const [key, value] of Object.entries(params)) {
|
|
32
92
|
if (value instanceof Array) {
|
|
33
93
|
for (const item of value) {
|
|
34
94
|
url.searchParams.append(key, item);
|
|
35
95
|
}
|
|
36
96
|
}
|
|
37
|
-
else {
|
|
97
|
+
else if (value !== undefined && value !== null) {
|
|
38
98
|
url.searchParams.set(key, String(value));
|
|
39
99
|
}
|
|
40
100
|
}
|
|
41
101
|
}
|
|
42
102
|
const headers = new Headers();
|
|
43
103
|
if (body) {
|
|
44
|
-
headers.append(
|
|
104
|
+
headers.append("Content-Type", "application/json; charset=utf-8");
|
|
45
105
|
}
|
|
46
106
|
if (params.token || this.#token) {
|
|
47
|
-
headers.set(
|
|
107
|
+
headers.set("Authorization", `Bearer ${params.token || this.#token}`);
|
|
48
108
|
}
|
|
49
109
|
const res = await request(url.toString(), { method, body, headers });
|
|
50
110
|
if (!res.ok) {
|
|
@@ -56,7 +116,7 @@ export class App {
|
|
|
56
116
|
async function request(url, options) {
|
|
57
117
|
const res = await fetch(url, options);
|
|
58
118
|
if (res.status === 429) {
|
|
59
|
-
const retryAfter = Number(res.headers.get(
|
|
119
|
+
const retryAfter = Number(res.headers.get("Retry-After") ?? 2);
|
|
60
120
|
await sleep(retryAfter * 1000);
|
|
61
121
|
return request(url, options);
|
|
62
122
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import type { EventsReceiver, ReceiverEventMap } from "../types/index.js";
|
|
3
|
+
export declare class DummyReceiver extends EventEmitter<ReceiverEventMap> implements EventsReceiver {
|
|
4
|
+
constructor();
|
|
5
|
+
start(): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=dummy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummy.d.ts","sourceRoot":"","sources":["../../../src/events/receivers/dummy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEhE,qBAAa,aAAc,SAAQ,YAAY,CAAC,gBAAgB,CAAE,YAAW,cAAc;;IAK1F,KAAK;CACL"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import type { App } from "../../client.js";
|
|
3
|
+
import type { EventsReceiver, ReceiverEventMap } from "../types/index.js";
|
|
4
|
+
export interface SocketEventsReceiverOptions {
|
|
5
|
+
appToken: string;
|
|
6
|
+
client: App;
|
|
7
|
+
}
|
|
8
|
+
export declare class SocketEventsReceiver extends EventEmitter<ReceiverEventMap> implements EventsReceiver {
|
|
9
|
+
#private;
|
|
10
|
+
client: App;
|
|
11
|
+
constructor({ appToken, client }: SocketEventsReceiverOptions);
|
|
12
|
+
start(): Promise<void>;
|
|
13
|
+
private _connect;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/events/receivers/socket.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AAEjC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,EAAE,cAAc,EAAgB,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE9E,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,GAAG,CAAA;CACX;AAED,qBAAa,oBAAqB,SAAQ,YAAY,CAAC,gBAAgB,CAAE,YAAW,cAAc;;IAE1F,MAAM,EAAE,GAAG,CAAA;gBAGN,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,2BAA2B;IAMvD,KAAK;YAIG,QAAQ;CAuCtB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import WebSocket from 'ws';
|
|
3
|
+
export class SocketEventsReceiver extends EventEmitter {
|
|
4
|
+
#appToken;
|
|
5
|
+
client;
|
|
6
|
+
#ws;
|
|
7
|
+
constructor({ appToken, client }) {
|
|
8
|
+
super();
|
|
9
|
+
this.#appToken = appToken;
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
async start() {
|
|
13
|
+
await this._connect();
|
|
14
|
+
}
|
|
15
|
+
async _connect() {
|
|
16
|
+
const { url } = await this.client.request('apps.connections.open', { token: this.#appToken });
|
|
17
|
+
this.#ws = new WebSocket(url + '&debug_reconnects=true');
|
|
18
|
+
this.#ws.addEventListener('open', this.#onOpen.bind(this));
|
|
19
|
+
this.#ws.addEventListener('message', this.#onMessage.bind(this));
|
|
20
|
+
this.#ws.addEventListener('close', this.#onClose.bind(this));
|
|
21
|
+
this.#ws.addEventListener('error', this.#onError.bind(this));
|
|
22
|
+
}
|
|
23
|
+
#onOpen() {
|
|
24
|
+
console.debug('[socket-mode] websocket connected');
|
|
25
|
+
}
|
|
26
|
+
#onMessage(event) {
|
|
27
|
+
console.debug('[socket-mode] message received');
|
|
28
|
+
if (typeof event.data === 'string') {
|
|
29
|
+
const data = JSON.parse(event.data);
|
|
30
|
+
if (data.type === 'events_api') {
|
|
31
|
+
this.#ws?.send(JSON.stringify({ envelope_id: data.envelope_id }));
|
|
32
|
+
this.emit('event', data.payload);
|
|
33
|
+
}
|
|
34
|
+
else if (data.type === 'hello') {
|
|
35
|
+
console.debug('[socket-mode] received server hello, app id', data.connection_info.app_id);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.warn('[socket-mode] unknown message:', data);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
#onClose(event) {
|
|
43
|
+
console.debug('[socket-mode] websocket closed with code', event.code, event.reason);
|
|
44
|
+
this._connect();
|
|
45
|
+
}
|
|
46
|
+
#onError(event) {
|
|
47
|
+
console.debug('[socket-mode] websocket error', event.message);
|
|
48
|
+
this.#ws?.close();
|
|
49
|
+
this._connect();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AnyMessage } from "../../api/types/message.js";
|
|
2
|
+
import type { DistributiveOmit } from "../../utils/typing.js";
|
|
3
|
+
export type AppMentionEvent = {
|
|
4
|
+
type: "app_mention";
|
|
5
|
+
channel: string;
|
|
6
|
+
event_ts: string;
|
|
7
|
+
} & DistributiveOmit<AnyMessage, "type">;
|
|
8
|
+
export type MessageEvent = {
|
|
9
|
+
channel: string;
|
|
10
|
+
event_ts: string;
|
|
11
|
+
} & AnyMessage;
|
|
12
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/events/types/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CAChB,GAAG,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;AAExC,MAAM,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CAChB,GAAG,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type EventEmitter from "events";
|
|
2
|
+
import type { AppMentionEvent, MessageEvent } from "./events.js";
|
|
3
|
+
export interface EventsReceiver extends EventEmitter<ReceiverEventMap> {
|
|
4
|
+
start(): unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface EventWrapper<T extends AllEvents = AllEvents> {
|
|
7
|
+
type: "event_callback";
|
|
8
|
+
token: string;
|
|
9
|
+
team_id: string;
|
|
10
|
+
api_app_id: string;
|
|
11
|
+
event: T;
|
|
12
|
+
event_context: string;
|
|
13
|
+
event_id: string;
|
|
14
|
+
event_time: number;
|
|
15
|
+
authorizations: unknown[];
|
|
16
|
+
is_ext_shared_channel: boolean;
|
|
17
|
+
context_team_id: string;
|
|
18
|
+
context_enterprise_id: string | null;
|
|
19
|
+
}
|
|
20
|
+
export type AllEventTypes = AllEvents["type"];
|
|
21
|
+
export type SlackEventMap = {
|
|
22
|
+
[K in AllEventTypes]: AllEvents & {
|
|
23
|
+
type: K;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type ReceiverEventMap = {
|
|
27
|
+
event: [
|
|
28
|
+
EventWrapper<AllEvents>
|
|
29
|
+
];
|
|
30
|
+
};
|
|
31
|
+
export type AllEvents = AppMentionEvent | MessageEvent;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/events/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAA;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE7D,MAAM,WAAW,cAAe,SAAQ,YAAY,CAAC,gBAAgB,CAAC;IACrE,KAAK,IAAI,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC5D,IAAI,EAAE,gBAAgB,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,CAAC,CAAA;IACR,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,OAAO,EAAE,CAAA;IACzB,qBAAqB,EAAE,OAAO,CAAA;IAC9B,eAAe,EAAE,MAAM,CAAA;IACvB,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAA;CACpC;AAED,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAE7C,MAAM,MAAM,aAAa,GAAG;KAC1B,CAAC,IAAI,aAAa,GAAG,SAAS,GAAG;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE;CAC7C,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,eAAe,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./error.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./error.js";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { Conversation } from
|
|
2
|
-
import type { NormalMessage } from
|
|
3
|
-
import type { App } from
|
|
4
|
-
import {
|
|
1
|
+
import type { Conversation } from "../api/types/conversation.js";
|
|
2
|
+
import type { NormalMessage } from "../api/types/message.js";
|
|
3
|
+
import type { App } from "../client.js";
|
|
4
|
+
import { type SendMessageWithFiles, type SendMessageWithoutFiles } from "../utils/messaging.js";
|
|
5
|
+
import type { DistributiveOmit } from "../utils/typing.js";
|
|
6
|
+
import { MessageRef, type MessageInstance } from "./message.js";
|
|
5
7
|
declare class ChannelMixin {
|
|
6
8
|
#private;
|
|
7
9
|
protected client: App;
|
|
@@ -9,13 +11,19 @@ declare class ChannelMixin {
|
|
|
9
11
|
/** ID of the channel */
|
|
10
12
|
get id(): string;
|
|
11
13
|
/**
|
|
12
|
-
* Sends a message in the channel
|
|
14
|
+
* Sends a message in the channel with files.
|
|
15
|
+
*
|
|
16
|
+
* @param message The message payload to send, including the files to upload. `text` will be
|
|
17
|
+
* ignored if `blocks` are provided.
|
|
18
|
+
*/
|
|
19
|
+
send(message: DistributiveOmit<SendMessageWithFiles, "channel">): Promise<undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Sends a message in the channel.
|
|
13
22
|
*
|
|
14
23
|
* @param message The message payload to send, either a mrkdwn-formatted string or an object.
|
|
15
|
-
* Including the `files` key in the object will upload the files and share them in the channel.
|
|
16
24
|
* @returns The sent message
|
|
17
25
|
*/
|
|
18
|
-
send(message:
|
|
26
|
+
send(message: DistributiveOmit<SendMessageWithoutFiles, "channel"> | string): Promise<MessageInstance<NormalMessage>>;
|
|
19
27
|
/**
|
|
20
28
|
* Gets a message reference object. You can use this object to call API methods, or `await` it to
|
|
21
29
|
* fetch message details.
|
|
@@ -23,7 +31,7 @@ declare class ChannelMixin {
|
|
|
23
31
|
* @param ts The timestamp of the message
|
|
24
32
|
* @returns A message reference object
|
|
25
33
|
*/
|
|
26
|
-
message(ts: string): MessageRef<import("../api/types/message").AnyMessage>;
|
|
34
|
+
message(ts: string): MessageRef<import("../api/types/message.js").AnyMessage>;
|
|
27
35
|
}
|
|
28
36
|
export declare class ChannelRef extends ChannelMixin implements PromiseLike<ChannelInstance> {
|
|
29
37
|
#private;
|
|
@@ -35,4 +43,4 @@ export declare class Channel extends ChannelMixin {
|
|
|
35
43
|
}
|
|
36
44
|
export type ChannelInstance = Channel & Conversation;
|
|
37
45
|
export {};
|
|
38
|
-
//# sourceMappingURL=channel.d.ts.map
|
|
46
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/resources/channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/resources/channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAGN,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAW,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAErE,cAAM,YAAY;;IAIhB,SAAS,CAAC,MAAM,EAAE,GAAG;gBAAX,MAAM,EAAE,GAAG,EACrB,EAAE,EAAE,MAAM;IAKX,wBAAwB;IACxB,IAAI,EAAE,WAEL;IAED;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAE1F;;;;;OAKG;IACG,IAAI,CACT,OAAO,EAAE,gBAAgB,CAAC,uBAAuB,EAAE,SAAS,CAAC,GAAG,MAAM,GACpE,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IAiB1C;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM;CAGlB;AAED,qBAAa,UAAW,SAAQ,YAAa,YAAW,WAAW,CAAC,eAAe,CAAC;;IACnF,IAAI,CAAC,QAAQ,GAAG,eAAe,EAAE,QAAQ,GAAG,KAAK,EAChD,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC/F,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GACjF,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;CAQnC;AAED,qBAAa,OAAQ,SAAQ,YAAY;;gBAG5B,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY;CAKvD;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,YAAY,CAAA"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { makeProxy } from "../utils/index.js";
|
|
2
|
+
import { sendMessage, } from "../utils/messaging.js";
|
|
3
|
+
import { Message, MessageRef } from "./message.js";
|
|
2
4
|
class ChannelMixin {
|
|
3
5
|
client;
|
|
4
6
|
#id;
|
|
@@ -10,16 +12,14 @@ class ChannelMixin {
|
|
|
10
12
|
get id() {
|
|
11
13
|
return this.#id;
|
|
12
14
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Sends a message in the channel
|
|
15
|
-
*
|
|
16
|
-
* @param message The message payload to send, either a mrkdwn-formatted string or an object.
|
|
17
|
-
* Including the `files` key in the object will upload the files and share them in the channel.
|
|
18
|
-
* @returns The sent message
|
|
19
|
-
*/
|
|
20
15
|
async send(message) {
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
if (typeof message === "string") {
|
|
17
|
+
message = { text: message };
|
|
18
|
+
}
|
|
19
|
+
const data = await sendMessage(this.client, { ...message, channel: this.id });
|
|
20
|
+
if (data) {
|
|
21
|
+
return new Message(this.client, this.#id, data.ts, data.message);
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Gets a message reference object. You can use this object to call API methods, or `await` it to
|
|
@@ -37,7 +37,7 @@ export class ChannelRef extends ChannelMixin {
|
|
|
37
37
|
return this.#fetch().then(onfulfilled, onrejected);
|
|
38
38
|
}
|
|
39
39
|
async #fetch() {
|
|
40
|
-
const data = await this.client.request(
|
|
40
|
+
const data = await this.client.request("conversations.info", { channel: this.id });
|
|
41
41
|
return new Channel(this.client, this.id, data.channel);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -46,12 +46,6 @@ export class Channel extends ChannelMixin {
|
|
|
46
46
|
constructor(client, id, data) {
|
|
47
47
|
super(client, id);
|
|
48
48
|
this.#data = data;
|
|
49
|
-
return
|
|
50
|
-
get(target, prop) {
|
|
51
|
-
if (prop in target)
|
|
52
|
-
return target[prop];
|
|
53
|
-
return target.#data[prop];
|
|
54
|
-
},
|
|
55
|
-
});
|
|
49
|
+
return makeProxy(this, () => this.#data);
|
|
56
50
|
}
|
|
57
51
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { AnyMessage, NormalMessage } from
|
|
2
|
-
import type { App } from
|
|
3
|
-
import {
|
|
1
|
+
import type { AnyMessage, NormalMessage } from "../api/types/message.js";
|
|
2
|
+
import type { App } from "../client.js";
|
|
3
|
+
import { type SendMessageWithFiles, type SendMessageWithoutFiles } from "../utils/messaging.js";
|
|
4
|
+
import type { DistributiveOmit } from "../utils/typing.js";
|
|
5
|
+
import { ChannelRef } from "./channel.js";
|
|
4
6
|
declare class MessageMixin {
|
|
5
7
|
#private;
|
|
6
8
|
protected client: App;
|
|
@@ -10,6 +12,21 @@ declare class MessageMixin {
|
|
|
10
12
|
protected get _channelId(): string;
|
|
11
13
|
/** Timestamp of the message */
|
|
12
14
|
get ts(): string;
|
|
15
|
+
protected get _threadTs(): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Sends a message as a reply to this messsage with files.
|
|
18
|
+
*
|
|
19
|
+
* @param message The message payload to send, including the files to upload. `text` will be
|
|
20
|
+
* ignored if `blocks` are provided.
|
|
21
|
+
*/
|
|
22
|
+
reply(message: DistributiveOmit<SendMessageWithFiles, "channel" | "thread_ts">): Promise<undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Sends a message as a reply to this messsage.
|
|
25
|
+
*
|
|
26
|
+
* @param message The message payload to send, either a mrkdwn-formatted string or an object.
|
|
27
|
+
* @returns The sent message
|
|
28
|
+
*/
|
|
29
|
+
reply(message: DistributiveOmit<SendMessageWithoutFiles, "channel" | "thread_ts"> | string): Promise<MessageInstance<NormalMessage>>;
|
|
13
30
|
}
|
|
14
31
|
export declare class MessageRef<Subtype extends AnyMessage = AnyMessage> extends MessageMixin implements PromiseLike<Message<Subtype>> {
|
|
15
32
|
#private;
|
|
@@ -19,10 +36,11 @@ export declare class Message<Subtype extends AnyMessage = AnyMessage> extends Me
|
|
|
19
36
|
#private;
|
|
20
37
|
constructor(client: App, channel: string, ts: string, data: Subtype);
|
|
21
38
|
/** @returns Whether this message is a normal message (subtype is undefined) */
|
|
22
|
-
isNormal(): this is
|
|
39
|
+
isNormal(): this is MessageInstance<NormalMessage>;
|
|
23
40
|
/** The raw data of this message */
|
|
24
41
|
get raw(): Subtype;
|
|
42
|
+
protected get _threadTs(): string | undefined;
|
|
25
43
|
}
|
|
26
44
|
export type MessageInstance<Subtype extends AnyMessage = AnyMessage> = Message<Subtype> & Subtype;
|
|
27
45
|
export {};
|
|
28
|
-
//# sourceMappingURL=message.d.ts.map
|
|
46
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/resources/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/resources/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAGpC,OAAO,EAGN,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,cAAM,YAAY;;IAKhB,SAAS,CAAC,MAAM,EAAE,GAAG;gBAAX,MAAM,EAAE,GAAG,EACrB,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,MAAM;IAMX,8CAA8C;IAC9C,IAAI,OAAO,eAEV;IAED,SAAS,KAAK,UAAU,WAEvB;IAED,+BAA+B;IAC/B,IAAI,EAAE,WAEL;IAED,SAAS,KAAK,SAAS,IAAI,MAAM,GAAG,SAAS,CAE5C;IAED;;;;;OAKG;IACG,KAAK,CACV,OAAO,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,SAAS,GAAG,WAAW,CAAC,GACtE,OAAO,CAAC,SAAS,CAAC;IAErB;;;;;OAKG;IACG,KAAK,CACV,OAAO,EAAE,gBAAgB,CAAC,uBAAuB,EAAE,SAAS,GAAG,WAAW,CAAC,GAAG,MAAM,GAClF,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;CAoB1C;AAED,qBAAa,UAAU,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,CAC9D,SAAQ,YACR,YAAW,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;;IAExC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,KAAK,EACjD,WAAW,CAAC,EACT,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAC/D,IAAI,GACJ,SAAS,EACZ,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GACjF,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;CAsBnC;AAED,qBAAa,OAAO,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,YAAY;;gBAGrE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;IAMnE,+EAA+E;IAC/E,QAAQ,IAAI,IAAI,IAAI,eAAe,CAAC,aAAa,CAAC;IAIlD,mCAAmC;IACnC,IAAI,GAAG,YAEN;IAED,cAAuB,SAAS,IAAI,MAAM,GAAG,SAAS,CAErD;CACD;AAED,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { SlackError } from
|
|
2
|
-
import {
|
|
1
|
+
import { SlackError } from "../error.js";
|
|
2
|
+
import { makeProxy } from "../utils/index.js";
|
|
3
|
+
import { sendMessage, } from "../utils/messaging.js";
|
|
4
|
+
import { ChannelRef } from "./channel.js";
|
|
3
5
|
class MessageMixin {
|
|
4
6
|
client;
|
|
5
7
|
#channel;
|
|
@@ -20,13 +22,29 @@ class MessageMixin {
|
|
|
20
22
|
get ts() {
|
|
21
23
|
return this.#ts;
|
|
22
24
|
}
|
|
25
|
+
get _threadTs() {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
async reply(message) {
|
|
29
|
+
if (typeof message === "string") {
|
|
30
|
+
message = { text: message };
|
|
31
|
+
}
|
|
32
|
+
const data = await sendMessage(this.client, {
|
|
33
|
+
...message,
|
|
34
|
+
channel: this.#channel,
|
|
35
|
+
thread_ts: this._threadTs || this.#ts,
|
|
36
|
+
});
|
|
37
|
+
if (data) {
|
|
38
|
+
return new Message(this.client, this.#channel, data.ts, data.message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
23
41
|
}
|
|
24
42
|
export class MessageRef extends MessageMixin {
|
|
25
43
|
then(onfulfilled, onrejected) {
|
|
26
44
|
return this.#fetch().then(onfulfilled, onrejected);
|
|
27
45
|
}
|
|
28
46
|
async #fetch() {
|
|
29
|
-
const data = await this.client.request(
|
|
47
|
+
const data = await this.client.request("conversations.replies", {
|
|
30
48
|
channel: this._channelId,
|
|
31
49
|
ts: this.ts,
|
|
32
50
|
latest: this.ts,
|
|
@@ -34,7 +52,7 @@ export class MessageRef extends MessageMixin {
|
|
|
34
52
|
inclusive: true,
|
|
35
53
|
});
|
|
36
54
|
if (!data.messages.length) {
|
|
37
|
-
throw new SlackError(
|
|
55
|
+
throw new SlackError("Message is not found");
|
|
38
56
|
}
|
|
39
57
|
return new Message(this.client, this._channelId, this.ts, data.messages[0]);
|
|
40
58
|
}
|
|
@@ -44,13 +62,7 @@ export class Message extends MessageMixin {
|
|
|
44
62
|
constructor(client, channel, ts, data) {
|
|
45
63
|
super(client, channel, ts);
|
|
46
64
|
this.#data = data;
|
|
47
|
-
return
|
|
48
|
-
get(target, prop) {
|
|
49
|
-
if (prop in target)
|
|
50
|
-
return target[prop];
|
|
51
|
-
return target.#data[prop];
|
|
52
|
-
},
|
|
53
|
-
});
|
|
65
|
+
return makeProxy(this, () => this.#data);
|
|
54
66
|
}
|
|
55
67
|
/** @returns Whether this message is a normal message (subtype is undefined) */
|
|
56
68
|
isNormal() {
|
|
@@ -60,4 +72,7 @@ export class Message extends MessageMixin {
|
|
|
60
72
|
get raw() {
|
|
61
73
|
return this.#data;
|
|
62
74
|
}
|
|
75
|
+
get _threadTs() {
|
|
76
|
+
return this.#data.thread_ts;
|
|
77
|
+
}
|
|
63
78
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAErC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAErC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAWvD"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
export async function sleep(ms) {
|
|
2
2
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
3
|
}
|
|
4
|
+
export function makeProxy(object, getter) {
|
|
5
|
+
return new Proxy(object, {
|
|
6
|
+
get(target, prop) {
|
|
7
|
+
if (prop in target) {
|
|
8
|
+
const value = target[prop];
|
|
9
|
+
if (typeof value === 'function')
|
|
10
|
+
return value.bind(target);
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
return getter()[prop];
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { KnownBlock } from "@slack/types";
|
|
2
|
+
import type { ChatPostMessageParams } from "../api/web/chat.js";
|
|
3
|
+
import type { App } from "../client.js";
|
|
4
|
+
export type SendMessageFile = {
|
|
5
|
+
file: Buffer | ArrayBuffer;
|
|
6
|
+
filename: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
snippet_type?: string;
|
|
9
|
+
alt_txt?: string;
|
|
10
|
+
};
|
|
11
|
+
export interface SendMessageWithFiles {
|
|
12
|
+
channel: string;
|
|
13
|
+
files: SendMessageFile[];
|
|
14
|
+
thread_ts?: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
blocks?: KnownBlock[];
|
|
17
|
+
token?: string;
|
|
18
|
+
}
|
|
19
|
+
export type SendMessageWithoutFiles = {
|
|
20
|
+
files?: never;
|
|
21
|
+
} & ChatPostMessageParams;
|
|
22
|
+
export type SendMessageParams = SendMessageWithFiles | SendMessageWithoutFiles;
|
|
23
|
+
export declare function sendMessage(client: App, params: SendMessageParams): Promise<{
|
|
24
|
+
channel: string;
|
|
25
|
+
ts: string;
|
|
26
|
+
message: import("../api/types/message.js").NormalMessage;
|
|
27
|
+
} | undefined>;
|
|
28
|
+
//# sourceMappingURL=messaging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging.d.ts","sourceRoot":"","sources":["../../src/utils/messaging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAGpC,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,WAAW,oBAAoB;IACpC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,uBAAuB,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG,qBAAqB,CAAA;AAE/E,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,GAAG,uBAAuB,CAAA;AAE9E,wBAAsB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,iBAAiB;;;;eAmBvE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SlackError } from "../error.js";
|
|
2
|
+
export async function sendMessage(client, params) {
|
|
3
|
+
if (params.files) {
|
|
4
|
+
const files = await Promise.all(params.files.map(async (file) => ({
|
|
5
|
+
id: await uploadHelper(client, file),
|
|
6
|
+
title: file.title,
|
|
7
|
+
})));
|
|
8
|
+
await client.request("files.completeUploadExternal", {
|
|
9
|
+
files,
|
|
10
|
+
channel_id: params.channel,
|
|
11
|
+
thread_ts: params.thread_ts,
|
|
12
|
+
initial_comment: params.text,
|
|
13
|
+
blocks: params.blocks,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const message = await client.request("chat.postMessage", params);
|
|
18
|
+
return { channel: message.channel, ts: message.ts, message: message.message };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function uploadHelper(client, file) {
|
|
22
|
+
const { upload_url, file_id } = await client.request("files.getUploadURLExternal", {
|
|
23
|
+
length: file.file.byteLength,
|
|
24
|
+
filename: file.filename,
|
|
25
|
+
snippet_type: file.snippet_type,
|
|
26
|
+
alt_txt: file.alt_txt,
|
|
27
|
+
});
|
|
28
|
+
const uploadResp = await fetch(upload_url, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
body: file.file,
|
|
31
|
+
});
|
|
32
|
+
if (!uploadResp.ok) {
|
|
33
|
+
throw new SlackError("Failed to upload file");
|
|
34
|
+
}
|
|
35
|
+
return file_id;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typing.d.ts","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,GAAG,SAAS,MAAM,GAAG,IAAI,CAAC,SAAS,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slack.ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A fully-typed, opinionated Slack API library",
|
|
5
5
|
"author": "@jollyroger182",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,14 +35,17 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/bun": "^1.3.11",
|
|
37
37
|
"@types/node": "^25.5.0",
|
|
38
|
+
"@types/ws": "^8.18.1",
|
|
38
39
|
"prettier": "^3.8.1",
|
|
39
40
|
"prettier-plugin-jsdoc": "^1.8.0",
|
|
41
|
+
"ts-add-js-extension": "^1.6.6",
|
|
40
42
|
"typescript": "^5"
|
|
41
43
|
},
|
|
42
44
|
"engines": {
|
|
43
45
|
"node": ">=18"
|
|
44
46
|
},
|
|
45
47
|
"dependencies": {
|
|
46
|
-
"@slack/types": "^2.20.1"
|
|
48
|
+
"@slack/types": "^2.20.1",
|
|
49
|
+
"ws": "^8.20.0"
|
|
47
50
|
}
|
|
48
51
|
}
|