slack.ts 0.0.2 → 0.0.4

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.
Files changed (66) hide show
  1. package/README.md +20 -3
  2. package/dist/api/index.d.ts +25 -1
  3. package/dist/api/index.d.ts.map +1 -1
  4. package/dist/api/index.js +5 -1
  5. package/dist/api/interactive/block_actions.d.ts +79 -0
  6. package/dist/api/interactive/block_actions.d.ts.map +1 -0
  7. package/dist/api/interactive/block_actions.js +1 -0
  8. package/dist/api/types/user.d.ts +54 -0
  9. package/dist/api/types/user.d.ts.map +1 -0
  10. package/dist/api/types/user.js +1 -0
  11. package/dist/api/web/apps.d.ts +6 -0
  12. package/dist/api/web/apps.d.ts.map +1 -0
  13. package/dist/api/web/apps.js +1 -0
  14. package/dist/api/web/chat.d.ts +5 -4
  15. package/dist/api/web/chat.d.ts.map +1 -1
  16. package/dist/api/web/conversations.d.ts +12 -0
  17. package/dist/api/web/conversations.d.ts.map +1 -1
  18. package/dist/api/web/files.d.ts +45 -0
  19. package/dist/api/web/files.d.ts.map +1 -0
  20. package/dist/api/web/files.js +1 -0
  21. package/dist/api/web/users.d.ts +11 -0
  22. package/dist/api/web/users.d.ts.map +1 -0
  23. package/dist/api/web/users.js +1 -0
  24. package/dist/client.d.ts +89 -4
  25. package/dist/client.d.ts.map +1 -1
  26. package/dist/client.js +85 -4
  27. package/dist/error.d.ts +2 -0
  28. package/dist/error.d.ts.map +1 -1
  29. package/dist/error.js +2 -0
  30. package/dist/events/receivers/dummy.d.ts +7 -0
  31. package/dist/events/receivers/dummy.d.ts.map +1 -0
  32. package/dist/events/receivers/dummy.js +7 -0
  33. package/dist/events/receivers/socket.d.ts +15 -0
  34. package/dist/events/receivers/socket.d.ts.map +1 -0
  35. package/dist/events/receivers/socket.js +60 -0
  36. package/dist/events/types/events.d.ts +12 -0
  37. package/dist/events/types/events.d.ts.map +1 -0
  38. package/dist/events/types/events.js +1 -0
  39. package/dist/events/types/index.d.ts +36 -0
  40. package/dist/events/types/index.d.ts.map +1 -0
  41. package/dist/events/types/index.js +1 -0
  42. package/dist/resources/action.d.ts +13 -0
  43. package/dist/resources/action.d.ts.map +1 -0
  44. package/dist/resources/action.js +22 -0
  45. package/dist/resources/channel.d.ts +34 -4
  46. package/dist/resources/channel.d.ts.map +1 -1
  47. package/dist/resources/channel.js +47 -16
  48. package/dist/resources/message.d.ts +114 -1
  49. package/dist/resources/message.d.ts.map +1 -1
  50. package/dist/resources/message.js +167 -8
  51. package/dist/resources/user.d.ts +38 -0
  52. package/dist/resources/user.d.ts.map +1 -0
  53. package/dist/resources/user.js +41 -0
  54. package/dist/utils/index.d.ts +1 -0
  55. package/dist/utils/index.d.ts.map +1 -1
  56. package/dist/utils/index.js +13 -0
  57. package/dist/utils/messaging.d.ts +28 -0
  58. package/dist/utils/messaging.d.ts.map +1 -0
  59. package/dist/utils/messaging.js +36 -0
  60. package/dist/utils/respond.d.ts +26 -0
  61. package/dist/utils/respond.d.ts.map +1 -0
  62. package/dist/utils/respond.js +63 -0
  63. package/dist/utils/typing.d.ts +3 -0
  64. package/dist/utils/typing.d.ts.map +1 -0
  65. package/dist/utils/typing.js +1 -0
  66. package/package.json +4 -2
