slack.ts 0.0.3 → 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 (42) hide show
  1. package/README.md +12 -0
  2. package/dist/api/index.d.ts +10 -1
  3. package/dist/api/index.d.ts.map +1 -1
  4. package/dist/api/interactive/block_actions.d.ts +79 -0
  5. package/dist/api/interactive/block_actions.d.ts.map +1 -0
  6. package/dist/api/interactive/block_actions.js +1 -0
  7. package/dist/api/types/user.d.ts +54 -0
  8. package/dist/api/types/user.d.ts.map +1 -0
  9. package/dist/api/types/user.js +1 -0
  10. package/dist/api/web/conversations.d.ts +12 -0
  11. package/dist/api/web/conversations.d.ts.map +1 -1
  12. package/dist/api/web/users.d.ts +11 -0
  13. package/dist/api/web/users.d.ts.map +1 -0
  14. package/dist/api/web/users.js +1 -0
  15. package/dist/client.d.ts +50 -8
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +44 -23
  18. package/dist/error.d.ts +2 -0
  19. package/dist/error.d.ts.map +1 -1
  20. package/dist/error.js +2 -0
  21. package/dist/events/receivers/socket.d.ts.map +1 -1
  22. package/dist/events/receivers/socket.js +10 -1
  23. package/dist/events/types/index.d.ts +4 -0
  24. package/dist/events/types/index.d.ts.map +1 -1
  25. package/dist/resources/action.d.ts +13 -0
  26. package/dist/resources/action.d.ts.map +1 -0
  27. package/dist/resources/action.js +22 -0
  28. package/dist/resources/channel.d.ts +23 -1
  29. package/dist/resources/channel.d.ts.map +1 -1
  30. package/dist/resources/channel.js +37 -0
  31. package/dist/resources/message.d.ts +95 -0
  32. package/dist/resources/message.d.ts.map +1 -1
  33. package/dist/resources/message.js +145 -1
  34. package/dist/resources/user.d.ts +38 -0
  35. package/dist/resources/user.d.ts.map +1 -0
  36. package/dist/resources/user.js +41 -0
  37. package/dist/utils/respond.d.ts +26 -0
  38. package/dist/utils/respond.d.ts.map +1 -0
  39. package/dist/utils/respond.js +63 -0
  40. package/dist/utils/typing.d.ts +1 -0
  41. package/dist/utils/typing.d.ts.map +1 -1
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -4,6 +4,16 @@ 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
 
