Skip to content

Commit 5e24c9d

Browse files
authored
feat: add support to @slack/types for work objects (#2412)
1 parent a2ef748 commit 5e24c9d

File tree

3 files changed

+301
-1
lines changed

3 files changed

+301
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export interface EntityDetailsRequestedEvent {
2+
type: 'entity_details_requested';
3+
user: string;
4+
trigger_id: string;
5+
link: {
6+
url: string;
7+
domain: string;
8+
};
9+
entity_url: string;
10+
app_unfurl_url?: string;
11+
user_locale: string;
12+
event_ts: string;
13+
external_ref?: {
14+
id: string;
15+
type?: string;
16+
};
17+
message_ts?: string;
18+
thread_ts?: string;
19+
channel?: string;
20+
}

packages/types/src/events/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type {
2525
import type { DNDUpdatedEvent, DNDUpdatedUserEvent } from './dnd';
2626
import type { EmailDomainChangedEvent } from './email';
2727
import type { EmojiChangedEvent } from './emoji';
28+
import type { EntityDetailsRequestedEvent } from './entity-details-requested';
2829
import type {
2930
FileChangeEvent,
3031
FileCommentDeletedEvent,
@@ -144,6 +145,7 @@ export type SlackEvent =
144145
| DNDUpdatedUserEvent
145146
| EmailDomainChangedEvent
146147
| EmojiChangedEvent
148+
| EntityDetailsRequestedEvent
147149
| FileChangeEvent
148150
| FileCommentDeletedEvent
149151
| FileCreatedEvent

packages/types/src/message-metadata.ts

Lines changed: 279 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import type { Option, PlainTextElement, SlackFile } from './block-kit/composition-objects';
2+
3+
// ------------------------------
4+
// Event metadata
5+
// ------------------------------
6+
17
/**
2-
* @description Application-specific data to attach to Slack message.
8+
* @description Application-specific event data to attach to a Slack message.
39
* @see {@link https://docs.slack.dev/messaging/message-metadata Using Metadata}
410
* @see {@link https://docs.slack.dev/messaging/message-metadata Metadata Payload Structure}
511
*/
@@ -20,3 +26,275 @@ export interface MessageMetadata {
2026
export interface MessageMetadataEventPayloadObject {
2127
[key: string]: string | number | boolean;
2228
}
29+
30+
// ------------------------------
31+
// Work object metadata
32+
// ------------------------------
33+
34+
/**
35+
* @description Metadata that represents a work object entity.
36+
*/
37+
export interface EntityMetadata {
38+
/**
39+
* @description Entity type.
40+
*/
41+
entity_type: EntityType | string;
42+
/**
43+
* @description Schema for the given entity type.
44+
*/
45+
entity_payload: {
46+
attributes: EntityAttributes;
47+
fields?: ContentItemEntityFields | FileEntityFields | IncidentEntityFields | TaskEntityFields;
48+
custom_fields?: EntityCustomField[];
49+
slack_file?: FileEntitySlackFile;
50+
display_order?: string[];
51+
actions?: {
52+
primary_actions?: EntityActionButton[];
53+
overflow_actions?: EntityActionButton[];
54+
};
55+
};
56+
/**
57+
* @description Reference (and optional type) used to identify an entity within the developer's system.
58+
*/
59+
external_ref: ExternalRef;
60+
/**
61+
* @description URL used to identify an entity within the developer's system.
62+
*/
63+
url: string;
64+
65+
/**
66+
* @description The exact URL posted in the source message. Required in metadata passed to `chat.unfurl`.
67+
*/
68+
app_unfurl_url?: string;
69+
}
70+
71+
export interface ExternalRef {
72+
id: string;
73+
type?: string;
74+
}
75+
76+
export enum EntityType {
77+
Task = 'slack#/entities/task',
78+
File = 'slack#/entities/file',
79+
Item = 'slack#/entities/item',
80+
Incident = 'slack#/entities/incident',
81+
ContentItem = 'slack#/entities/content_item',
82+
}
83+
84+
export interface FileEntitySlackFile {
85+
id: string;
86+
type?: string;
87+
}
88+
89+
export interface EntityAttributes {
90+
title: {
91+
text: string;
92+
edit?: EntityEditSupport;
93+
};
94+
display_type?: string;
95+
display_id?: string;
96+
product_icon?: EntityIconField;
97+
product_name?: string;
98+
locale?: string;
99+
full_size_preview?: EntityFullSizePreview;
100+
metadata_last_modified?: number;
101+
}
102+
103+
export interface EntityIconField {
104+
alt_text: string;
105+
url?: string;
106+
slack_file?: {
107+
id?: string;
108+
url?: string;
109+
};
110+
}
111+
112+
export interface EntityEditSupport {
113+
enabled: boolean;
114+
placeholder?: PlainTextElement;
115+
hint?: PlainTextElement;
116+
optional?: boolean;
117+
select?: {
118+
current_value?: string;
119+
current_values?: string[];
120+
static_options?: Option[];
121+
fetch_options_dynamically?: boolean;
122+
min_query_length?: number;
123+
};
124+
number?: {
125+
is_decimal_allowed?: boolean;
126+
min_value?: number;
127+
max_value?: number;
128+
};
129+
text?: {
130+
min_length?: number;
131+
max_length?: number;
132+
};
133+
}
134+
135+
export interface EntityFullSizePreview {
136+
is_supported: boolean;
137+
preview_url?: string;
138+
mime_type?: string;
139+
error?: {
140+
code: string;
141+
message?: string;
142+
};
143+
}
144+
145+
export interface FileEntityFields {
146+
preview?: EntityImageField;
147+
created_by?: EntityTypedField;
148+
date_created?: EntityTimestampField;
149+
date_updated?: EntityTimestampField;
150+
last_modified_by?: EntityTypedField;
151+
file_size?: EntityStringField;
152+
mime_type?: EntityStringField;
153+
full_size_preview?: EntityFullSizePreview;
154+
}
155+
156+
export interface TaskEntityFields {
157+
description?: EntityStringField;
158+
created_by?: EntityTypedField;
159+
date_created?: EntityTimestampField;
160+
date_updated?: EntityTimestampField;
161+
assignee?: EntityTypedField;
162+
status?: EntityStringField;
163+
due_date?: EntityTypedField;
164+
priority?: EntityStringField;
165+
}
166+
167+
export interface IncidentEntityFields {
168+
status?: EntityStringField;
169+
priority?: EntityStringField;
170+
urgency?: EntityStringField;
171+
created_by?: EntityTypedField;
172+
assigned_to?: EntityTypedField;
173+
date_created?: EntityTimestampField;
174+
date_updated?: EntityTimestampField;
175+
description?: EntityStringField;
176+
service?: EntityStringField;
177+
}
178+
179+
export interface ContentItemEntityFields {
180+
preview?: EntityImageField;
181+
description?: EntityStringField;
182+
created_by?: EntityTypedField;
183+
date_created?: EntityTimestampField;
184+
date_updated?: EntityTimestampField;
185+
last_modified_by?: EntityTypedField;
186+
}
187+
188+
export interface EntityArrayItemField extends Omit<EntityTypedField, 'type'> {
189+
type?: string;
190+
}
191+
192+
export interface EntityTypedField {
193+
type: string;
194+
label?: string;
195+
value?: string | number;
196+
link?: string;
197+
icon?: EntityIconField;
198+
long?: boolean;
199+
format?: string;
200+
image_url?: string;
201+
slack_file?: SlackFile;
202+
alt_text?: string;
203+
edit?: EntityEditSupport;
204+
tag_color?: string;
205+
user?: EntityUserIDField | EntityUserField;
206+
entity_ref?: EntityRefField;
207+
}
208+
209+
export interface EntityStringField {
210+
value: string;
211+
label?: string;
212+
format?: string;
213+
link?: string;
214+
icon?: EntityIconField;
215+
long?: boolean;
216+
type?: string;
217+
tag_color?: string;
218+
edit?: EntityEditSupport;
219+
}
220+
221+
export interface EntityUserIDField {
222+
user_id: string;
223+
}
224+
225+
export interface EntityUserField {
226+
text: string;
227+
url?: string;
228+
email?: string;
229+
icon?: EntityIconField;
230+
}
231+
232+
export interface EntityRefField {
233+
entity_url: string;
234+
external_ref: ExternalRef;
235+
title: string;
236+
display_type?: string;
237+
icon?: EntityIconField;
238+
}
239+
240+
export interface EntityTimestampField {
241+
value: number;
242+
label?: string;
243+
link?: string;
244+
icon?: EntityIconField;
245+
type?: string;
246+
edit?: EntityEditSupport;
247+
}
248+
249+
export interface EntityImageField {
250+
alt_text: string;
251+
label?: string;
252+
image_url?: string;
253+
slack_file?: SlackFile;
254+
title?: string;
255+
type?: string;
256+
}
257+
258+
export interface EntityCustomField {
259+
label: string;
260+
key: string;
261+
type: CustomFieldType | string;
262+
value?: string | number | EntityArrayItemField[];
263+
link?: string;
264+
icon?: EntityIconField;
265+
long?: boolean;
266+
format?: string;
267+
image_url?: string;
268+
slack_file?: SlackFile;
269+
alt_text?: string;
270+
tag_color?: string;
271+
edit?: EntityEditSupport;
272+
item_type?: string;
273+
user?: EntityUserIDField | EntityUserField;
274+
entity_ref?: EntityRefField;
275+
}
276+
277+
export enum CustomFieldType {
278+
Integer = 'integer',
279+
String = 'string',
280+
Array = 'array',
281+
Date = 'slack#/types/date',
282+
Timestamp = 'slack#/types/timestamp',
283+
Image = 'slack#/types/image',
284+
ChannelId = 'slack#/types/channel_id',
285+
User = 'slack#/types/user',
286+
EntityRef = 'slack#/types/entity_ref',
287+
}
288+
289+
export interface EntityActionButton {
290+
text: string;
291+
action_id: string;
292+
value?: string;
293+
style?: string;
294+
url?: string;
295+
accessibility_label?: string;
296+
processing_state?: {
297+
enabled: boolean;
298+
interstitial_text?: string;
299+
};
300+
}

0 commit comments

Comments
 (0)