package/README.md CHANGED
@@ -4,13 +4,30 @@ An opinionated Slack API library with full TypeScript support.
4
4
 
5
5
  ## Usage
6
6
 
7
+ You can install this package from npm with
8
+
9
+ ```shell
10
+ npm i slack.ts
11
+ # or
12
+ bun add slack.ts
13
+ ```
14
+
15
+ Sample usage:
16
+
7
17
  ```typescript
8
18
  import { App } from 'slack.ts'
9
19
 
10
20
  const app = new App({
11
- token: process.env.SLACK_BOT_TOKEN
21
+ token: process.env.SLACK_BOT_TOKEN,
22
+ receiver: { type: 'socket', appToken: process.env.SLACK_APP_TOKEN! },
12
23
  })
13
24
 
14
- const message = await app.channel('C0123456ABC').send('Hello, slack.ts!')
15
- console.log("Message timestamp:", message.ts)
25
+ app.message(async ({ message }) => {
26
+ if (message.user === process.env.SLACK_USER_ID) return
27
+ await message.reply("I'm always listening :eyes:")
28
+ })
29
+
30
+ await app.start()
16
31
  ```
32
+
33
+ For more examples, see [the examples directory](./examples).
@@ -1,7 +1,14 @@
1
+ import type { AppsConnectionsOpenParams, AppsConnectionsOpenResponse } from "./web/apps.js";
1
2
  import type { AuthTestParams, AuthTestResponse } from "./web/auth.js";
2
3
  import type { ChatPostMessageParams, ChatPostMessageResponse } from "./web/chat.js";