@@ -19,3 +29,5 @@ app.message(async ({ message }) => {
19
29
 
20
30
  await app.start()
21
31
  ```
32
+
33
+ For more examples, see [the examples directory](./examples).
@@ -1,8 +1,9 @@
1
1
  import type { AppsConnectionsOpenParams, AppsConnectionsOpenResponse } from "./web/apps.js";
2
2
  import type { AuthTestParams, AuthTestResponse } from "./web/auth.js";
3
3
  import type { ChatPostMessageParams, ChatPostMessageResponse } from "./web/chat.js";
4
- import type { ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from "./web/conversations.js";
4
+ import type { ConversationsHistoryParams, ConversationsHistoryResponse, ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from "./web/conversations.js";
5
5
  import type { FilesCompleteUploadExternalParams, FilesCompleteUploadExternalResponse, FilesGetUploadURLExternalParams, FilesGetUploadURLExternalResponse } from "./web/files.js";
6
+ import type { UsersInfoParams, UsersInfoResponse } from "./web/users.js";
6
7
  export interface SlackWebAPIMap {
7
8
  "apps.connections.open": {
8
9
  params: AppsConnectionsOpenParams;
@@ -20,6 +21,10 @@ export interface SlackWebAPIMap {
20
21
  params: ConversationsInfoParams;
21
22
  response: ConversationsInfoResponse;
22
23
  };
24
+ "conversations.history": {
25
+ params: ConversationsHistoryParams;
26
+ response: ConversationsHistoryResponse;
27
+ };
23
28
  "conversations.replies": {
24
29
  params: ConversationsRepliesParams;
25
30
  response: ConversationsRepliesResponse;
@@ -32,6 +37,10 @@ export interface SlackWebAPIMap {
32
37
  params: FilesGetUploadURLExternalParams;
33
38
  response: FilesGetUploadURLExternalResponse;
34
39
  };
40
+ "users.info": {
41
+ params: UsersInfoParams;
42
+ response: UsersInfoResponse;
43
+ };
35
44
  }
36
45
  export type SlackAPIMethod = keyof SlackWebAPIMap;
37
46
  export type SlackAPIParams<Method extends SlackAPIMethod> = SlackWebAPIMap[Method]["params"] & {
@@ -1 +1 @@
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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AAK,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"}
@@ -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,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,eAAe,CAAA;IACrB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IACrE,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,oBAAoB,CAAA;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACtF,UAAU,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,OAAO,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACtC,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,KAAK,CAAC,EAAE;QAAE,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M,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,MAA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,EAAE,MAAM,CAAA;IACrB,yBAAyB,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACzE,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,0BAA0B,CAAC,EAAE,MAAM,CAAA;CACnC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -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,Y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B,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,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
@@ -2,9 +2,12 @@ import { ChannelRef } from "./resources/channel.js";
2
2
  import { type SlackAPIMethod, type SlackAPIParams, type SlackAPIResponse } from "./api/index.js";
3
3
  import { type SocketEventsReceiverOptions } from "./events/receivers/socket.js";
4
4
  import type { DistributiveOmit } from "./utils/typing.js";
5
- import type { AllEvents, EventWrapper } from "./events/types/index.js";
5
+ import type { AllEvents, AllEventTypes, EventWrapper, SlackEventMap } from "./events/types/index.js";
6
6
  import { type MessageInstance } from "./resources/message.js";
7
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";
8
11
  type ReceiverOptions = ({
9
12
  type: "socket";
10
13
  } & DistributiveOmit<SocketEventsReceiverOptions, "client">) | {
@@ -15,21 +18,20 @@ interface AppOptions {
15
18
  token?: string;
16
19
  receiver?: ReceiverOptions;
17
20
  }
18
- type MessageCallbackData = {
21
+ export type MessageCallbackData = {
19
22
  message: MessageInstance;
20
23
  client: App;
21
24
  event: EventWrapper<MessageEvent>;
22
25
  };
23
- type MessageCallback = (data: MessageCallbackData) => unknown;
24
- type EventCallbackData<Event extends AllEvents> = {
26
+ export type MessageCallback = (data: MessageCallbackData) => unknown;
27
+ export type EventCallbackData<Event extends AllEvents> = {
25
28
  client: App;
26
29
  event: EventWrapper<Event>;
27
30
  };
28
- type EventCallback<Event extends AllEvents> = (data: EventCallbackData<Event>) => unknown;
29
- export declare class App {
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> {
30
34
  #private;
31
- private messageCallbacks;
32
- private eventCallbacks;
33
35
  constructor({ token, receiver }?: AppOptions);
34
36
  /**
35
37
  * Registers a callback for `message` events.
@@ -44,6 +46,16 @@ export declare class App {
44
46
  * @param callback Function to execute when the event is received
45
47
  */
46
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;
47
59
  /**
48
60
  * Starts the event receiver. If you don't use the events, interactions, and slash command APIs,
49
61
  * you don't need to call this function.
@@ -69,5 +81,35 @@ export declare class App {
69
81
  ok: true;
70
82
  }>;
71
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
+ };
72
114
  export {};
73
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,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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AAA;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
@@ -5,12 +5,14 @@ import { POST_METHODS, } from "./api/index.js";
5
5
  import { SocketEventsReceiver } from "./events/receivers/socket.js";
6
6
  import { DummyReceiver } from "./events/receivers/dummy.js";
7
7
  import { Message } from "./resources/message.js";
8
- export class App {
8
+ import EventEmitter from "events";
9
+ import { Action } from "./resources/action.js";
10
+ export class App extends EventEmitter {
9
11
  #token;
10
12
  #receiver;
11
- messageCallbacks = [];
12
- eventCallbacks = {};
13
13
  constructor({ token, receiver = { type: "dummy" } } = {}) {
14
+ super({ captureRejections: true });
15
+ this.on("error", this.#onCallbackError.bind(this));
14
16
  this.#token = token;
15
17
  switch (receiver.type) {
16
18
  case "socket":
@@ -20,33 +22,38 @@ export class App {
20
22
  this.#receiver = new DummyReceiver();
21
23
  }
22
24
  this.#receiver.on("event", this.#onEvent.bind(this));
25
+ this.#receiver.on("block_actions", this.#onBlockActions.bind(this));
23
26
  }
24
27
  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
- }
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);
41
38
  }
42
39
  }
40
+ async #onCallbackError(error) {
41
+ console.error("Error occurred executing callback");
42
+ console.error(error);
43
+ }
43
44
  /**
44
45
  * Registers a callback for `message` events.
45
46
  *
46
47
  * @param callback Function to execute when a new message is received
47
48
  */
48
49
  message(callback) {
49
- this.messageCallbacks.push(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
+ });
50
57
  }
51
58
  /**
52
59
  * Registers a callback for a given type of event.
@@ -55,9 +62,23 @@ export class App {
55
62
  * @param callback Function to execute when the event is received
56
63
  */
57
64
  event(type, callback) {
58
- if (!this.eventCallbacks[type])
59
- this.eventCallbacks[type] = [];
60
- this.eventCallbacks[type].push(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
+ });
61
82
  }
62
83
  /**
63
84
  * Starts the event receiver. If you don't use the events, interactions, and slash command APIs,
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"}
package/dist/error.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export class SlackError extends Error {
2
2
  }
3
+ export class SlackTimeoutError extends Error {
4
+ }
3
5
  export class SlackWebAPIError extends SlackError {
4
6
  url;
5
7
  data;
@@ -1 +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"}
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;AAG9E,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;IAYvD,KAAK;YAIG,QAAQ;CA0CtB"}
@@ -5,10 +5,15 @@ export class SocketEventsReceiver extends EventEmitter {
5
5
  client;
6
6
  #ws;
7
7
  constructor({ appToken, client }) {
8
- super();
8
+ super({ captureRejections: true });
9
+ this.on('error', this.#onEventError.bind(this));
9
10
  this.#appToken = appToken;
10
11
  this.client = client;
11
12
  }
13
+ #onEventError(error) {
14
+ console.error('[socket-mode] error occurred handling event');
15
+ console.error(error);
16
+ }
12
17
  async start() {
13
18
  await this._connect();
14
19
  }
@@ -31,6 +36,10 @@ export class SocketEventsReceiver extends EventEmitter {
31
36
  this.#ws?.send(JSON.stringify({ envelope_id: data.envelope_id }));
32
37
  this.emit('event', data.payload);
33
38
  }
39
+ else if (data.type === 'interactive') {
40
+ this.#ws?.send(JSON.stringify({ envelope_id: data.envelope_id }));
41
+ this.emit(data.payload.type, data.payload);
42
+ }
34
43
  else if (data.type === 'hello') {
35
44
  console.debug('[socket-mode] received server hello, app id', data.connection_info.app_id);
36
45
  }
@@ -1,5 +1,6 @@
1
1
  import type EventEmitter from "events";
2
2
  import type { AppMentionEvent, MessageEvent } from "./events.js";
3
+ import type { BlockActions } from "../../api/interactive/block_actions.js";
3
4
  export interface EventsReceiver extends EventEmitter<ReceiverEventMap> {
4
5
  start(): unknown;
5
6
  }
@@ -27,6 +28,9 @@ export type ReceiverEventMap = {
27
28
  event: [
28
29
  EventWrapper<AllEvents>
29
30
  ];
31
+ block_actions: [
32
+ BlockActions
33
+ ];
30
34
  };
31
35
  export type AllEvents = AppMentionEvent | MessageEvent;
32
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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,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,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;IAChC,aAAa,EAAE,CAAC,YAAY,CAAC,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,eAAe,GAAG,YAAY,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { BlockAction, BlockActions } from "../api/interactive/block_actions.js";
2
+ import type { App } from "../client.js";
3
+ import { type Responder } from "../utils/respond.js";
4
+ export declare class Action<Type extends BlockAction = BlockAction> {
5
+ #private;
6
+ protected client: App;
7
+ constructor(client: App, action: Type, event: BlockActions);
8
+ get event(): BlockActions;
9
+ get raw(): Type;
10
+ get respond(): Responder<true>;
11
+ }
12
+ export type ActionInstance<Type extends BlockAction = BlockAction> = Action<Type> & Type;
13
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/resources/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AACjF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEhE,qBAAa,MAAM,CAAC,IAAI,SAAS,WAAW,GAAG,WAAW;;IAKxD,SAAS,CAAC,MAAM,EAAE,GAAG;gBAAX,MAAM,EAAE,GAAG,EACrB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,YAAY;IAOpB,IAAI,KAAK,iBAER;IAED,IAAI,GAAG,SAEN;IAED,IAAI,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,CAE7B;CACD;AAED,MAAM,MAAM,cAAc,CAAC,IAAI,SAAS,WAAW,GAAG,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { makeProxy } from "../utils/index.js";
2
+ import { ResponderImpl } from "../utils/respond.js";
3
+ export class Action {
4
+ client;
5
+ #data;
6
+ #event;
7
+ constructor(client, action, event) {
8
+ this.client = client;
9
+ this.#data = action;
10
+ this.#event = event;
11
+ return makeProxy(this, () => this.#data);
12
+ }
13
+ get event() {
14
+ return this.#event;
15
+ }
16
+ get raw() {
17
+ return this.#data;
18
+ }
19
+ get respond() {
20
+ return new ResponderImpl(this.client, this.#event.response_url, this.#event.trigger_id);
21
+ }
22
+ }
@@ -1,9 +1,20 @@
1
+ import type { TimestampPaginationParams } from "../api/types/api.js";
1
2
  import type { Conversation } from "../api/types/conversation.js";
2
3
  import type { NormalMessage } from "../api/types/message.js";
3
4
  import type { App } from "../client.js";
4
5
  import { type SendMessageWithFiles, type SendMessageWithoutFiles } from "../utils/messaging.js";
5
6
  import type { DistributiveOmit } from "../utils/typing.js";
6
7
  import { MessageRef, type MessageInstance } from "./message.js";
8
+ import { UserRef } from "./user.js";
9
+ interface FetchMessagesParams extends Omit<TimestampPaginationParams, "limit"> {
10
+ /**
11
+ * How many messages to fetch in each API call. This will not affect the number of returned
12
+ * messages. Defaults to 100
13
+ */
14
+ batch?: number;
15
+ /** How many messages to return in total. Defaults to unlimited */
16
+ limit?: number;
17
+ }
7
18
  declare class ChannelMixin {
8
19
  #private;
9
20
  protected client: App;
@@ -32,6 +43,15 @@ declare class ChannelMixin {
32
43
  * @returns A message reference object
33
44
  */
34
45
  message(ts: string): MessageRef<import("../api/types/message.js").AnyMessage>;
46
+ /**
47
+ * Fetches messages in the channel. Note that this method only fetches root messages (i.e.,
48
+ * messages not in a thread); to fetch thread replies, use the `replies` method on messages
49
+ * instead.
50
+ *
51
+ * @param params Options for fetching messages
52
+ * @returns An async iterator of messages, from newest to oldest
53
+ */
54
+ messages(params?: FetchMessagesParams): AsyncGenerator<MessageInstance, void, unknown>;
35
55
  }
36
56
  export declare class ChannelRef extends ChannelMixin implements PromiseLike<ChannelInstance> {
37
57
  #private;
@@ -40,7 +60,9 @@ export declare class ChannelRef extends ChannelMixin implements PromiseLike<Chan
40
60
  export declare class Channel extends ChannelMixin {
41
61
  #private;
42
62
  constructor(client: App, id: string, data: Conversation);
63
+ /** A reference to the creator of this channel. Only available for non-DM channels. */
64
+ get creator(): UserRef | undefined;
43
65
  }
44
- export type ChannelInstance = Channel & Conversation;
66
+ export type ChannelInstance = Channel & DistributiveOmit<Conversation, "creator">;
45
67
  export {};
46
68
  //# 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;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,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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;IAMvD,sFAAsF;IACtF,IAAI,OAAO,wBAEV;CACD;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,gBAAgB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import { makeProxy } from "../utils/index.js";
2
2
  import { sendMessage, } from "../utils/messaging.js";
3
3
  import { Message, MessageRef } from "./message.js";
4
+ import { UserRef } from "./user.js";
4
5
  class ChannelMixin {
5
6
  client;
6
7
  #id;
@@ -31,6 +32,38 @@ class ChannelMixin {
31
32
  message(ts) {
32
33
  return new MessageRef(this.client, this.#id, ts);
33
34
  }
35
+ /**
36
+ * Fetches messages in the channel. Note that this method only fetches root messages (i.e.,
37
+ * messages not in a thread); to fetch thread replies, use the `replies` method on messages
38
+ * instead.
39
+ *
40
+ * @param params Options for fetching messages
41
+ * @returns An async iterator of messages, from newest to oldest
42
+ */
43
+ async *messages(params = {}) {
44
+ let remaining = params.limit ?? Infinity;
45
+ let cursor;
46
+ if (remaining <= 0)
47
+ return;
48
+ while (true) {
49
+ const batch = await this.client.request("conversations.history", {
50
+ channel: this.#id,
51
+ latest: params.latest,
52
+ oldest: params.oldest,
53
+ inclusive: params.inclusive,
54
+ limit: Math.min(remaining, params.batch ?? 100),
55
+ cursor,
56
+ });
57
+ for (const message of batch.messages) {
58
+ yield new Message(this.client, this.#id, message.ts, message);
59
+ if (--remaining <= 0)
60
+ return;
61
+ }
62
+ cursor = batch.response_metadata?.next_cursor;
63
+ if (!batch.has_more || !cursor)
64
+ return;
65
+ }
66
+ }
34
67
  }
35
68
  export class ChannelRef extends ChannelMixin {
36
69
  then(onfulfilled, onrejected) {
@@ -48,4 +81,8 @@ export class Channel extends ChannelMixin {
48
81
  this.#data = data;
49
82
  return makeProxy(this, () => this.#data);
50
83
  }
84
+ /** A reference to the creator of this channel. Only available for non-DM channels. */
85
+ get creator() {
86
+ return this.#data.creator ? new UserRef(this.client, this.#data.creator) : undefined;
87
+ }
51
88
  }
@@ -1,8 +1,33 @@
1
+ import type { BlockAction, BlockActionTypes } from "../api/interactive/block_actions.js";
2
+ import type { TimestampPaginationParams } from "../api/types/api.js";
1
3
  import type { AnyMessage, NormalMessage } from "../api/types/message.js";
2
4
  import type { App } from "../client.js";
3
5
  import { type SendMessageWithFiles, type SendMessageWithoutFiles } from "../utils/messaging.js";
4
6
  import type { DistributiveOmit } from "../utils/typing.js";
7
+ import type { ActionInstance } from "./action.js";
5
8
  import { ChannelRef } from "./channel.js";
9
+ import { UserRef } from "./user.js";
10
+ interface FetchRepliesParams extends Omit<TimestampPaginationParams, "limit"> {
11
+ /**
12
+ * How many replies to fetch in each API call. This will not affect the number of returned
13
+ * messages.
14
+ *
15
+ * @default 100
16
+ */
17
+ batch?: number;
18
+ /**
19
+ * How many replies to return in total.
20
+ *
21
+ * @default Infinity
22
+ */
23
+ limit?: number;
24
+ /**
25
+ * Whether to include the root message in the results.
26
+ *
27
+ * @default true
28
+ */
29
+ root?: boolean;
30
+ }
6
31
  declare class MessageMixin {
7
32
  #private;
8
33
  protected client: App;
@@ -13,6 +38,11 @@ declare class MessageMixin {
13
38
  /** Timestamp of the message */
14
39
  get ts(): string;
15
40
  protected get _threadTs(): string | undefined;
41
+ /**
42
+ * Waits for an event about this message to occur before continuing. To configure the wait object,
43
+ * see its methods (for example, `message.wait.timeout(60000)`).
44
+ */
45
+ get wait(): MessageWait;
16
46
  /**
17
47
  * Sends a message as a reply to this messsage with files.
18
48
  *
@@ -27,6 +57,14 @@ declare class MessageMixin {
27
57
  * @returns The sent message
28
58
  */
29
59
  reply(message: DistributiveOmit<SendMessageWithoutFiles, "channel" | "thread_ts"> | string): Promise<MessageInstance<NormalMessage>>;
60
+ /**
61
+ * Fetches replies in the thread of this message. Note that this method may return the root
62
+ * message by default; set `params.root` to `false` to skip it.
63
+ *
64
+ * @param params Options for fetching replies
65
+ * @returns An async iterator of messages, from oldest to newest
66
+ */
67
+ replies(params?: FetchRepliesParams): AsyncGenerator<MessageInstance, void, unknown>;
30
68
  }
31
69
  export declare class MessageRef<Subtype extends AnyMessage = AnyMessage> extends MessageMixin implements PromiseLike<Message<Subtype>> {
32
70
  #private;
@@ -39,8 +77,65 @@ export declare class Message<Subtype extends AnyMessage = AnyMessage> extends Me
39
77
  isNormal(): this is MessageInstance<NormalMessage>;
40
78
  /** The raw data of this message */
41
79
  get raw(): Subtype;
80
+ /**
81
+ * A reference to the user that created the message. Note that for system messages (such as
82
+ * channel join messages), this may not be the user you expect. Read the Slack documentation to
83
+ * find out.
84
+ */
85
+ get author(): UserRef;
42
86
  protected get _threadTs(): string | undefined;
43
87
  }
44
88
  export type MessageInstance<Subtype extends AnyMessage = AnyMessage> = Message<Subtype> & Subtype;
89
+ declare class MessageWait {
90
+ private message;
91
+ private client;
92
+ private _timeout;
93
+ constructor(message: MessageMixin, client: App);
94
+ /**
95
+ * Sets the timeout of the wait. A `SlackTimeoutError` will be thrown if no matching event occurs
96
+ * after the timeout. Set this to `0` to disable timeouts; i.e., methods will wait forever. (This
97
+ * is dangerous because it creates potential memory leaks!)
98
+ *
99
+ * By default, timeout is set to 10 minutes.
100
+ *
101
+ * @param timeout Timeout in milliseconds
102
+ * @returns `this` for chaining
103
+ */
104
+ timeout(timeout: number): this;
105
+ /**
106
+ * Waits for a block action on this message happened (e.g., a button is pressed).
107
+ *
108
+ * The parameters can be any of any of the following:
109
+ *
110
+ * - An action ID; for example, `'place_order'`.
111
+ * - An event type and an action ID joined with a dot (`.`); for example, `'button.place_order'`.
112
+ * The benefit of using this instead of a plain action ID is, if all string parameters have an
113
+ * event type prefix, the return type of this function will be automatically narrowed to only
114
+ * the possible action types.
115
+ * - A function (`async` or not) that takes in an action and returns `false` if this action should
116
+ * be ignored (useful for permission checks).
117
+ *
118
+ * An action is matched if its container is this message, its `action_id` is one of the parameters
119
+ * passed in, and it passes all the function checks.
120
+ *
121
+ * NOTE: You must specify at least one non-function parameter, since the `action_id` of the action
122
+ * must match one of the arguments.
123
+ *
124
+ * @param specifiers An array of specifiers (see above for their format)
125
+ * @returns The action that occurred that matches the specifiers.
126
+ * @throws `SlackTimeoutError` if timed out before a matched event occurred
127
+ */
128
+ action<ActionIDs extends (string | ActionPredicate)[]>(...specifiers: ActionIDs): Promise<ExtractActionWaitReturnValue<ExtractString<ActionIDs[number]>>>;
129
+ }
130
+ type ActionPredicate = (action: ActionInstance) => boolean | Promise<boolean>;
131
+ type ExtractActionWaitReturnValue<ActionID extends string> = ActionInstance<ExtractWaitActionType<ActionID>>;
132
+ type ExtractWaitActionType<Specifier extends string> = {
133
+ [K in Specifier]: BlockAction & ExtractTypeAndActionID<Specifier>;
134
+ }[Specifier];
135
+ type ExtractTypeAndActionID<T extends string> = T extends `${infer Type extends BlockActionTypes}.${infer ActionID}` ? {
136
+ type: Type;
137
+ action_id: ActionID;
138
+ } : never;
139
+ type ExtractString<T> = T extends string ? T : never;
45
140
  export {};
46
141
  //# 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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cAAc,CAC1E,qBAAqB,CAAC,QAAQ,CAAC,CAC/B,CAAA;AAED,KAAK,qBAAqB,CAAC,SAAS,SAAS,MAAM,IAAI;KACrD,CAAC,IAAI,SAAS,GAAG,WAAW,GAAG,sBAAsB,CAAC,SAAS,CAAC;CACjE,CAAC,SAAS,CAAC,CAAA;AAEZ,KAAK,sBAAsB,CAAC,CAAC,SAAS,MAAM,IAC3C,CAAC,SAAS,GAAG,MAAM,IAAI,SAAS,gBAAgB,IAAI,MAAM,QAAQ,EAAE,GACjE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,QAAQ,CAAA;CAAE,GACnC,KAAK,CAAA;AAET,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAA"}
@@ -1,7 +1,8 @@
1
- import { SlackError } from "../error.js";
1
+ import { SlackError, SlackTimeoutError } from "../error.js";
2
2
  import { makeProxy } from "../utils/index.js";
3
3
  import { sendMessage, } from "../utils/messaging.js";
4
4
  import { ChannelRef } from "./channel.js";
5
+ import { UserRef } from "./user.js";
5
6
  class MessageMixin {
6
7
  client;
7
8
  #channel;
@@ -25,6 +26,13 @@ class MessageMixin {
25
26
  get _threadTs() {
26
27
  return undefined;
27
28
  }
29
+ /**
30
+ * Waits for an event about this message to occur before continuing. To configure the wait object,
31
+ * see its methods (for example, `message.wait.timeout(60000)`).
32
+ */
33
+ get wait() {
34
+ return new MessageWait(this, this.client);
35
+ }
28
36
  async reply(message) {
29
37
  if (typeof message === "string") {
30
38
  message = { text: message };
@@ -38,6 +46,38 @@ class MessageMixin {
38
46
  return new Message(this.client, this.#channel, data.ts, data.message);
39
47
  }
40
48
  }
49
+ /**
50
+ * Fetches replies in the thread of this message. Note that this method may return the root
51
+ * message by default; set `params.root` to `false` to skip it.
52
+ *
53
+ * @param params Options for fetching replies
54
+ * @returns An async iterator of messages, from oldest to newest
55
+ */
56
+ async *replies(params = {}) {
57
+ let remaining = params.limit ?? Infinity;
58
+ let cursor;
59
+ while (true) {
60
+ const batch = await this.client.request("conversations.replies", {
61
+ channel: this.#channel,
62
+ ts: this.#ts,
63
+ latest: params.latest,
64
+ oldest: params.oldest,
65
+ inclusive: params.inclusive,
66
+ limit: params.batch ?? 100,
67
+ cursor,
68
+ });
69
+ for (const message of batch.messages) {
70
+ if (!(params.root ?? true) && message.ts === this.#ts)
71
+ continue;
72
+ yield new Message(this.client, this.#channel, message.ts, message);
73
+ if (--remaining <= 0)
74
+ return;
75
+ }
76
+ cursor = batch.response_metadata?.next_cursor;
77
+ if (!batch.has_more || !cursor)
78
+ return;
79
+ }
80
+ }
41
81
  }
42
82
  export class MessageRef extends MessageMixin {
43
83
  then(onfulfilled, onrejected) {
@@ -72,7 +112,111 @@ export class Message extends MessageMixin {
72
112
  get raw() {
73
113
  return this.#data;
74
114
  }
115
+ /**
116
+ * A reference to the user that created the message. Note that for system messages (such as
117
+ * channel join messages), this may not be the user you expect. Read the Slack documentation to
118
+ * find out.
119
+ */
120
+ get author() {
121
+ return new UserRef(this.client, this.#data.user);
122
+ }
75
123
  get _threadTs() {
76
124
  return this.#data.thread_ts;
77
125
  }
78
126
  }
127
+ class MessageWait {
128
+ message;
129
+ client;
130
+ _timeout = 600000;
131
+ constructor(message, client) {
132
+ this.message = message;
133
+ this.client = client;
134
+ }
135
+ /**
136
+ * Sets the timeout of the wait. A `SlackTimeoutError` will be thrown if no matching event occurs
137
+ * after the timeout. Set this to `0` to disable timeouts; i.e., methods will wait forever. (This
138
+ * is dangerous because it creates potential memory leaks!)
139
+ *
140
+ * By default, timeout is set to 10 minutes.
141
+ *
142
+ * @param timeout Timeout in milliseconds
143
+ * @returns `this` for chaining
144
+ */
145
+ timeout(timeout) {
146
+ this._timeout = timeout;
147
+ return this;
148
+ }
149
+ /**
150
+ * Waits for a block action on this message happened (e.g., a button is pressed).
151
+ *
152
+ * The parameters can be any of any of the following:
153
+ *
154
+ * - An action ID; for example, `'place_order'`.
155
+ * - An event type and an action ID joined with a dot (`.`); for example, `'button.place_order'`.
156
+ * The benefit of using this instead of a plain action ID is, if all string parameters have an
157
+ * event type prefix, the return type of this function will be automatically narrowed to only
158
+ * the possible action types.
159
+ * - A function (`async` or not) that takes in an action and returns `false` if this action should
160
+ * be ignored (useful for permission checks).
161
+ *
162
+ * An action is matched if its container is this message, its `action_id` is one of the parameters
163
+ * passed in, and it passes all the function checks.
164
+ *
165
+ * NOTE: You must specify at least one non-function parameter, since the `action_id` of the action
166
+ * must match one of the arguments.
167
+ *
168
+ * @param specifiers An array of specifiers (see above for their format)
169
+ * @returns The action that occurred that matches the specifiers.
170
+ * @throws `SlackTimeoutError` if timed out before a matched event occurred
171
+ */
172
+ async action(...specifiers) {
173
+ return new Promise((resolve, reject) => {
174
+ const predicates = [];
175
+ const cleanup = () => {
176
+ if (timer) {
177
+ clearTimeout(timer);
178
+ }
179
+ for (const name of subscriptions) {
180
+ this.client.off(name, callback);
181
+ }
182
+ };
183
+ const callback = async (action) => {
184
+ const { event } = action;
185
+ if ((event.container.type === "message" || event.container.type === "message_attachment") &&
186
+ event.container.message_ts === this.message.ts &&
187
+ !(await Promise.all(predicates.map((predicate) => predicate(action)))).filter((v) => !v)
188
+ .length) {
189
+ cleanup();
190
+ resolve(action);
191
+ }
192
+ };
193
+ const subscriptions = [];
194
+ for (const specifier of specifiers) {
195
+ if (typeof specifier === "string") {
196
+ this.client.on(`action.${specifier}`, callback);
197
+ subscriptions.push(`action.${specifier}`);
198
+ const index = specifier.indexOf(".");
199
+ if (index >= 0) {
200
+ const type = specifier.substring(0, index);
201
+ const actionId = specifier.substring(index + 1);
202
+ this.client.on(`action:${type}.${actionId}`, callback);
203
+ subscriptions.push(`action:${type}.${actionId}`);
204
+ }
205
+ }
206
+ else {
207
+ predicates.push(specifier);
208
+ }
209
+ }
210
+ if (!subscriptions.length) {
211
+ reject(new SlackError("No action ID specifiers given"));
212
+ return;
213
+ }
214
+ const timer = this._timeout
215
+ ? setTimeout(() => {
216
+ cleanup();
217
+ reject(new SlackTimeoutError(`Timed out waiting for action (${this._timeout} ms)`));
218
+ }, this._timeout)
219
+ : null;
220
+ });
221
+ }
222
+ }
@@ -0,0 +1,38 @@
1
+ import type { NormalMessage } from "../api/types/message.js";
2
+ import type { User as UserData } from "../api/types/user.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 { type MessageInstance } from "./message.js";
7
+ declare class UserMixin {
8
+ #private;
9
+ protected client: App;
10
+ constructor(client: App, id: string);
11
+ /** ID of the channel */
12
+ get id(): string;
13
+ /**
14
+ * Sends a message in DM with the user 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 DM with the user.
22
+ *
23
+ * @param message The message payload to send, either a mrkdwn-formatted string or an object.
24
+ * @returns The sent message
25
+ */
26
+ send(message: DistributiveOmit<SendMessageWithoutFiles, "channel"> | string): Promise<MessageInstance<NormalMessage>>;
27
+ }
28
+ export declare class UserRef extends UserMixin implements PromiseLike<UserInstance> {
29
+ #private;
30
+ then<TResult1 = UserInstance, TResult2 = never>(onfulfilled?: ((value: UserInstance) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
31
+ }
32
+ export declare class User extends UserMixin {
33
+ #private;
34
+ constructor(client: App, id: string, data: UserData);
35
+ }
36
+ export type UserInstance = User & UserData;
37
+ export {};
38
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/resources/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAs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AE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ;CAKnD;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,QAAQ,CAAA"}
@@ -0,0 +1,41 @@
1
+ import { makeProxy } from "../utils/index.js";
2
+ import { sendMessage, } from "../utils/messaging.js";
3
+ import { Message } from "./message.js";
4
+ class UserMixin {
5
+ client;
6
+ #id;
7
+ constructor(client, id) {
8
+ this.client = client;
9
+ this.#id = id;
10
+ }
11
+ /** ID of the channel */
12
+ get id() {
13
+ return this.#id;
14
+ }
15
+ async send(message) {
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
+ }
24
+ }
25
+ export class UserRef extends UserMixin {
26
+ then(onfulfilled, onrejected) {
27
+ return this.#fetch().then(onfulfilled, onrejected);
28
+ }
29
+ async #fetch() {
30
+ const data = await this.client.request("users.info", { user: this.id });
31
+ return new User(this.client, this.id, data.user);
32
+ }
33
+ }
34
+ export class User extends UserMixin {
35
+ #data;
36
+ constructor(client, id, data) {
37
+ super(client, id);
38
+ this.#data = data;
39
+ return makeProxy(this, () => this.#data);
40
+ }
41
+ }
@@ -0,0 +1,26 @@
1
+ import type { KnownBlock } from "@slack/types";
2
+ import type { App } from "../client.js";
3
+ export declare class ResponderImpl implements Responder {
4
+ private client;
5
+ private response_url;
6
+ private trigger_id;
7
+ constructor(client: App, response_url: string | undefined, trigger_id: string);
8
+ message(message: string | MessageResponseParams): Promise<void>;
9
+ edit(message: string | MessageResponseParams): Promise<void>;
10
+ delete(): Promise<void>;
11
+ }
12
+ export type Responder<HasResponseURL extends boolean = true> = {} & (HasResponseURL extends true ? {
13
+ message(message: string | MessageResponseParams): Promise<void>;
14
+ edit(message: string | MessageResponseParams): Promise<void>;
15
+ delete(): Promise<void>;
16
+ } : {});
17
+ export type MessageResponseParams = {
18
+ ephemeral?: boolean;
19
+ text?: string;
20
+ blocks?: KnownBlock[];
21
+ } & ({
22
+ text: string;
23
+ } | {
24
+ blocks: KnownBlock[];
25
+ });
26
+ //# sourceMappingURL=respond.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"respond.d.ts","sourceRoot":"","sources":["../../src/utils/respond.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAEpC,qBAAa,aAAc,YAAW,SAAS;IAE7C,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,UAAU;gBAFV,MAAM,EAAE,GAAG,EACX,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,UAAU,EAAE,MAAM;IAGrB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB;IAuB/C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB;IAuB5C,MAAM;CAaZ;AAED,MAAM,MAAM,SAAS,CAAC,cAAc,SAAS,OAAO,GAAG,IAAI,IAAI,EAAE,GAAG,CAAC,cAAc,SAAS,IAAI,GAC7F;IACA,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5D,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB,GACA,EAAE,CAAC,CAAA;AAEN,MAAM,MAAM,qBAAqB,GAAG;IACnC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;CACrB,GAAG,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC,CAAA"}
@@ -0,0 +1,63 @@
1
+ import { SlackError } from "../error.js";
2
+ export class ResponderImpl {
3
+ client;
4
+ response_url;
5
+ trigger_id;
6
+ constructor(client, response_url, trigger_id) {
7
+ this.client = client;
8
+ this.response_url = response_url;
9
+ this.trigger_id = trigger_id;
10
+ }
11
+ async message(message) {
12
+ if (!this.response_url)
13
+ throw new SlackError("Cannot respond to this event with a message");
14
+ if (typeof message === "string")
15
+ message = { text: message };
16
+ const payload = {
17
+ text: message.text,
18
+ blocks: message.blocks,
19
+ response_type: message.ephemeral ? "ephemeral" : "in_channel",
20
+ replace_original: false,
21
+ };
22
+ const resp = await fetch(this.response_url, {
23
+ method: "POST",
24
+ headers: { "Content-Type": "application/json; charset=utf-8" },
25
+ body: JSON.stringify(payload),
26
+ });
27
+ if (!resp.ok) {
28
+ throw new SlackError(`Responding to response_url failed with status code ${resp.status}`);
29
+ }
30
+ }
31
+ async edit(message) {
32
+ if (!this.response_url)
33
+ throw new SlackError("Cannot respond to this event with an edit");
34
+ if (typeof message === "string")
35
+ message = { text: message };
36
+ const payload = {
37
+ text: message.text,
38
+ blocks: message.blocks,
39
+ response_type: message.ephemeral ? "ephemeral" : "in_channel",
40
+ replace_original: true,
41
+ };
42
+ const resp = await fetch(this.response_url, {
43
+ method: "POST",
44
+ headers: { "Content-Type": "application/json; charset=utf-8" },
45
+ body: JSON.stringify(payload),
46
+ });
47
+ if (!resp.ok) {
48
+ throw new SlackError(`Responding to response_url failed with status code ${resp.status}`);
49
+ }
50
+ }
51
+ async delete() {
52
+ if (!this.response_url)
53
+ throw new SlackError("Cannot respond to this event with deletion");
54
+ const resp = await fetch(this.response_url, {
55
+ method: "POST",
56
+ headers: { "Content-Type": "application/json; charset=utf-8" },
57
+ body: JSON.stringify({ delete_original: true }),
58
+ });
59
+ if (!resp.ok) {
60
+ throw new SlackError(`Responding to response_url failed with status code ${resp.status}`);
61
+ }
62
+ }
63
+ }
@@ -1,2 +1,3 @@
1
1
  export type DistributiveOmit<T, Key extends keyof any> = T extends any ? Omit<T, Key> : never;
2
+ export type ExtractPrefix<T extends string, PrefixType extends string = string, Sep extends string = ':', IfNotFound = never> = T extends `${infer Prefix extends PrefixType}${Sep}${string}` ? Prefix : IfNotFound;
2
3
  //# sourceMappingURL=typing.d.ts.map
@@ -1 +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"}
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;AAE7F,MAAM,MAAM,aAAa,CACxB,CAAC,SAAS,MAAM,EAChB,UAAU,SAAS,MAAM,GAAG,MAAM,EAClC,GAAG,SAAS,MAAM,GAAG,GAAG,EACxB,UAAU,GAAG,KAAK,IACf,CAAC,SAAS,GAAG,MAAM,MAAM,SAAS,UAAU,GAAG,GAAG,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,UAAU,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slack.ts",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A fully-typed, opinionated Slack API library",
5
5
  "author": "@jollyroger182",
6
6
  "license": "MIT",