slack.ts 0.0.1
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/LICENSE +21 -0
- package/README.md +16 -0
- package/dist/api/index.d.ts +32 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/types/api.d.ts +36 -0
- package/dist/api/types/api.d.ts.map +1 -0
- package/dist/api/types/api.js +1 -0
- package/dist/api/types/conversation.d.ts +83 -0
- package/dist/api/types/conversation.d.ts.map +1 -0
- package/dist/api/types/conversation.js +1 -0
- package/dist/api/types/message.d.ts +83 -0
- package/dist/api/types/message.d.ts.map +1 -0
- package/dist/api/types/message.js +1 -0
- package/dist/api/web/auth.d.ts +13 -0
- package/dist/api/web/auth.d.ts.map +1 -0
- package/dist/api/web/auth.js +1 -0
- package/dist/api/web/chat.d.ts +37 -0
- package/dist/api/web/chat.d.ts.map +1 -0
- package/dist/api/web/chat.js +1 -0
- package/dist/api/web/conversations.d.ts +39 -0
- package/dist/api/web/conversations.d.ts.map +1 -0
- package/dist/api/web/conversations.js +1 -0
- package/dist/client.d.ts +30 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +66 -0
- package/dist/error.d.ts +12 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +18 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/resources/channel.d.ts +38 -0
- package/dist/resources/channel.d.ts.map +1 -0
- package/dist/resources/channel.js +57 -0
- package/dist/resources/message.d.ts +28 -0
- package/dist/resources/message.d.ts.map +1 -0
- package/dist/resources/message.js +63 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 @jollyroger182
|
|
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 deal
|
|
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
|
|
13
|
+
all 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/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# slack.ts
|
|
2
|
+
|
|
3
|
+
An opinionated Slack API library with full TypeScript support.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { App } from 'slack.ts'
|
|
9
|
+
|
|
10
|
+
const app = new App({
|
|
11
|
+
token: process.env.SLACK_BOT_TOKEN
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const message = await app.channel('C0123456ABC').send('Hello, slack.ts!')
|
|
15
|
+
console.log("Message timestamp:", message.ts)
|
|
16
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AuthTestParams, AuthTestResponse } from './web/auth';
|
|
2
|
+
import type { ChatPostMessageParams, ChatPostMessageResponse } from './web/chat';
|
|
3
|
+
import type { ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from './web/conversations';
|
|
4
|
+
export interface SlackWebAPIMap {
|
|
5
|
+
'auth.test': {
|
|
6
|
+
params: AuthTestParams;
|
|
7
|
+
response: AuthTestResponse;
|
|
8
|
+
};
|
|
9
|
+
'chat.postMessage': {
|
|
10
|
+
params: ChatPostMessageParams;
|
|
11
|
+
response: ChatPostMessageResponse;
|
|
12
|
+
};
|
|
13
|
+
'conversations.info': {
|
|
14
|
+
params: ConversationsInfoParams;
|
|
15
|
+
response: ConversationsInfoResponse;
|
|
16
|
+
};
|
|
17
|
+
'conversations.replies': {
|
|
18
|
+
params: ConversationsRepliesParams;
|
|
19
|
+
response: ConversationsRepliesResponse;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export type SlackAPIMethod = keyof SlackWebAPIMap;
|
|
23
|
+
export type SlackAPIParams<Method extends SlackAPIMethod> = SlackWebAPIMap[Method]['params'] & {
|
|
24
|
+
token?: string;
|
|
25
|
+
};
|
|
26
|
+
export type SlackAPIResponse<Method extends SlackAPIMethod> = {
|
|
27
|
+
ok: false;
|
|
28
|
+
error: string;
|
|
29
|
+
} | ({
|
|
30
|
+
ok: true;
|
|
31
|
+
} & SlackWebAPIMap[Method]['response']);
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAE5B,MAAM,WAAW,cAAc;IAC9B,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;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface CursorPaginationParams {
|
|
2
|
+
/**
|
|
3
|
+
* Paginate through collections of data by setting the cursor parameter to a next_cursor attribute
|
|
4
|
+
* returned by a previous request's response_metadata. Default value fetches the first "page" of
|
|
5
|
+
* the collection.
|
|
6
|
+
*/
|
|
7
|
+
cursor?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The maximum number of items to return. Fewer than the requested number of items may be
|
|
10
|
+
* returned, even if the end of the list hasn't been reached.
|
|
11
|
+
*/
|
|
12
|
+
limit?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface TimestampPaginationParams {
|
|
15
|
+
/**
|
|
16
|
+
* Include items with `oldest` or `latest` timestamps in results. Ignored unless either timestamp
|
|
17
|
+
* is specified.
|
|
18
|
+
*/
|
|
19
|
+
inclusive?: boolean;
|
|
20
|
+
/** Only items before this Unix timestamp will be included in results. */
|
|
21
|
+
latest?: string;
|
|
22
|
+
/** Only items after this Unix timestamp will be included in results. */
|
|
23
|
+
oldest?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The maximum number of items to return. Fewer than the requested number of items may be
|
|
26
|
+
* returned, even if the end of the list hasn't been reached.
|
|
27
|
+
*/
|
|
28
|
+
limit?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CursorPaginationResponse {
|
|
31
|
+
has_more: boolean;
|
|
32
|
+
response_metadata?: {
|
|
33
|
+
next_cursor: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/types/api.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACtC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,yBAAyB;IACzC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,wBAAwB;IACxC,QAAQ,EAAE,OAAO,CAAA;IACjB,iBAAiB,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAA;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
interface ConversationCommon {
|
|
2
|
+
id: string;
|
|
3
|
+
created: number;
|
|
4
|
+
is_org_shared?: boolean;
|
|
5
|
+
is_im?: boolean;
|
|
6
|
+
context_team_id: string;
|
|
7
|
+
updated: number;
|
|
8
|
+
is_channel?: boolean;
|
|
9
|
+
is_group?: boolean;
|
|
10
|
+
is_mpim?: boolean;
|
|
11
|
+
is_private?: boolean;
|
|
12
|
+
is_archived: boolean;
|
|
13
|
+
is_general?: boolean;
|
|
14
|
+
is_shared?: boolean;
|
|
15
|
+
is_ext_shared?: boolean;
|
|
16
|
+
is_pending_ext_shared?: boolean;
|
|
17
|
+
pending_shared?: string[];
|
|
18
|
+
shared_team_ids?: string[];
|
|
19
|
+
internal_team_ids?: string[];
|
|
20
|
+
pending_connected_team_ids?: string[];
|
|
21
|
+
is_starred?: boolean;
|
|
22
|
+
last_read?: string;
|
|
23
|
+
properties?: unknown;
|
|
24
|
+
is_open?: boolean;
|
|
25
|
+
creator?: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
name_normalized?: string;
|
|
28
|
+
purpose?: Purpose;
|
|
29
|
+
topic?: Purpose;
|
|
30
|
+
connected_limited_team_ids?: string[];
|
|
31
|
+
connected_team_ids?: string[];
|
|
32
|
+
conversation_host_id?: string;
|
|
33
|
+
is_global_shared?: boolean;
|
|
34
|
+
is_non_threadable?: boolean;
|
|
35
|
+
is_org_default?: boolean;
|
|
36
|
+
is_org_mandatory?: boolean;
|
|
37
|
+
is_read_only?: boolean;
|
|
38
|
+
is_thread_only?: boolean;
|
|
39
|
+
locale?: string;
|
|
40
|
+
num_members?: number;
|
|
41
|
+
}
|
|
42
|
+
interface NonIMCommon extends ConversationCommon {
|
|
43
|
+
creator: string;
|
|
44
|
+
name: string;
|
|
45
|
+
name_normalized: string;
|
|
46
|
+
purpose: Purpose;
|
|
47
|
+
topic: Purpose;
|
|
48
|
+
unlinked?: number;
|
|
49
|
+
parent_conversation?: unknown | null;
|
|
50
|
+
is_member?: boolean;
|
|
51
|
+
is_moved?: number;
|
|
52
|
+
}
|
|
53
|
+
interface Channel extends NonIMCommon {
|
|
54
|
+
is_channel: true;
|
|
55
|
+
is_private: false;
|
|
56
|
+
previous_names?: string[];
|
|
57
|
+
}
|
|
58
|
+
interface Group extends NonIMCommon {
|
|
59
|
+
is_channel: true;
|
|
60
|
+
is_private: true;
|
|
61
|
+
is_mpim: false;
|
|
62
|
+
}
|
|
63
|
+
interface MPIM extends NonIMCommon {
|
|
64
|
+
is_channel: true;
|
|
65
|
+
is_private: true;
|
|
66
|
+
is_mpim: true;
|
|
67
|
+
}
|
|
68
|
+
interface IM extends ConversationCommon {
|
|
69
|
+
is_im: true;
|
|
70
|
+
user: string;
|
|
71
|
+
priority: number;
|
|
72
|
+
unread_count: number;
|
|
73
|
+
unread_count_display: number;
|
|
74
|
+
latest?: unknown;
|
|
75
|
+
}
|
|
76
|
+
export type Conversation = Channel | Group | MPIM | IM;
|
|
77
|
+
interface Purpose {
|
|
78
|
+
value: string;
|
|
79
|
+
creator: string;
|
|
80
|
+
last_set: number;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/api/types/conversation.ts"],"names":[],"mappings":"AAAA,UAAU,kBAAkB;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO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
3
|
+
blocks?: KnownBlock[];
|
|
4
|
+
color?: 'good' | 'warning' | 'danger' | string;
|
|
5
|
+
author_icon?: string;
|
|
6
|
+
author_link?: string;
|
|
7
|
+
author_name?: string;
|
|
8
|
+
fallback?: string;
|
|
9
|
+
fields?: AttachmentField[];
|
|
10
|
+
footer?: string;
|
|
11
|
+
footer_icon?: string;
|
|
12
|
+
image_url?: string;
|
|
13
|
+
mrkdwn_in?: string[];
|
|
14
|
+
pretext?: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
thumb_url?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
title_link?: string;
|
|
19
|
+
ts?: string;
|
|
20
|
+
} & ({
|
|
21
|
+
blocks: KnownBlock[];
|
|
22
|
+
} | {
|
|
23
|
+
fallback: string;
|
|
24
|
+
} | {
|
|
25
|
+
text: string;
|
|
26
|
+
});
|
|
27
|
+
export interface AttachmentField {
|
|
28
|
+
title?: string;
|
|
29
|
+
value?: string;
|
|
30
|
+
short?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface BotProfile {
|
|
33
|
+
id: string;
|
|
34
|
+
app_id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
icons: {
|
|
37
|
+
image_36: string;
|
|
38
|
+
image_48: string;
|
|
39
|
+
image_72: string;
|
|
40
|
+
};
|
|
41
|
+
deleted: boolean;
|
|
42
|
+
updated: number;
|
|
43
|
+
team_id: string;
|
|
44
|
+
}
|
|
45
|
+
interface MaybeBot {
|
|
46
|
+
bot_id?: string;
|
|
47
|
+
app_id?: string;
|
|
48
|
+
bot_profile?: BotProfile;
|
|
49
|
+
}
|
|
50
|
+
interface MaybeAttachments {
|
|
51
|
+
attachments: Attachment[];
|
|
52
|
+
}
|
|
53
|
+
interface MaybeBlocks {
|
|
54
|
+
blocks?: KnownBlock[];
|
|
55
|
+
}
|
|
56
|
+
interface MessageCommon {
|
|
57
|
+
type: 'message';
|
|
58
|
+
ts: string;
|
|
59
|
+
subtype?: string;
|
|
60
|
+
thread_ts?: string;
|
|
61
|
+
text?: string;
|
|
62
|
+
user?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface NormalMessage extends MessageCommon, MaybeBot, MaybeAttachments, MaybeBlocks {
|
|
65
|
+
subtype?: never;
|
|
66
|
+
user: string;
|
|
67
|
+
team: string;
|
|
68
|
+
edited?: {
|
|
69
|
+
user: string;
|
|
70
|
+
ts: string;
|
|
71
|
+
};
|
|
72
|
+
client_msg_id?: string;
|
|
73
|
+
parent_user_id?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface ChannelJoinMessage extends MessageCommon {
|
|
76
|
+
subtype: 'channel_join';
|
|
77
|
+
user: string;
|
|
78
|
+
text: string;
|
|
79
|
+
inviter?: string;
|
|
80
|
+
}
|
|
81
|
+
export type AnyMessage = NormalMessage | ChannelJoinMessage;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/api/types/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,eAAe,EAAE,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM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AE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACb;AAID,MAAM,WAAW,aAAc,SAAQ,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW;IAC5F,OAAO,CAAC,EAAE,KAAK,CAAA;IAEf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;IACrC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACxD,OAAO,EAAE,cAAc,CAAA;IAEvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface AuthTestParams {
|
|
2
|
+
}
|
|
3
|
+
export interface AuthTestResponse {
|
|
4
|
+
url: string;
|
|
5
|
+
team: string;
|
|
6
|
+
user: string;
|
|
7
|
+
team_id: string;
|
|
8
|
+
user_id: string;
|
|
9
|
+
bot_id?: string;
|
|
10
|
+
enterprise_id?: string;
|
|
11
|
+
is_enterprise_install?: boolean;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/api/web/auth.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;CAAG;AAElC,MAAM,WAAW,gBAAgB;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { NormalMessage } from '../types/message';
|
|
2
|
+
interface MarkdownMessage {
|
|
3
|
+
markdown_text: string;
|
|
4
|
+
blocks?: never;
|
|
5
|
+
text?: never;
|
|
6
|
+
}
|
|
7
|
+
type TextMessage = {
|
|
8
|
+
markdown_text?: never;
|
|
9
|
+
blocks?: unknown[];
|
|
10
|
+
text?: string;
|
|
11
|
+
} & ({
|
|
12
|
+
blocks: unknown[];
|
|
13
|
+
} | {
|
|
14
|
+
text: string;
|
|
15
|
+
});
|
|
16
|
+
export type ChatPostMessageParams = {
|
|
17
|
+
channel: string;
|
|
18
|
+
attachments?: unknown[];
|
|
19
|
+
icon_emoji?: string;
|
|
20
|
+
icon_url?: string;
|
|
21
|
+
link_names?: boolean;
|
|
22
|
+
metadata?: unknown;
|
|
23
|
+
mrkdwn?: boolean;
|
|
24
|
+
parse?: 'none' | 'full';
|
|
25
|
+
reply_broadcast?: boolean;
|
|
26
|
+
thread_ts?: string;
|
|
27
|
+
unfurl_links?: boolean;
|
|
28
|
+
unfurl_media?: boolean;
|
|
29
|
+
username?: string;
|
|
30
|
+
} & (MarkdownMessage | TextMessage);
|
|
31
|
+
export interface ChatPostMessageResponse {
|
|
32
|
+
channel: string;
|
|
33
|
+
ts: string;
|
|
34
|
+
message: NormalMessage;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/api/web/chat.ts"],"names":[],"m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se, TimestampPaginationParams } from '../types/api';
|
|
2
|
+
import type { Conversation } from '../types/conversation';
|
|
3
|
+
import type { AnyMessage } from '../types/message';
|
|
4
|
+
export interface ConversationsInfoParams {
|
|
5
|
+
/** Conversation ID to learn more about */
|
|
6
|
+
channel: string;
|
|
7
|
+
/**
|
|
8
|
+
* Set this to `true` to receive the locale for this conversation. Defaults to `false`
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
include_locale?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Set to `true` to include the member count for the specified conversation. Defaults to `false`
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
include_num_members?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ConversationsInfoResponse {
|
|
21
|
+
channel: Conversation;
|
|
22
|
+
}
|
|
23
|
+
export interface ConversationsRepliesParams extends CursorPaginationParams, TimestampPaginationParams {
|
|
24
|
+
/** Conversation ID to fetch thread from. */
|
|
25
|
+
channel: string;
|
|
26
|
+
/**
|
|
27
|
+
* Unique identifier of either a thread’s parent message or a message in the thread. `ts` must be
|
|
28
|
+
* the timestamp of an existing message with 0 or more replies. If there are no replies then just
|
|
29
|
+
* the single message referenced by `ts` will return - it is just an ordinary, unthreaded
|
|
30
|
+
* message.
|
|
31
|
+
*/
|
|
32
|
+
ts: string;
|
|
33
|
+
/** Return all metadata associated with this message. */
|
|
34
|
+
include_all_metadata?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface ConversationsRepliesResponse extends CursorPaginationResponse {
|
|
37
|
+
messages: AnyMessage[];
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=conversations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversations.d.ts","sourceRoot":"","sources":["../../../src/api/web/conversations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,MAAM,WAAW,uBAAuB;IACvC,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAA;IAEf;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,yBAAyB;IACzC,OAAO,EAAE,YAAY,CAAA;CACrB;AAED,MAAM,WAAW,0BAChB,SAAQ,sBAAsB,EAAE,yBAAyB;IACzD,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAA;IAEf;;;;;OAKG;IACH,EAAE,EAAE,MAAM,CAAA;IAEV,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC7E,QAAQ,EAAE,UAAU,EAAE,CAAA;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ChannelRef } from './resources/channel';
|
|
2
|
+
import type { SlackAPIMethod, SlackAPIParams, SlackAPIResponse } from './api';
|
|
3
|
+
interface AppOptions {
|
|
4
|
+
token?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class App {
|
|
7
|
+
#private;
|
|
8
|
+
constructor({ token }: AppOptions);
|
|
9
|
+
/**
|
|
10
|
+
* Gets a channel reference object. You can use this object to call API methods, or `await` it to
|
|
11
|
+
* fetch channel details.
|
|
12
|
+
*
|
|
13
|
+
* @param id Channel ID
|
|
14
|
+
* @returns A channel reference object
|
|
15
|
+
*/
|
|
16
|
+
channel(id: string): ChannelRef;
|
|
17
|
+
/**
|
|
18
|
+
* Makes a Slack Web API request.
|
|
19
|
+
*
|
|
20
|
+
* @param endpoint The Slack Web API method to call
|
|
21
|
+
* @param params The parameters for the method
|
|
22
|
+
* @param [method='GET'] The HTTP method for the request. Default is `'GET'`
|
|
23
|
+
* @returns The response from the API call
|
|
24
|
+
*/
|
|
25
|
+
request<Method extends SlackAPIMethod>(endpoint: Method, params: SlackAPIParams<Method>, method?: string): Promise<SlackAPIResponse<Method> & {
|
|
26
|
+
ok: true;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +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,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAE7E,UAAU,UAAU;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,qBAAa,GAAG;;gBAGH,EAAE,KAAK,EAAE,EAAE,UAAU;IAIjC;;;;;;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,SAAQ,GACZ,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,CAAC;CAgCnD"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { sleep } from './utils';
|
|
2
|
+
import { ChannelRef } from './resources/channel';
|
|
3
|
+
import { SlackWebAPIError, SlackWebAPIPlatformError } from './error';
|
|
4
|
+
export class App {
|
|
5
|
+
#token;
|
|
6
|
+
constructor({ token }) {
|
|
7
|
+
this.#token = token;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Gets a channel reference object. You can use this object to call API methods, or `await` it to
|
|
11
|
+
* fetch channel details.
|
|
12
|
+
*
|
|
13
|
+
* @param id Channel ID
|
|
14
|
+
* @returns A channel reference object
|
|
15
|
+
*/
|
|
16
|
+
channel(id) {
|
|
17
|
+
return new ChannelRef(this, id);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Makes a Slack Web API request.
|
|
21
|
+
*
|
|
22
|
+
* @param endpoint The Slack Web API method to call
|
|
23
|
+
* @param params The parameters for the method
|
|
24
|
+
* @param [method='GET'] The HTTP method for the request. Default is `'GET'`
|
|
25
|
+
* @returns The response from the API call
|
|
26
|
+
*/
|
|
27
|
+
async request(endpoint, params, method = 'GET') {
|
|
28
|
+
const body = method !== 'GET' ? JSON.stringify(params) : undefined;
|
|
29
|
+
const url = new URL(`https://slack.com/api/${endpoint}`);
|
|
30
|
+
if (method === 'GET' && params) {
|
|
31
|
+
for (const [key, value] of Object.entries(params)) {
|
|
32
|
+
if (value instanceof Array) {
|
|
33
|
+
for (const item of value) {
|
|
34
|
+
url.searchParams.append(key, item);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
url.searchParams.set(key, String(value));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const headers = new Headers();
|
|
43
|
+
if (body) {
|
|
44
|
+
headers.append('Content-Type', 'application/json; charset=utf-8');
|
|
45
|
+
}
|
|
46
|
+
if (params.token || this.#token) {
|
|
47
|
+
headers.set('Authorization', `Bearer ${params.token || this.#token}`);
|
|
48
|
+
}
|
|
49
|
+
const res = await request(url.toString(), { method, body, headers });
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
throw new SlackWebAPIPlatformError(url.toString(), res, res.error);
|
|
52
|
+
}
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function request(url, options) {
|
|
57
|
+
const res = await fetch(url, options);
|
|
58
|
+
if (res.status === 429) {
|
|
59
|
+
const retryAfter = Number(res.headers.get('Retry-After') ?? 2);
|
|
60
|
+
await sleep(retryAfter * 1000);
|
|
61
|
+
return request(url, options);
|
|
62
|
+
}
|
|
63
|
+
if (!res.ok)
|
|
64
|
+
throw new SlackWebAPIError(url, await res.json());
|
|
65
|
+
return (await res.json());
|
|
66
|
+
}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class SlackError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class SlackWebAPIError extends SlackError {
|
|
4
|
+
url: string;
|
|
5
|
+
data?: unknown | undefined;
|
|
6
|
+
constructor(url: string, data?: unknown | undefined);
|
|
7
|
+
}
|
|
8
|
+
export declare class SlackWebAPIPlatformError extends SlackWebAPIError {
|
|
9
|
+
error: string;
|
|
10
|
+
constructor(url: string, data: unknown, error: string);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;CAAG;AAExC,qBAAa,gBAAiB,SAAQ,UAAU;IAEvC,GAAG,EAAE,MAAM;IACX,IAAI,CAAC,EAAE,OAAO;gBADd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,YAAA;CAItB;AAED,qBAAa,wBAAyB,SAAQ,gBAAgB;IAIrD,KAAK,EAAE,MAAM;gBAFpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,OAAO,EACN,KAAK,EAAE,MAAM;CAIrB"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class SlackError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export class SlackWebAPIError extends SlackError {
|
|
4
|
+
url;
|
|
5
|
+
data;
|
|
6
|
+
constructor(url, data) {
|
|
7
|
+
super(`Fetch ${url} failed`);
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.data = data;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class SlackWebAPIPlatformError extends SlackWebAPIError {
|
|
13
|
+
error;
|
|
14
|
+
constructor(url, data, error) {
|
|
15
|
+
super(url, data);
|
|
16
|
+
this.error = error;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Conversation } from '../api/types/conversation';
|
|
2
|
+
import type { NormalMessage } from '../api/types/message';
|
|
3
|
+
import type { App } from '../client';
|
|
4
|
+
import { MessageRef, type MessageInstance } from './message';
|
|
5
|
+
declare class ChannelMixin {
|
|
6
|
+
#private;
|
|
7
|
+
protected client: App;
|
|
8
|
+
constructor(client: App, id: string);
|
|
9
|
+
/** ID of the channel */
|
|
10
|
+
get id(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Sends a message in the channel
|
|
13
|
+
*
|
|
14
|
+
* @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
|
+
* @returns The sent message
|
|
17
|
+
*/
|
|
18
|
+
send(message: any): Promise<MessageInstance<NormalMessage>>;
|
|
19
|
+
/**
|
|
20
|
+
* Gets a message reference object. You can use this object to call API methods, or `await` it to
|
|
21
|
+
* fetch message details.
|
|
22
|
+
*
|
|
23
|
+
* @param ts The timestamp of the message
|
|
24
|
+
* @returns A message reference object
|
|
25
|
+
*/
|
|
26
|
+
message(ts: string): MessageRef<import("../api/types/message").AnyMessage>;
|
|
27
|
+
}
|
|
28
|
+
export declare class ChannelRef extends ChannelMixin implements PromiseLike<ChannelInstance> {
|
|
29
|
+
#private;
|
|
30
|
+
then<TResult1 = ChannelInstance, TResult2 = never>(onfulfilled?: ((value: ChannelInstance) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
|
|
31
|
+
}
|
|
32
|
+
export declare class Channel extends ChannelMixin {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(client: App, id: string, data: Conversation);
|
|
35
|
+
}
|
|
36
|
+
export type ChannelInstance = Channel & Conversation;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +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;AACpC,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;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,GAAG;IAUvB;;;;;;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;CAUvD;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Message, MessageRef } from './message';
|
|
2
|
+
class ChannelMixin {
|
|
3
|
+
client;
|
|
4
|
+
#id;
|
|
5
|
+
constructor(client, id) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
this.#id = id;
|
|
8
|
+
}
|
|
9
|
+
/** ID of the channel */
|
|
10
|
+
get id() {
|
|
11
|
+
return this.#id;
|
|
12
|
+
}
|
|
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
|
+
async send(message) {
|
|
21
|
+
const data = await this.client.request('chat.postMessage', { ...message, channel: this.id });
|
|
22
|
+
return new Message(this.client, this.#id, data.ts, data.message);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets a message reference object. You can use this object to call API methods, or `await` it to
|
|
26
|
+
* fetch message details.
|
|
27
|
+
*
|
|
28
|
+
* @param ts The timestamp of the message
|
|
29
|
+
* @returns A message reference object
|
|
30
|
+
*/
|
|
31
|
+
message(ts) {
|
|
32
|
+
return new MessageRef(this.client, this.#id, ts);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ChannelRef extends ChannelMixin {
|
|
36
|
+
then(onfulfilled, onrejected) {
|
|
37
|
+
return this.#fetch().then(onfulfilled, onrejected);
|
|
38
|
+
}
|
|
39
|
+
async #fetch() {
|
|
40
|
+
const data = await this.client.request('conversations.info', { channel: this.id });
|
|
41
|
+
return new Channel(this.client, this.id, data.channel);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class Channel extends ChannelMixin {
|
|
45
|
+
#data;
|
|
46
|
+
constructor(client, id, data) {
|
|
47
|
+
super(client, id);
|
|
48
|
+
this.#data = data;
|
|
49
|
+
return new Proxy(this, {
|
|
50
|
+
get(target, prop) {
|
|
51
|
+
if (prop in target)
|
|
52
|
+
return target[prop];
|
|
53
|
+
return target.#data[prop];
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AnyMessage, NormalMessage } from '../api/types/message';
|
|
2
|
+
import type { App } from '../client';
|
|
3
|
+
import { ChannelRef } from './channel';
|
|
4
|
+
declare class MessageMixin {
|
|
5
|
+
#private;
|
|
6
|
+
protected client: App;
|
|
7
|
+
constructor(client: App, channel: string, ts: string);
|
|
8
|
+
/** The channel where this message was sent */
|
|
9
|
+
get channel(): ChannelRef;
|
|
10
|
+
protected get _channelId(): string;
|
|
11
|
+
/** Timestamp of the message */
|
|
12
|
+
get ts(): string;
|
|
13
|
+
}
|
|
14
|
+
export declare class MessageRef<Subtype extends AnyMessage = AnyMessage> extends MessageMixin implements PromiseLike<Message<Subtype>> {
|
|
15
|
+
#private;
|
|
16
|
+
then<TResult1 = Message<Subtype>, TResult2 = never>(onfulfilled?: ((value: Message<Subtype>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
|
|
17
|
+
}
|
|
18
|
+
export declare class Message<Subtype extends AnyMessage = AnyMessage> extends MessageMixin {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(client: App, channel: string, ts: string, data: Subtype);
|
|
21
|
+
/** @returns Whether this message is a normal message (subtype is undefined) */
|
|
22
|
+
isNormal(): this is Message<NormalMessage>;
|
|
23
|
+
/** The raw data of this message */
|
|
24
|
+
get raw(): Subtype;
|
|
25
|
+
}
|
|
26
|
+
export type MessageInstance<Subtype extends AnyMessage = AnyMessage> = Message<Subtype> & Subtype;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +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;AAEpC,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;CACD;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;IAWnE,+EAA+E;IAC/E,QAAQ,IAAI,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC;IAI1C,mCAAmC;IACnC,IAAI,GAAG,YAEN;CACD;AAED,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SlackError } from '../error';
|
|
2
|
+
import { ChannelRef } from './channel';
|
|
3
|
+
class MessageMixin {
|
|
4
|
+
client;
|
|
5
|
+
#channel;
|
|
6
|
+
#ts;
|
|
7
|
+
constructor(client, channel, ts) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.#channel = channel;
|
|
10
|
+
this.#ts = ts;
|
|
11
|
+
}
|
|
12
|
+
/** The channel where this message was sent */
|
|
13
|
+
get channel() {
|
|
14
|
+
return new ChannelRef(this.client, this.#channel);
|
|
15
|
+
}
|
|
16
|
+
get _channelId() {
|
|
17
|
+
return this.#channel;
|
|
18
|
+
}
|
|
19
|
+
/** Timestamp of the message */
|
|
20
|
+
get ts() {
|
|
21
|
+
return this.#ts;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class MessageRef extends MessageMixin {
|
|
25
|
+
then(onfulfilled, onrejected) {
|
|
26
|
+
return this.#fetch().then(onfulfilled, onrejected);
|
|
27
|
+
}
|
|
28
|
+
async #fetch() {
|
|
29
|
+
const data = await this.client.request('conversations.replies', {
|
|
30
|
+
channel: this._channelId,
|
|
31
|
+
ts: this.ts,
|
|
32
|
+
latest: this.ts,
|
|
33
|
+
oldest: this.ts,
|
|
34
|
+
inclusive: true,
|
|
35
|
+
});
|
|
36
|
+
if (!data.messages.length) {
|
|
37
|
+
throw new SlackError('Message is not found');
|
|
38
|
+
}
|
|
39
|
+
return new Message(this.client, this._channelId, this.ts, data.messages[0]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class Message extends MessageMixin {
|
|
43
|
+
#data;
|
|
44
|
+
constructor(client, channel, ts, data) {
|
|
45
|
+
super(client, channel, ts);
|
|
46
|
+
this.#data = data;
|
|
47
|
+
return new Proxy(this, {
|
|
48
|
+
get(target, prop) {
|
|
49
|
+
if (prop in target)
|
|
50
|
+
return target[prop];
|
|
51
|
+
return target.#data[prop];
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** @returns Whether this message is a normal message (subtype is undefined) */
|
|
56
|
+
isNormal() {
|
|
57
|
+
return !this.#data.subtype;
|
|
58
|
+
}
|
|
59
|
+
/** The raw data of this message */
|
|
60
|
+
get raw() {
|
|
61
|
+
return this.#data;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAErC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "slack.ts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A fully-typed, opinionated Slack API library",
|
|
5
|
+
"author": "@jollyroger182",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"slack",
|
|
9
|
+
"api",
|
|
10
|
+
"typescript",
|
|
11
|
+
"bot",
|
|
12
|
+
"web-api",
|
|
13
|
+
"client",
|
|
14
|
+
"http"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "bun run build.ts",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"prepublishOnly": "bun run typecheck && bun run build"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/bun": "^1.3.11",
|
|
37
|
+
"@types/node": "^25.5.0",
|
|
38
|
+
"prettier": "^3.8.1",
|
|
39
|
+
"prettier-plugin-jsdoc": "^1.8.0",
|
|
40
|
+
"typescript": "^5"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@slack/types": "^2.20.1"
|
|
47
|
+
}
|
|
48
|
+
}
|