Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unfurl_links and unfurl_media to Message #130

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/surfaces/message.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Each instance of the `MessageBuilder` object has chainable setter methods for th

`ts` – *String*

`unfurlLinks` - *Boolean*

`unfurlMedia` - *Boolean*


?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below.

Expand Down
3 changes: 3 additions & 0 deletions src/internal/constants/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export enum Prop {
DeleteOriginal = 'deleteOriginal',
ResponseType = 'responseType',
PostAt = 'postAt',
UnfurlLinks = 'unfurlLinks',
UnfurlLinks = 'unfurlMedia',
Ephemeral = 'ephemeral',
InChannel = 'inChannel',
Ts = 'ts',
Expand All @@ -89,4 +91,5 @@ export enum Prop {
VideoUrl = 'videoUrl',
MaxFiles = 'maxFiles',
Filetypes = 'filetypes',

}
2 changes: 2 additions & 0 deletions src/internal/dto/slack-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export enum Param {
deleteOriginal = 'delete_original',
responseType = 'response_type',
postAt = 'post_at',
unfurlLinks = 'unfurl_links',
unfurlMedia = 'unfurl_media',
color = 'color',
fallback = 'fallback',
attachments = 'attachments',
Expand Down
26 changes: 26 additions & 0 deletions src/internal/methods/set-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,32 @@ export abstract class PostAt extends Builder {
}
}

export abstract class UnfurlLinks extends Builder {
/**
* @description Enables (or disables) unfurling of primarily text-based content.
*
* {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation}
* {@link https://www.blockbuilder.dev|Open Block Builder Documentation}
*/

public unfurlLinks(unfurlLinks: Settable<boolean>): this {
return this.set(unfurlLinks, Prop.UnfurlLinks);
}
}

export abstract class UnfurlMedia extends Builder {
/**
* @description Enables (or disables) unfurling of primarily text-based content.
*
* {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation}
* {@link https://www.blockbuilder.dev|Open Block Builder Documentation}
*/

public unfurlMedia(unfurlMedia: Settable<boolean>): this {
return this.set(unfurlMedia, Prop.UnfurlLinks);
}
}

export abstract class PrivateMetaData extends Builder {
/**
* @description Defines a string sent back to your server with view and interaction payloads.
Expand Down
2 changes: 2 additions & 0 deletions src/surfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export function HomeTab(params?: HomeTabParams): HomeTabBuilder {
* @param {string} [params.text] Text to be displayed in the notification on the Message, or in the body, if there are no Blocks available.
* @param {timestamp} [params.threadTs] Sets the message to be a reply in a thread to the message whose timestamp is passed.
* @param {timestamp} [params.postAt] Sets a time for the message to be posted, as a scheduled message.
* @param {boolean} [params.unfurlLinks] Sets whether Slack should unfurl links in the Message.
* @param {boolean} [params.unfurlMedia] Sets whether Slack should unfurl media in the Message.
*
* {@link https://api.slack.com/messaging/composing|View in Slack API Documentation}
*/
Expand Down
8 changes: 8 additions & 0 deletions src/surfaces/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
GetBlocks,
GetPreviewUrl,
PrintPreviewUrl,
UnfurlLinks,
UnfurlMedia,
} from '../internal/methods';

import type { SlackBlockDto, SlackDto } from '../internal/dto';
Expand All @@ -32,6 +34,8 @@ export interface MessageParams {
text?: string;
threadTs?: string;
ts?: string;
unfurlLinks?: boolean;
unfurlMedia?: boolean;
}

export interface MessageBuilder extends AsUser,
Expand All @@ -47,6 +51,8 @@ export interface MessageBuilder extends AsUser,
Text,
ThreadTs,
Ts,
UnfurlLinks,
UnfurlMedia,
BuildToJSON,
BuildToObject<SlackMessageDto>,
GetAttachments,
Expand Down Expand Up @@ -85,6 +91,8 @@ applyMixins(MessageBuilder, [
Text,
ThreadTs,
Ts,
UnfurlLinks,
UnfurlMedia,
BuildToJSON,
BuildToObject,
GetAttachments,
Expand Down
2 changes: 2 additions & 0 deletions tests/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ export * from './value';
export * from './video-url';
export * from './max-files';
export * from './filetypes';
export * from './unfurl-links';
export * from './unfurl-media';
18 changes: 18 additions & 0 deletions tests/methods/unfurl-links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CompositeBuilderClassConfig } from '../test-config-types';
import { Prop } from '../../src/internal/constants';
import { methodArgMocks } from '../mocks/method-arg-mocks';
import { SlackDto } from '../../src/internal';
import * as checks from '../checks';

export const unfurlLinks = (params: CompositeBuilderClassConfig): void => {
const config = {
...params,
methodArgMock: methodArgMocks.unfurlLinks,
methodName: Prop.UnfurlLinks,
propSetterPropName: Prop.UnfurlLinks,
slackDtoParamName: SlackDto.mapParam(Prop.UnfurlLinks),
};

checks.settableProperty(config);
checks.literalBuild(config);
};
18 changes: 18 additions & 0 deletions tests/methods/unfurl-media.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CompositeBuilderClassConfig } from '../test-config-types';
import { Prop } from '../../src/internal/constants';
import { methodArgMocks } from '../mocks/method-arg-mocks';
import { SlackDto } from '../../src/internal';
import * as checks from '../checks';

export const unfurlMedia = (params: CompositeBuilderClassConfig): void => {
const config = {
...params,
methodArgMock: methodArgMocks.unfurlMedia,
methodName: Prop.UnfurlLinks,
propSetterPropName: Prop.UnfurlLinks,
slackDtoParamName: SlackDto.mapParam(Prop.UnfurlLinks),
};

checks.settableProperty(config);
checks.literalBuild(config);
};
2 changes: 2 additions & 0 deletions tests/mocks/method-arg-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const methodArgMocks = {
asUser: methodArgMocksByType.bool,
threadTs: methodArgMocksByType.string,
ts: methodArgMocksByType.string,
unfurlLinks: methodArgMocksByType.bool,
unfurlMedia: methodArgMocksByType.bool,
replaceOriginal: methodArgMocksByType.bool,
deleteOriginal: methodArgMocksByType.bool,
responseType: methodArgMocksByType.ephemeral,
Expand Down
2 changes: 2 additions & 0 deletions tests/surfaces/message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const methodsConfig = [
methods.ts,
methods.attachments,
methods.ignoreMarkdown,
methods.unfurlLinks,
methods.unfurlMedia,
];

testCompositeBuilderClass({ config, methods: methodsConfig });