-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathchat.ts
More file actions
370 lines (350 loc) · 13.2 KB
/
chat.ts
File metadata and controls
370 lines (350 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import type {
AnyChunk,
Block, // TODO: these will be combined into one in a new types release
EntityMetadata,
KnownBlock,
LinkUnfurls,
MessageAttachment,
MessageMetadata,
} from '@slack/types';
import type { OptionalArgument } from '../helpers';
import type {
CursorPaginationEnabled,
OptionalTeamAssignable,
TimelinePaginationEnabled,
TokenOverridable,
} from './common';
export interface Channel {
/** @description Channel ID for the message. */
channel: string;
}
export interface ChannelAndTS extends Channel {
/** @description Timestamp of the message. */
ts: string;
}
interface ChannelAndMessageTS extends Channel {
/** @description Timestamp of the message. */
message_ts: string;
}
export interface AsUser {
/**
* @description Pass `true` to act as the authed user with {@link https://docs.slack.dev/reference/scopes/chat.write `chat:write:user` scope}.
* Bot users in this context are considered authed users. If unused or `false`, the message will be acted upon with
* {@link https://docs.slack.dev/reference/scopes/chat.write `chat:write:bot` scope}.
*/
as_user?: boolean;
}
export interface LinkNames {
/** @description Find and link channel names and usernames. */
link_names?: boolean;
}
export interface Parse {
/**
* @description Change how messages are treated. Defaults to `none`.
* @see {@link https://docs.slack.dev/messaging/formatting-message-text Formatting: Automatic parsing}.
*/
parse?: 'full' | 'none';
}
interface Text {
/**
* @description Text of the message. If used in conjunction with `blocks` or `attachments`, `text` will be used
* as fallback text for notifications only.
*/
text: string;
}
interface MarkdownText {
/**
* @description Accepts message text formatted in markdown. This argument should not be used in conjunction with `blocks` or `text`. Limit this field to 12,000 characters.
* @example **This is bold text**
*/
markdown_text: string;
}
export interface ChannelAndText extends Channel, Text {}
export interface ChannelAndBlocks extends Channel, Partial<Text> {
/**
* @description An array of structured Blocks.
* @see {@link https://docs.slack.dev/reference/block-kit/blocks Blocks reference}.
*/
blocks: (KnownBlock | Block)[];
}
export interface ChannelAndAttachments extends Channel, Partial<Text> {
/**
* @description An array of structured attachments.
* @see {@link https://docs.slack.dev/messaging/formatting-message-text#attachments Adding secondary attachments}.
*/
attachments: MessageAttachment[];
}
export interface ChannelAndMarkdownText extends Channel, MarkdownText {}
// Models message-creation arguments, user must provide one of the following combinations:
// 1. channel and text
// 2. channel and blocks
// 3. channel and attachments
// 4. channel and markdown_text
type MessageContents = ChannelAndText | ChannelAndBlocks | ChannelAndAttachments | ChannelAndMarkdownText;
export interface ThreadTS {
/**
* @description Provide another message's `ts` value to post this message in a thread. Avoid using a reply's `ts`
* value; use its parent's value instead.
*/
thread_ts: string;
}
export interface WithinThreadReply extends Partial<ThreadTS> {
/**
* @description Used in conjunction with `thread_ts`, when set to `false` will make the reply only visibile within
* a thread.
*/
reply_broadcast?: false;
}
export interface BroadcastedThreadReply extends ThreadTS {
/** @description Used in conjunction with `thread_ts`, when set to `true` will broadcast the reply to the channel. */
reply_broadcast: boolean;
}
// For APIs supporting `reply_broadcast`, there are two options: either a broadcasted threaded reply,
// or not broadcasted. Broadcasted replies are necessarily threaded, so `thread_ts` becomes required.
type ReplyInThread = WithinThreadReply | BroadcastedThreadReply;
export interface ChatPostMessageMetadata {
/**
* @description Object representing message metadata, entity and/or event data to attach to a Slack message.
* Provide 'entities' to set work object entity metadata.
* Provide 'event_type' and 'event_payload' to set event metadata.
*/
metadata?: Partial<MessageMetadata> & {
/**
* @description An array of work object entities.
*/
entities?: EntityMetadata[];
};
}
export interface Metadata {
/** @description Object representing message metadata, which will be made accessible to any user or app. */
metadata?: MessageMetadata;
}
export interface IconEmoji {
as_user?: false;
icon_url?: never;
/**
* @description Emoji to use as the icon for this message. Overrides `icon_url`.
* Can only be used with `as_user` set to `false`.
*/
icon_emoji?: string;
}
export interface IconURL {
as_user?: false;
icon_emoji?: never;
/**
* @description URL to an image to use as the icon for this message. `icon_emoji` takes precendence over this field.
* Can only be used with `as_user` set to `false`.
*/
icon_url?: string;
}
// Can only specify message icon via predefined authorship using one of emoji or URL, but not both.
type Icon = IconEmoji | IconURL;
export interface Username {
as_user?: false;
/** @description Set your bot's username. Can only be used with `as_user` set to `false`. */
username?: string;
}
// This union keys on as_user: if it is undefined or false, then the Icon and Username types should be available
// and adhered to. Otherwise if true, then no icon or username fields should be available.
type Authorship =
| (Icon & Username)
| {
/**
* @description Pass `true` to act as the authed user with {@link https://docs.slack.dev/reference/scopes/chat.write `chat:write:user` scope}.
* Bot users in this context are considered authed users. If unused or `false`, the message will be acted upon with
* {@link https://docs.slack.dev/reference/scopes/chat.write `chat:write:bot` scope}.
*/
as_user: true;
icon_emoji?: never;
icon_url?: never;
};
export interface Unfurls {
/** @description Pass `true` to enable unfurling of primarily text-based content. */
unfurl_links?: boolean;
/** @description Pass `false` to disable unfurling of media content. */
unfurl_media?: boolean;
}
export interface ChatAppendStreamArguments extends TokenOverridable, ChannelAndTS, Partial<MarkdownText> {
/**
* @description An array of {@link https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming chunk objects} to append to the stream.
* Either `markdown_text` or `chunks` is required.
*/
chunks?: AnyChunk[];
}
// https://docs.slack.dev/reference/methods/chat.delete
export interface ChatDeleteArguments extends ChannelAndTS, AsUser, TokenOverridable {}
// https://docs.slack.dev/reference/methods/chat.deleteScheduledMessage
export interface ChatDeleteScheduledMessageArguments extends Channel, AsUser, TokenOverridable {
/** @description The `scheduled_message_id` returned from call to {@link https://docs.slack.dev/reference/methods/chat.scheduleMessage `chat.scheduleMessage`}. */
scheduled_message_id: string;
}
// https://docs.slack.dev/reference/methods/chat.getPermalink
export interface ChatGetPermalinkArguments extends ChannelAndMessageTS, TokenOverridable {}
// https://docs.slack.dev/reference/methods/chat.meMessage
export interface ChatMeMessageArguments extends ChannelAndText, TokenOverridable {}
// https://docs.slack.dev/reference/methods/chat.postEphemeral
export type ChatPostEphemeralArguments = TokenOverridable &
MessageContents & {
/**
* @description `id` of the user who will receive the ephemeral message.
* The user should be in the channel specified by the `channel` argument.
*/
user: string;
} & Authorship &
Parse &
LinkNames &
Partial<ThreadTS>;
// https://docs.slack.dev/reference/methods/chat.postMessage
export type ChatPostMessageArguments = TokenOverridable &
MessageContents &
ReplyInThread &
Authorship &
Parse &
LinkNames &
ChatPostMessageMetadata &
Unfurls & {
/** @description Disable Slack markup parsing by setting to `false`. Enabled by default. */
mrkdwn?: boolean;
};
// https://docs.slack.dev/reference/methods/chat.scheduleMessage
export type ChatScheduleMessageArguments = TokenOverridable &
MessageContents & {
/** @description Unix EPOCH timestamp of time in future to send the message. */
post_at: string | number;
} & ReplyInThread &
Parse &
LinkNames &
AsUser &
Metadata &
Unfurls;
// https://docs.slack.dev/reference/methods/chat.scheduledMessages.list
export type ChatScheduledMessagesListArguments = OptionalArgument<
TokenOverridable &
CursorPaginationEnabled &
OptionalTeamAssignable &
Pick<TimelinePaginationEnabled, 'latest' | 'oldest'> &
Partial<Channel>
>;
export interface ChatStartStreamArguments extends TokenOverridable, Channel, Partial<MarkdownText>, ThreadTS {
/**
* @description An array of {@link https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming chunk objects} to start the stream with.
* Either `markdown_text` or `chunks` is required.
*/
chunks?: AnyChunk[];
/**
* @description The ID of the team that is associated with `recipient_user_id`.
* This is required when starting a streaming conversation outside of a DM.
*/
recipient_team_id?: string;
/**
* @description The ID of the user to receive the streaming conversation messages.
* This is required when starting a streaming conversation outside of a DM.
*/
recipient_user_id?: string;
/**
* @description Specifies how tasks are displayed in the message. A "timeline" displays individual tasks
* with text and "plan" displays all tasks together.
*/
task_display_mode?: string;
/**
* @description Emoji to use as the icon for this message. Overrides `icon_url`.
* @example :chart_with_upwards_trend:
*/
icon_emoji?: string;
/**
* @description Image URL to use as the icon for this message.
* @example http://lorempixel.com/48/48
*/
icon_url?: string;
/**
* @description The bot's username to display.
* @example My Bot
*/
username?: string;
}
export type ChatStopStreamArguments = TokenOverridable &
ChannelAndTS &
Partial<MarkdownText> &
Partial<Metadata> & {
/**
* @description An array of {@link https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming chunk objects} to finish the stream with.
*/
chunks?: AnyChunk[];
/**
* Block formatted elements will be appended to the end of the message.
*/
blocks?: (KnownBlock | Block)[];
};
export interface SourceAndUnfurlID {
/**
* @description The source of the link to unfurl. The source may either be `composer`, when the link is inside the
* message composer, or `conversations_history`, when the link has been posted to a conversation.
*/
source: 'composer' | 'conversations_history';
/**
* @description The ID of the link to unfurl. Both `unfurl_id` and `source` must be provided together, or `channel`
* and `ts` must be provided together.
*/
unfurl_id: string;
}
type UnfurlTarget = ChannelAndTS | SourceAndUnfurlID;
// https://docs.slack.dev/reference/methods/chat.unfurl
export type ChatUnfurlArguments = (ChatUnfurlUnfurls | ChatUnfurlMetadata) &
UnfurlTarget &
TokenOverridable & {
/**
* @description Provide a simply-formatted string to send as an ephemeral message to the user as invitation to
* authenticate further and enable full unfurling behavior. Provides two buttons, Not now or Never ask me again.
*/
user_auth_message?: string;
/**
* @description Set to `true` to indicate the user must install your Slack app to trigger unfurls for this domain.
* Defaults to `false`.
*/
user_auth_required?: boolean;
/**
* @description Send users to this custom URL where they will complete authentication in your app to fully trigger
* unfurling. Value should be properly URL-encoded.
*/
user_auth_url?: string;
/**
* @description Provide a JSON based array of structured blocks presented as URL-encoded string to send as an
* ephemeral message to the user as invitation to authenticate further and enable full unfurling behavior.
*/
user_auth_blocks?: (KnownBlock | Block)[];
};
/**
* @description The `unfurls` param of the `chat.unfurl` API.
*/
interface ChatUnfurlUnfurls {
/**
* @description Object with keys set to URLs featured in the message, pointing to their unfurl
* blocks or message attachments.
*/
unfurls: LinkUnfurls;
}
/**
* @description The `metadata` param of the `chat.unfurl` API.
*/
interface ChatUnfurlMetadata {
/**
* @description Unfurl metadata featuring an array of entities to attach to the message based on URLs featured in the message.
*/
metadata: Partial<MessageMetadata> & {
entities: EntityMetadata[];
};
}
// https://docs.slack.dev/reference/methods/chat.update
export type ChatUpdateArguments = MessageContents & {
/** @description Timestamp of the message to be updated. */
ts: string;
} & TokenOverridable &
AsUser &
LinkNames &
Metadata &
Parse & {
/** @description Array of new file ids that will be sent with this message. */
file_ids?: string[];
/** @description Broadcast an existing thread reply to make it visible to everyone in the channel or conversation. */
reply_broadcast?: boolean;
};