3
- import type { ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from "./web/conversations.js";
4
+ import type { ConversationsHistoryParams, ConversationsHistoryResponse, ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from "./web/conversations.js";
5
+ import type { FilesCompleteUploadExternalParams, FilesCompleteUploadExternalResponse, FilesGetUploadURLExternalParams, FilesGetUploadURLExternalResponse } from "./web/files.js";
6
+ import type { UsersInfoParams, UsersInfoResponse } from "./web/users.js";
4
7
  export interface SlackWebAPIMap {
8
+ "apps.connections.open": {
9
+ params: AppsConnectionsOpenParams;
10
+ response: AppsConnectionsOpenResponse;
11
+ };
5
12
  "auth.test": {
6
13
  params: AuthTestParams;
7
14
  response: AuthTestResponse;
@@ -14,10 +21,26 @@ export interface SlackWebAPIMap {
14
21
  params: ConversationsInfoParams;
15
22
  response: ConversationsInfoResponse;
16
23
  };
24
+ "conversations.history": {
25
+ params: ConversationsHistoryParams;
26
+ response: ConversationsHistoryResponse;
27
+ };
17
28
  "conversations.replies": {
18
29
  params: ConversationsRepliesParams;
19
30
  response: ConversationsRepliesResponse;
20
31
  };
32
+ "files.completeUploadExternal": {
33
+ params: FilesCompleteUploadExternalParams;
34
+ response: FilesCompleteUploadExternalResponse;
35
+ };
36
+ "files.getUploadURLExternal": {
37
+ params: FilesGetUploadURLExternalParams;
38
+ response: FilesGetUploadURLExternalResponse;
39
+ };
40
+ "users.info": {
41
+ params: UsersInfoParams;
42
+ response: UsersInfoResponse;
43
+ };
21
44
  }
22
45
  export type SlackAPIMethod = keyof SlackWebAPIMap;
23
46
  export type SlackAPIParams<Method extends SlackAPIMethod> = SlackWebAPIMap[Method]["params"] & {
@@ -29,4 +52,5 @@ export type SlackAPIResponse<Method extends SlackAPIMethod> = {
29
52
  } | ({
30
53
  ok: true;
31
54
  } & SlackWebAPIMap[Method]["response"]);
55
+ export declare const POST_METHODS: SlackAPIMethod[];
32
56
  //# sourceMappingURL=index.d.ts.map
@@ -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;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,CA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AA;IACD,uBAAuB,EAAE;QACxB,MAAM,EAAE,0BAA0B,CAAA;QAClC,QAAQ,EAAE,4BAA4B,CAAA;KACtC,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;IACD,YAAY,EAAE;QACb,MAAM,EAAE,eAAe,CAAA;QACvB,QAAQ,EAAE,iBAAiB,CAAA;KAC3B,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
@@ -1 +1,5 @@
1
- export {};
1
+ export const POST_METHODS = [
2
+ 'apps.connections.open',
3
+ 'chat.postMessage',
4
+ 'files.completeUploadExternal',
5
+ ];
@@ -0,0 +1,79 @@
1
+ import type { PlainTextElement } from "@slack/types";
2
+ import type { AnyMessage } from "../types/message.js";
3
+ export interface BlockActions {
4
+ type: "block_actions";
5
+ user: {
6
+ id: string;
7
+ username: string;
8
+ name: string;
9
+ team_id: string;
10
+ };
11
+ api_app_id: string;
12
+ token: string;
13
+ container: BlockActionContainer;
14
+ trigger_id: string;
15
+ team: {
16
+ id: string;
17
+ domain: string;
18
+ enterprise_id?: string;
19
+ enterprise_name?: string;
20
+ };
21
+ enterprise?: {
22
+ id: string;
23
+ name: string;
24
+ };
25
+ is_enterprise_install?: boolean;
26
+ channel?: {
27
+ id: string;
28
+ name: string;
29
+ };
30
+ message?: AnyMessage;
31
+ state?: {
32
+ values: Record<string, Record<string, unknown>>;
33
+ };
34
+ response_url?: string;
35
+ actions: BlockAction[];
36
+ }
37
+ interface MessageAttachmentContainer {
38
+ type: "message_attachment";
39
+ message_ts: string;
40
+ attachment_id: number;
41
+ channel_id: string;
42
+ is_ephemeral: boolean;
43
+ is_app_unfurl: boolean;
44
+ }
45
+ interface ViewContainer {
46
+ type: "view";
47
+ view_id: string;
48
+ }
49
+ interface MessageContainer {
50
+ type: "message";
51
+ message_ts: string;
52
+ channel_id: string;
53
+ is_ephemeral: boolean;
54
+ }
55
+ type BlockActionContainer = MessageAttachmentContainer | ViewContainer | MessageContainer;
56
+ interface ActionCommon {
57
+ block_id: string;
58
+ action_id: string;
59
+ action_ts: string;
60
+ }
61
+ export interface ButtonAction extends ActionCommon {
62
+ type: "button";
63
+ text: PlainTextElement;
64
+ value?: string;
65
+ style?: "primary" | "danger";
66
+ }
67
+ export interface PlainTextInputAction extends ActionCommon {
68
+ type: "plain_text_input";
69
+ value: string | null;
70
+ }
71
+ export type BlockAction = ButtonAction | PlainTextInputAction;
72
+ export type BlockActionTypes = BlockAction["type"];
73
+ export type BlockActionMap = {
74
+ [K in BlockActionTypes]: BlockAction & {
75
+ type: K;
76
+ };
77
+ };
78
+ export {};
79
+ //# sourceMappingURL=block_actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_actions.d.ts","sourceRoot":"","sources":["../../../src/api/interactive/block_actions.ts"],"names":[],"mappings":"AAAA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AE,OAAO,CAAA;IACrB,aAAa,EAAE,OAAO,CAAA;CACtB;AAED,UAAU,aAAa;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CACf;AAED,UAAU,gBAAgB;IACzB,IAAI,EAAE,SAAS,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;CACrB;AAED,KAAK,oBAAoB,GAAG,0BAA0B,GAAG,aAAa,GAAG,gBAAgB,CAAA;AAEzF,UAAU,YAAY;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,YAAa,SAAQ,YAAY;IACjD,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,gBAAgB,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;CAC5B;AAED,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACzD,IAAI,EAAE,kBAAkB,CAAA;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,oBAAoB,CAAA;AAE7D,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;AAElD,MAAM,MAAM,cAAc,GAAG;KAC3B,CAAC,IAAI,gBAAgB,GAAG,WAAW,GAAG;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE;CAClD,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ export interface User {
2
+ id: string;
3
+ team_id: string;
4
+ name: string;
5
+ deleted: boolean;
6
+ color: string;
7
+ real_name: string;
8
+ tz: string;
9
+ tz_label: string;
10
+ tz_offset: number;
11
+ profile: UserProfile;
12
+ is_admin: boolean;
13
+ is_owner: boolean;
14
+ is_primary_owner: boolean;
15
+ is_restricted: boolean;
16
+ is_ultra_restricted: boolean;
17
+ is_bot: boolean;
18
+ updated: number;
19
+ is_app_user: boolean;
20
+ has_2fa: boolean;
21
+ }
22
+ export interface UserProfile {
23
+ real_name: string;
24
+ display_name?: string;
25
+ avatar_hash?: string;
26
+ real_name_normalized: string;
27
+ display_name_normalized?: string;
28
+ image_24: string;
29
+ image_32: string;
30
+ image_48: string;
31
+ image_72: string;
32
+ image_192: string;
33
+ image_512: string;
34
+ image_original?: string;
35
+ first_name?: string;
36
+ last_name?: string;
37
+ team: string;
38
+ email?: string;
39
+ title?: string;
40
+ pronouns?: string;
41
+ phone?: string;
42
+ skype?: string;
43
+ status_text?: string;
44
+ status_text_canonical?: string;
45
+ status_emoji?: string;
46
+ status_emoji_display_info?: {
47
+ emoji_name: string;
48
+ display_url: string;
49
+ }[];
50
+ status_expiration?: number;
51
+ huddle_state?: string;
52
+ huddle_state_expiration_ts?: number;
53
+ }
54
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/types/user.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,WAAW,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,gBAAgB,EAAE,OAAO,CAAA;IACzB,aAAa,EAAE,OAAO,CAAA;IACtB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,MAAM,EAAE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face AppsConnectionsOpenResponse {
4
+ url: string;
5
+ }
6
+ //# sourceMappingURL=apps.d.ts.map
@@ -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 {};
@@ -1,4 +1,5 @@
1
- import type { NormalMessage } from "../types/message.js";
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,16 +7,16 @@ interface MarkdownMessage {
6
7
  }
7
8
  type TextMessage = {
8
9
  markdown_text?: never;
9
- blocks?: unknown[];
10
+ blocks?: KnownBlock[];
10
11
  text?: string;
11
12
  } & ({
12
- blocks: unknown[];
13
+ blocks: KnownBlock[];
13
14
  } | {
14
15
  text: string;
15
16
  });
16
17
  export type ChatPostMessageParams = {
17
18
  channel: string;
18
- attachments?: unknown[];
19
+ attachments?: Attachment[];
19
20
  icon_emoji?: string;
20
21
  icon_url?: string;
21
22
  link_names?: boolean;
@@ -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;AAErD,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,OAAO,EAAE,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,CAAC;IAAE,MAAM,EAAE,OAAO,E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,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"}
@@ -20,6 +20,18 @@ export interface ConversationsInfoParams {
20
20
  export interface ConversationsInfoResponse {
21
21
  channel: Conversation;
22
22
  }
23
+ export interface ConversationsHistoryParams extends CursorPaginationParams, TimestampPaginationParams {
24
+ /** Conversation ID to fetch history for. */
25
+ channel: string;
26
+ /** Return all metadata associated with this message. */
27
+ include_all_metadata?: boolean;
28
+ }
29
+ export interface ConversationsHistoryResponse extends CursorPaginationResponse {
30
+ messages: AnyMessage[];
31
+ pin_count: number;
32
+ channel_actions_ts?: number | null;
33
+ channel_actions_count?: number;
34
+ }
23
35
  export interface ConversationsRepliesParams extends CursorPaginationParams, TimestampPaginationParams {
24
36
  /** Conversation ID to fetch thread from. */
25
37
  channel: string;
@@ -1 +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"}
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,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC7E,QAAQ,EAAE,UAAU,EAAE,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC9B;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,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 {};
@@ -0,0 +1,11 @@
1
+ import type { User } from "../types/user.js";
2
+ export interface UsersInfoParams {
3
+ /** User to get info on */
4
+ user: string;
5
+ /** Set this to `true` to receive the locale for this user. Defaults to `false` */
6
+ include_locale?: boolean;
7
+ }
8
+ export interface UsersInfoResponse {
9
+ user: User;
10
+ }
11
+ //# sourceMappingURL=users.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../src/api/web/users.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEzC,MAAM,WAAW,eAAe;IAC/B,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IAEZ,kFAAkF;IAClF,cAAc,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,IAAI,CAAA;CACV"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/client.d.ts CHANGED
@@ -1,11 +1,66 @@
1
1
  import { ChannelRef } from "./resources/channel.js";
2
- import type { SlackAPIMethod, SlackAPIParams, SlackAPIResponse } from "./api/index.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, AllEventTypes, EventWrapper, SlackEventMap } from "./events/types/index.js";
6
+ import { type MessageInstance } from "./resources/message.js";
7
+ import type { MessageEvent } from "./events/types/events.js";
8
+ import type { BlockAction, BlockActionMap, BlockActions, BlockActionTypes } from "./api/interactive/block_actions.js";
9
+ import EventEmitter from "events";
10
+ import { Action, type ActionInstance } from "./resources/action.js";
11
+ type ReceiverOptions = ({
12
+ type: "socket";
13
+ } & DistributiveOmit<SocketEventsReceiverOptions, "client">) | {
14
+ type: "dummy";
15
+ options?: never;
16
+ };
3
17
  interface AppOptions {
4
18
  token?: string;
19
+ receiver?: ReceiverOptions;
5
20
  }
6
- export declare class App {
21
+ export type MessageCallbackData = {
22
+ message: MessageInstance;
23
+ client: App;
24
+ event: EventWrapper<MessageEvent>;
25
+ };
26
+ export type MessageCallback = (data: MessageCallbackData) => unknown;
27
+ export type EventCallbackData<Event extends AllEvents> = {
28
+ client: App;
29
+ event: EventWrapper<Event>;
30
+ };
31
+ export type EventCallback<Event extends AllEvents> = (data: EventCallbackData<Event>) => unknown;
32
+ export type BlockActionCallback<Type extends BlockAction> = (data: Action<Type>) => unknown;
33
+ export declare class App extends EventEmitter<AppEventMap> {
7
34
  #private;
8
- constructor({ token }: AppOptions);
35
+ constructor({ token, receiver }?: AppOptions);
36
+ /**
37
+ * Registers a callback for `message` events.
38
+ *
39
+ * @param callback Function to execute when a new message is received
40
+ */
41
+ message(callback: MessageCallback): void;
42
+ /**
43
+ * Registers a callback for a given type of event.
44
+ *
45
+ * @param type Type of event to register
46
+ * @param callback Function to execute when the event is received
47
+ */
48
+ event<Event extends AllEvents>(type: Event["type"], callback: EventCallback<Event>): void;
49
+ /**
50
+ * Registers a callback for a given type of block actions.
51
+ *
52
+ * For more powerful callbacks, use `app.on('action:button', ...)`, `app.on('action.action_id',
53
+ * ...)`, or `app.on('action:button.action_id', ...)` instead.
54
+ *
55
+ * @param type Type of event to register
56
+ * @param callback Function to execute when the event is received
57
+ */
58
+ action<Type extends BlockAction>(type: Type["type"], callback: BlockActionCallback<Type>): void;
59
+ /**
60
+ * Starts the event receiver. If you don't use the events, interactions, and slash command APIs,
61
+ * you don't need to call this function.
62
+ */
63
+ start(): Promise<void>;
9
64
  /**
10
65
  * Gets a channel reference object. You can use this object to call API methods, or `await` it to
11
66
  * fetch channel details.
@@ -22,9 +77,39 @@ export declare class App {
22
77
  * @param [method='GET'] The HTTP method for the request. Default is `'GET'`
23
78
  * @returns The response from the API call
24
79
  */
25
- request<Method extends SlackAPIMethod>(endpoint: Method, params: SlackAPIParams<Method>, method?: string): Promise<SlackAPIResponse<Method> & {
80
+ request<Method extends SlackAPIMethod>(endpoint: Method, params: SlackAPIParams<Method>, method?: "GET" | "POST"): Promise<SlackAPIResponse<Method> & {
26
81
  ok: true;
27
82
  }>;
28
83
  }
84
+ type AppEventMap = {
85
+ event: [
86
+ EventWrapper
87
+ ];
88
+ actions: [
89
+ BlockActions
90
+ ];
91
+ action: [
92
+ ActionInstance
93
+ ];
94
+ } & {
95
+ [K in AllEventTypes as `event:${K}`]: [
96
+ {
97
+ payload: SlackEventMap[K];
98
+ event: EventWrapper<SlackEventMap[K]>;
99
+ }
100
+ ];
101
+ } & {
102
+ [K in BlockActionTypes as `action:${K}`]: [
103
+ ActionInstance<BlockActionMap[K]>
104
+ ];
105
+ } & {
106
+ [K in `action.${string}`]: [
107
+ ActionInstance
108
+ ];
109
+ } & {
110
+ [K in BlockActionTypes as `action:${K}.${string}`]: [
111
+ ActionInstance<BlockActionMap[K]>
112
+ ];
113
+ };
29
114
  export {};
30
115
  //# sourceMappingURL=client.d.ts.map
@@ -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,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,E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AS,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;AAED,KAAK,WAAW,GAAG;IAClB,KAAK,EAAE,CAAC,YAAY,CAAC,CAAA;IACrB,OAAO,EAAE,CAAC,YAAY,CAAC,CAAA;IACvB,MAAM,EAAE,CAAC,cAAc,CAAC,CAAA;CACxB,GAAG;KACF,CAAC,IAAI,aAAa,IAAI,SAAS,CAAC,EAAE,GAAG;QACrC;YAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;YAAC,KAAK,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;SAAE;KACpE;CACD,GAAG;KACF,CAAC,IAAI,gBAAgB,IAAI,UAAU,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7E,GAAG;KACF,CAAC,IAAI,UAAU,MAAM,EAAE,GAAG,CAAC,cAAc,CAAC;CAC3C,GAAG;KACF,CAAC,IAAI,gBAAgB,IAAI,UAAU,CAAC,IAAI,MAAM,EAAE,GAAG,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;CACvF,CAAA"}
package/dist/client.js CHANGED
@@ -1,10 +1,91 @@
1
1
  import { sleep } from "./utils/index.js";
2
2
  import { ChannelRef } from "./resources/channel.js";
3
3
  import { SlackWebAPIError, SlackWebAPIPlatformError } from "./error.js";
4
- export class App {
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";
8
+ import EventEmitter from "events";
9
+ import { Action } from "./resources/action.js";
10
+ export class App extends EventEmitter {
5
11
  #token;
6
- constructor({ token }) {
12
+ #receiver;
13
+ constructor({ token, receiver = { type: "dummy" } } = {}) {
14
+ super({ captureRejections: true });
15
+ this.on("error", this.#onCallbackError.bind(this));
7
16
  this.#token = token;
17
+ switch (receiver.type) {
18
+ case "socket":
19
+ this.#receiver = new SocketEventsReceiver({ ...receiver, client: this });
20
+ break;
21
+ default:
22
+ this.#receiver = new DummyReceiver();
23
+ }
24
+ this.#receiver.on("event", this.#onEvent.bind(this));
25
+ this.#receiver.on("block_actions", this.#onBlockActions.bind(this));
26
+ }
27
+ async #onEvent(event) {
28
+ this.emit("event", event);
29
+ this.emit(`event:${event.event.type}`, { payload: event.event, event: event });
30
+ }
31
+ async #onBlockActions(event) {
32
+ this.emit("actions", event);
33
+ for (const action of event.actions) {
34
+ const obj = new Action(this, action, event);
35
+ this.emit(`action:${action.type}`, obj);
36
+ this.emit(`action.${action.action_id}`, obj);
37
+ this.emit(`action:${action.type}.${action.action_id}`, obj);
38
+ }
39
+ }
40
+ async #onCallbackError(error) {
41
+ console.error("Error occurred executing callback");
42
+ console.error(error);
43
+ }
44
+ /**
45
+ * Registers a callback for `message` events.
46
+ *
47
+ * @param callback Function to execute when a new message is received
48
+ */
49
+ message(callback) {
50
+ this.on("event:message", async ({ event, payload }) => {
51
+ await callback({
52
+ event,
53
+ message: new Message(this, payload.channel, payload.ts, payload),
54
+ client: this,
55
+ });
56
+ });
57
+ }
58
+ /**
59
+ * Registers a callback for a given type of event.
60
+ *
61
+ * @param type Type of event to register
62
+ * @param callback Function to execute when the event is received
63
+ */
64
+ event(type, callback) {
65
+ this.on(`event:${type}`, async ({ event }) => {
66
+ await callback({ event: event, client: this });
67
+ });
68
+ }
69
+ /**
70
+ * Registers a callback for a given type of block actions.
71
+ *
72
+ * For more powerful callbacks, use `app.on('action:button', ...)`, `app.on('action.action_id',
73
+ * ...)`, or `app.on('action:button.action_id', ...)` instead.
74
+ *
75
+ * @param type Type of event to register
76
+ * @param callback Function to execute when the event is received
77
+ */
78
+ action(type, callback) {
79
+ this.on(`action:${type}`, async (action) => {
80
+ await callback(action);
81
+ });
82
+ }
83
+ /**
84
+ * Starts the event receiver. If you don't use the events, interactions, and slash command APIs,
85
+ * you don't need to call this function.
86
+ */
87
+ async start() {
88
+ await this.#receiver.start();
8
89
  }
9
90
  /**
10
91
  * Gets a channel reference object. You can use this object to call API methods, or `await` it to
@@ -24,7 +105,7 @@ export class App {
24
105
  * @param [method='GET'] The HTTP method for the request. Default is `'GET'`
25
106
  * @returns The response from the API call
26
107
  */
27
- async request(endpoint, params, method = "GET") {
108
+ async request(endpoint, params, method = POST_METHODS.includes(endpoint) ? "POST" : "GET") {
28
109
  const body = method !== "GET" ? JSON.stringify(params) : undefined;
29
110
  const url = new URL(`https://slack.com/api/${endpoint}`);
30
111
  if (method === "GET" && params) {
@@ -34,7 +115,7 @@ export class App {
34
115
  url.searchParams.append(key, item);
35
116
  }
36
117
  }
37
- else {
118
+ else if (value !== undefined && value !== null) {
38
119
  url.searchParams.set(key, String(value));
39
120
  }
40
121
  }
package/dist/error.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export declare class SlackError extends Error {
2
2
  }
3
+ export declare class SlackTimeoutError extends Error {
4
+ }
3
5
  export declare class SlackWebAPIError extends SlackError {
4
6
  url: string;
5
7
  data?: unknown | undefined;
@@ -1 +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"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;CAAG;AAExC,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAE/C,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"}