Skip to content

Commit 7849554

Browse files
committed
Update
1 parent a3f8922 commit 7849554

3 files changed

Lines changed: 52 additions & 16 deletions

File tree

packages/types/src/message-metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @description Application-specific data to attach to a Slack message.
33
*/
4-
export interface MessageMetadata extends EventMetadata, EntitiesMetadata {}
4+
export type MessageMetadata = EventMetadata | EntitiesMetadata | (EventMetadata & EntitiesMetadata);
55

66
/**
77
* @description Metadata that represents an event in Slack.
@@ -27,7 +27,7 @@ export interface MessageMetadataEventPayloadObject {
2727
}
2828

2929
/**
30-
* @description Metadata that represents an entity.
30+
* @description An array of entities.
3131
*/
3232
export interface EntitiesMetadata {
3333
entities: EntityMetadata[];

packages/web-api/src/types/request/chat.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { OptionalArgument } from '../helpers';
22

33
import type {
44
Block, // TODO: these will be combined into one in a new types release
5-
EntitiesMetadata,
5+
EntityMetadata,
66
KnownBlock,
77
LinkUnfurls,
88
MessageAttachment,
@@ -221,25 +221,31 @@ export interface SourceAndUnfurlID {
221221
}
222222
type UnfurlTarget = ChannelAndTS | SourceAndUnfurlID;
223223

224-
type ChatUnfurlEntitiesMetadata = EntitiesMetadata & {
225-
/**
226-
* @description The unfurl URL for the entity.
227-
*/
228-
app_unfurl_url?: string;
229-
};
230-
231-
// https://api.slack.com/methods/chat.unfurl
232-
export type ChatUnfurlArguments = {
224+
type ChatUnfurlArgumentUnfurls = {
233225
/**
234226
* @description Object with keys set to URLs featured in the message, pointing to their unfurl
235227
* blocks or message attachments.
236228
*/
237-
unfurls?: LinkUnfurls;
229+
unfurls: LinkUnfurls;
230+
};
231+
232+
type ChatUnfurlArgumentMetadata = {
238233
/**
239234
* @description Array of entities to attach to the message based on URLs featured in the message.
240235
*/
241-
metadata?: ChatUnfurlEntitiesMetadata;
242-
} & UnfurlTarget &
236+
metadata: {
237+
entities: (EntityMetadata & {
238+
/**
239+
* @description The unfurl URL for the entity.
240+
*/
241+
app_unfurl_url: string;
242+
})[];
243+
};
244+
};
245+
246+
// https://api.slack.com/methods/chat.unfurl
247+
export type ChatUnfurlArguments = (ChatUnfurlArgumentUnfurls | ChatUnfurlArgumentMetadata) &
248+
UnfurlTarget &
243249
TokenOverridable & {
244250
/**
245251
* @description Provide a simply-formatted string to send as an ephemeral message to the user as invitation to

packages/web-api/test/types/methods/chat.test-d.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ expectAssignable<Parameters<typeof web.chat.postMessage>>([
399399
reply_broadcast: false, // can send a threaded message and explicitly not broadcast it
400400
},
401401
]);
402+
expectAssignable<Parameters<typeof web.chat.postMessage>>([
403+
{
404+
channel: 'C1234',
405+
blocks: [],
406+
thread_ts: '1234.56',
407+
metadata: {
408+
entities: [
409+
{
410+
entity_type: 'slack#/entities/file',
411+
entity_payload: {},
412+
},
413+
],
414+
},
415+
},
416+
]);
402417
// adding a test for when `reply_broadcast` specific boolean value is not known ahead of time
403418
// https://github.com/slackapi/node-slack-sdk/issues/1859
404419
function wideBooleanTest(b: boolean) {
@@ -546,7 +561,7 @@ expectError(
546561
);
547562
expectError(
548563
web.chat.unfurl({
549-
channel: 'C1234', // missing unfurls
564+
channel: 'C1234', // missing both unfurls and metadata
550565
ts: '1234.56',
551566
}),
552567
);
@@ -600,6 +615,21 @@ expectAssignable<Parameters<typeof web.chat.unfurl>>([
600615
ts: '1234.56',
601616
},
602617
]);
618+
expectAssignable<Parameters<typeof web.chat.unfurl>>([
619+
{
620+
channel: 'C1234',
621+
ts: '1234.56',
622+
metadata: {
623+
entities: [
624+
{
625+
entity_type: '',
626+
entity_payload: {},
627+
app_unfurl_url: 'https://google.com',
628+
},
629+
],
630+
},
631+
},
632+
]);
603633

604634
// chat.update
605635
// -- sad path

0 commit comments

Comments
 (0)