Skip to content

Commit a23d1f6

Browse files
committed
feat(message): add unfurlLinks and unfurlMedia methods
Cherry-picked from PR raycharius#130 with bug fixes: - Fixed duplicate UnfurlLinks enum key (should be UnfurlMedia) - Fixed unfurlMedia method using wrong Prop (UnfurlLinks → UnfurlMedia) - Fixed unfurl-media.ts test using wrong Prop references Closes raycharius#119
1 parent 1555ae1 commit a23d1f6

11 files changed

Lines changed: 87 additions & 0 deletions

File tree

docs/surfaces/message.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Each instance of the `MessageBuilder` object has chainable setter methods for th
3333
3434
`ts` – *String*
3535
36+
`unfurlLinks` - *Boolean*
37+
38+
`unfurlMedia` - *Boolean*
39+
3640
3741
?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below.
3842

src/internal/constants/props.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export enum Prop {
6464
DeleteOriginal = 'deleteOriginal',
6565
ResponseType = 'responseType',
6666
PostAt = 'postAt',
67+
UnfurlLinks = 'unfurlLinks',
68+
UnfurlMedia = 'unfurlMedia',
6769
Ephemeral = 'ephemeral',
6870
InChannel = 'inChannel',
6971
Ts = 'ts',
@@ -89,4 +91,5 @@ export enum Prop {
8991
VideoUrl = 'videoUrl',
9092
MaxFiles = 'maxFiles',
9193
Filetypes = 'filetypes',
94+
9295
}

src/internal/dto/slack-dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export enum Param {
6666
deleteOriginal = 'delete_original',
6767
responseType = 'response_type',
6868
postAt = 'post_at',
69+
unfurlLinks = 'unfurl_links',
70+
unfurlMedia = 'unfurl_media',
6971
color = 'color',
7072
fallback = 'fallback',
7173
attachments = 'attachments',

src/internal/methods/set-methods.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,32 @@ export abstract class PostAt extends Builder {
561561
}
562562
}
563563

564+
export abstract class UnfurlLinks extends Builder {
565+
/**
566+
* @description Enables (or disables) unfurling of primarily text-based content.
567+
*
568+
* {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation}
569+
* {@link https://www.blockbuilder.dev|Open Block Builder Documentation}
570+
*/
571+
572+
public unfurlLinks(unfurlLinks: Settable<boolean>): this {
573+
return this.set(unfurlLinks, Prop.UnfurlLinks);
574+
}
575+
}
576+
577+
export abstract class UnfurlMedia extends Builder {
578+
/**
579+
* @description Enables (or disables) unfurling of primarily text-based content.
580+
*
581+
* {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation}
582+
* {@link https://www.blockbuilder.dev|Open Block Builder Documentation}
583+
*/
584+
585+
public unfurlMedia(unfurlMedia: Settable<boolean>): this {
586+
return this.set(unfurlMedia, Prop.UnfurlMedia);
587+
}
588+
}
589+
564590
export abstract class PrivateMetaData extends Builder {
565591
/**
566592
* @description Defines a string sent back to your server with view and interaction payloads.

src/surfaces/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export function HomeTab(params?: HomeTabParams): HomeTabBuilder {
3939
* @param {string} [params.text] Text to be displayed in the notification on the Message, or in the body, if there are no Blocks available.
4040
* @param {timestamp} [params.threadTs] Sets the message to be a reply in a thread to the message whose timestamp is passed.
4141
* @param {timestamp} [params.postAt] Sets a time for the message to be posted, as a scheduled message.
42+
* @param {boolean} [params.unfurlLinks] Sets whether Slack should unfurl links in the Message.
43+
* @param {boolean} [params.unfurlMedia] Sets whether Slack should unfurl media in the Message.
4244
*
4345
* {@link https://docs.slack.dev/messaging/composing|View in Slack API Documentation}
4446
*/

src/surfaces/message.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
GetBlocks,
2222
GetPreviewUrl,
2323
PrintPreviewUrl,
24+
UnfurlLinks,
25+
UnfurlMedia,
2426
} from '../internal/methods';
2527

2628
import type { SlackBlockDto, SlackDto } from '../internal/dto';
@@ -32,6 +34,8 @@ export interface MessageParams {
3234
text?: string;
3335
threadTs?: string;
3436
ts?: string;
37+
unfurlLinks?: boolean;
38+
unfurlMedia?: boolean;
3539
}
3640

3741
export interface MessageBuilder extends AsUser,
@@ -47,6 +51,8 @@ export interface MessageBuilder extends AsUser,
4751
Text,
4852
ThreadTs,
4953
Ts,
54+
UnfurlLinks,
55+
UnfurlMedia,
5056
BuildToJSON,
5157
BuildToObject<SlackMessageDto>,
5258
GetAttachments,
@@ -85,6 +91,8 @@ applyMixins(MessageBuilder, [
8591
Text,
8692
ThreadTs,
8793
Ts,
94+
UnfurlLinks,
95+
UnfurlMedia,
8896
BuildToJSON,
8997
BuildToObject,
9098
GetAttachments,

tests/methods/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ export * from './value';
8484
export * from './video-url';
8585
export * from './max-files';
8686
export * from './filetypes';
87+
export * from './unfurl-links';
88+
export * from './unfurl-media';

tests/methods/unfurl-links.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { CompositeBuilderClassConfig } from '../test-config-types';
2+
import { Prop } from '../../src/internal/constants';
3+
import { methodArgMocks } from '../mocks/method-arg-mocks';
4+
import { SlackDto } from '../../src/internal';
5+
import * as checks from '../checks';
6+
7+
export const unfurlLinks = (params: CompositeBuilderClassConfig): void => {
8+
const config = {
9+
...params,
10+
methodArgMock: methodArgMocks.unfurlLinks,
11+
methodName: Prop.UnfurlLinks,
12+
propSetterPropName: Prop.UnfurlLinks,
13+
slackDtoParamName: SlackDto.mapParam(Prop.UnfurlLinks),
14+
};
15+
16+
checks.settableProperty(config);
17+
checks.literalBuild(config);
18+
};

tests/methods/unfurl-media.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { CompositeBuilderClassConfig } from '../test-config-types';
2+
import { Prop } from '../../src/internal/constants';
3+
import { methodArgMocks } from '../mocks/method-arg-mocks';
4+
import { SlackDto } from '../../src/internal';
5+
import * as checks from '../checks';
6+
7+
export const unfurlMedia = (params: CompositeBuilderClassConfig): void => {
8+
const config = {
9+
...params,
10+
methodArgMock: methodArgMocks.unfurlMedia,
11+
methodName: Prop.UnfurlMedia,
12+
propSetterPropName: Prop.UnfurlMedia,
13+
slackDtoParamName: SlackDto.mapParam(Prop.UnfurlMedia),
14+
};
15+
16+
checks.settableProperty(config);
17+
checks.literalBuild(config);
18+
};

tests/mocks/method-arg-mocks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const methodArgMocks = {
6161
asUser: methodArgMocksByType.bool,
6262
threadTs: methodArgMocksByType.string,
6363
ts: methodArgMocksByType.string,
64+
unfurlLinks: methodArgMocksByType.bool,
65+
unfurlMedia: methodArgMocksByType.bool,
6466
replaceOriginal: methodArgMocksByType.bool,
6567
deleteOriginal: methodArgMocksByType.bool,
6668
responseType: methodArgMocksByType.ephemeral,

0 commit comments

Comments
 (0)