diff --git a/.gitignore b/.gitignore index 29f51247..0fef67c9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ coverage/ package-lock.json dist/ docs-generator-dist/ +tmp/ \ No newline at end of file diff --git a/README.md b/README.md index 6147507c..f6867dcb 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ import { Modal, Section, bold, link } from 'slack-block-builder'; `Elements` – UI elements that are used to capture user interaction. -`Bits` – These are composition objects and other bits and pieces from Slack's docs. Included are `Attachment`, `Options`, `OptionGroup`, and `ConfirmationDialog`. They felt like they were deserving of their own category. +`Bits` – These are composition objects and other bits and pieces from Slack's docs. Included are `Attachment`, `Options`, `OptionGroup`, `ConfirmationDialog` and a list of rich text objects. They felt like they were deserving of their own category. `Utilities` – A group of utility functions. See [Utility Functions](#utility-functions). @@ -143,6 +143,10 @@ Below is a list of supported objects and how to access them in **Block Builder** | Input | Block | :white_check_mark: | `Blocks.Input()` | Section | Block | :white_check_mark: | `Blocks.Section()` | Video | Block | :white_check_mark: | `Blocks.Video()` +| Rich Text | Block | :white_check_mark: | `Blocks.RichText()` +| Markdown | Block | :white_check_mark: | `Blocks.Markdown()` +| Table | Block | :white_check_mark: | `Blocks.Table()` +| Context Actions | Block | :white_check_mark: | `Blocks.ContextActions()` | Button | Element | :white_check_mark:️ | `Elements.Button()` | Checkboxes | Element | :white_check_mark: | `Elements.Checkboxes()` | Date Picker | Element | :white_check_mark: | `Elements.DatePicker()` @@ -158,11 +162,41 @@ Below is a list of supported objects and how to access them in **Block Builder** | Select Menus | Element | :white_check_mark: | `Elements.[Type]Select()` | Multi-Select Menus | Element | :white_check_mark: | `Elements.[Type]MultiSelect()` | URL Input | Element | :white_check_mark: | `Elements.NumberInput()` +| Workflow Button | Element | :white_check_mark: | `Elements.WorkflowButton()` +| Icon Button | Element | :white_check_mark: | `Elements.IconButton()` +| Feedback Buttons | Element | :white_check_mark: | `Elements.FeedbackButtons()` +| Rich Text Input | Element | :white_check_mark: | `Elements.RichTextInput()` | Option | Composition Object | :white_check_mark: | `Bits.Option()` | Confirm Dialog | Composition Object | :white_check_mark: | `Bits.ConfirmationDialog()` | Option Group | Composition Object | :white_check_mark: | `Bits.OptionGroup()` +| Rich Text Section | Composition Object | :white_check_mark: | `Bits.RichTextSection()` +| Rich Text List | Composition Object | :white_check_mark: | `Bits.RichTextList()` +| Rich Text Quote | Composition Object | :white_check_mark: | `Bits.RichTextQuote()` +| Rich Text Preformatted | Composition Object | :white_check_mark: | `Bits.RichTextPreformatted()` +| Rich Text Text | Composition Object | :white_check_mark: | `Bits.RichTextText()` +| Rich Text Emoji | Composition Object | :white_check_mark: | `Bits.RichTextEmoji()` +| Rich Text Link | Composition Object | :white_check_mark: | `Bits.RichTextLink()` +| Rich Text User | Composition Object | :white_check_mark: | `Bits.RichTextUser()` +| Rich Text Channel | Composition Object | :white_check_mark: | `Bits.RichTextChannel()` +| Rich Text Usergroup | Composition Object | :white_check_mark: | `Bits.RichTextUsergroup()` +| Rich Text Broadcast | Composition Object | :white_check_mark: | `Bits.RichTextBroadcast()` +| Rich Text Date | Composition Object | :white_check_mark: | `Bits.RichTextDate()` +| Rich Text Color | Composition Object | :white_check_mark: | `Bits.RichTextColor()` +| Rich Text Team | Composition Object | :white_check_mark: | `Bits.RichTextTeam()` | Attachment | Legacy Feature | :white_check_mark: | `Bits.Attachment()` +### Rich Text Block + +The `Rich Text` block is used to display formatted, structured representation of text. It is also the output of the Slack client's WYSIWYG message composer, so all messages sent by end-users will have this format. + +Use this block to include user-defined formatted text in your Block Kit payload. While it is possible to format text with `mrkdwn`, `rich_text` is preferred and allows greater flexibility. + +You might encounter a `rich_text` block in a message payload, as a built-in type in apps created with the Deno Slack SDK, or as output of the `RichTextInput` block element. + +Rich text blocks can be deeply nested. For instance: a `RichTextList` can contain a `RichTextSection` which can contain bold style text. + +?> **Note:** When using `RichText` within a `Table` block, you are restricted to using `RichTextSection`. Other top-level elements like `RichTextList`, `RichTextQuote`, and `RichTextPreformatted` are not supported in table cells. + ### Creating a Simple Interactive Message Let's take a look at how to compose an interactive message. Even though [Slack](https://slack.com) now has modals, these have always been the basis for [Slack](https://slack.com) apps. diff --git a/docs/_sidebar.md b/docs/_sidebar.md index d0f07a1b..de2d85dd 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -33,6 +33,10 @@ * [Input](blocks/input.md "Block Builder – Input – Maintainable JavaScript Code for Slack Block Kit") * [Section](blocks/section.md "Block Builder – Section – Maintainable JavaScript Code for Slack Block Kit") * [Video](blocks/video.md "Block Builder – Video – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text](blocks/rich-text.md "Block Builder – Rich Text – Maintainable JavaScript Code for Slack Block Kit") + * [Markdown](blocks/markdown.md "Block Builder – Markdown – Maintainable JavaScript Code for Slack Block Kit") + * [Table](blocks/table.md "Block Builder – Table – Maintainable JavaScript Code for Slack Block Kit") + * [Context Actions](blocks/context-actions.md "Block Builder – Context Actions – Maintainable JavaScript Code for Slack Block Kit") * **Element References** @@ -60,6 +64,10 @@ * [URL Input](elements/url-input.md "Block Builder – URL Input – Maintainable JavaScript Code for Slack Block Kit") * [User Multi-Select](elements/user-multi-select.md "Block Builder – User Multi-Select – Maintainable JavaScript Code for Slack Block Kit") * [User Select](elements/user-select.md "Block Builder – User Select – Maintainable JavaScript Code for Slack Block Kit") + * [Workflow Button](elements/workflow-button.md "Block Builder – Workflow Button – Maintainable JavaScript Code for Slack Block Kit") + * [Icon Button](elements/icon-button.md "Block Builder – Icon Button – Maintainable JavaScript Code for Slack Block Kit") + * [Feedback Buttons](elements/feedback-buttons.md "Block Builder – Feedback Buttons – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Input](elements/rich-text-input.md "Block Builder – Rich Text Input – Maintainable JavaScript Code for Slack Block Kit") * **Bit References** * [Introduction](bits/introduction.md "Block Builder – Bits – Introduction – Maintainable JavaScript Code for Slack Block Kit") @@ -67,6 +75,20 @@ * [Confirmation Dialog](bits/confirmation-dialog.md "Block Builder – Confirmation Dialog – Maintainable JavaScript Code for Slack Block Kit") * [Option](bits/option.md "Block Builder – Option – Maintainable JavaScript Code for Slack Block Kit") * [Option Group](bits/option-group.md "Block Builder – Option Group – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Section](bits/rich-text-section.md "Block Builder – Rich Text Section – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text List](bits/rich-text-list.md "Block Builder – Rich Text List – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Quote](bits/rich-text-quote.md "Block Builder – Rich Text Quote – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Preformatted](bits/rich-text-preformatted.md "Block Builder – Rich Text Preformatted – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Text](bits/rich-text-text.md "Block Builder – Rich Text Text – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Emoji](bits/rich-text-emoji.md "Block Builder – Rich Text Emoji – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Link](bits/rich-text-link.md "Block Builder – Rich Text Link – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text User](bits/rich-text-user.md "Block Builder – Rich Text User – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Channel](bits/rich-text-channel.md "Block Builder – Rich Text Channel – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Usergroup](bits/rich-text-usergroup.md "Block Builder – Rich Text Usergroup – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Broadcast](bits/rich-text-broadcast.md "Block Builder – Rich Text Broadcast – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Date](bits/rich-text-date.md "Block Builder – Rich Text Date – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Color](bits/rich-text-color.md "Block Builder – Rich Text Color – Maintainable JavaScript Code for Slack Block Kit") + * [Rich Text Team](bits/rich-text-team.md "Block Builder – Rich Text Team – Maintainable JavaScript Code for Slack Block Kit") * **Component References** * [Paginator](components/paginator.md "Block Builder – Paginator – Maintainable JavaScript Code for Slack Block Kit") diff --git a/docs/bits/rich-text-broadcast.md b/docs/bits/rich-text-broadcast.md new file mode 100644 index 00000000..8209b30a --- /dev/null +++ b/docs/bits/rich-text-broadcast.md @@ -0,0 +1,46 @@ +# Rich Text Broadcast + +?> **Note:** This document is a reference to the `RichTextBroadcastBuilder` object in **Block Builder**. For creating @here, @channel, or @everyone mentions in rich text. + +### Creating an Instance + +```javascript +import { RichTextBroadcast } from 'slack-block-builder'; + +const myObj = RichTextBroadcast(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextBroadcast(params?); +``` + +### Params + +`range` – *String* – The broadcast range: `'here'`, `'channel'`, or `'everyone'` + +### Styling Methods + +```javascript +RichTextBroadcastBuilder.bold(); +RichTextBroadcastBuilder.italic(); +RichTextBroadcastBuilder.strike(); +RichTextBroadcastBuilder.code(); +``` + +### Example + +```javascript +import { RichTextBroadcast } from 'slack-block-builder'; + +RichTextBroadcast({ range: 'here' }); +RichTextBroadcast({ range: 'channel' }); +RichTextBroadcast({ range: 'everyone' }); +``` + +### Other Methods + +```javascript +RichTextBroadcastBuilder.end(); +``` diff --git a/docs/bits/rich-text-channel.md b/docs/bits/rich-text-channel.md new file mode 100644 index 00000000..fa65ec53 --- /dev/null +++ b/docs/bits/rich-text-channel.md @@ -0,0 +1,44 @@ +# Rich Text Channel + +?> **Note:** This document is a reference to the `RichTextChannelBuilder` object in **Block Builder**. For creating #channel mentions in rich text. + +### Creating an Instance + +```javascript +import { RichTextChannel } from 'slack-block-builder'; + +const myObj = RichTextChannel(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextChannel(params?); +``` + +### Params + +`channelId` – *String* – The channel ID to mention (e.g., `'C1234ABCD'`) + +### Styling Methods + +```javascript +RichTextChannelBuilder.bold(); +RichTextChannelBuilder.italic(); +RichTextChannelBuilder.strike(); +RichTextChannelBuilder.code(); +``` + +### Example + +```javascript +import { RichTextChannel } from 'slack-block-builder'; + +RichTextChannel({ channelId: 'C1234ABCD' }); +``` + +### Other Methods + +```javascript +RichTextChannelBuilder.end(); +``` diff --git a/docs/bits/rich-text-color.md b/docs/bits/rich-text-color.md new file mode 100644 index 00000000..c974e18a --- /dev/null +++ b/docs/bits/rich-text-color.md @@ -0,0 +1,73 @@ +# Rich Text Color + +?> **Note:** This document is a reference to the `RichTextColorBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Rich Text element docs](https://docs.slack.dev/reference/block-kit/blocks#element-types) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `RichTextColorBuilder` is available as both a top-level import and as a member of its 'category', `Bits`: + +```javascript +import { RichTextColor } from 'slack-block-builder'; + +const myObj = RichTextColor(params?); + +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextColor(params?); +``` + +### Params + +Each instance of the `RichTextColorBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`value` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextColorBuilder` on which it is called. + +```javascript +RichTextColorBuilder.value(string); +``` + +Sets the hex color value (e.g., '#FF5733'). + +```javascript +RichTextColorBuilder.bold(); +``` + +Makes the color text bold. + +```javascript +RichTextColorBuilder.italic(); +``` + +Makes the color text italic. + +```javascript +RichTextColorBuilder.strike(); +``` + +Adds strikethrough to the color text. + +```javascript +RichTextColorBuilder.code(); +``` + +Formats the color text as inline code. + +### Other Methods + +The `RichTextColorBuilder` object also has other methods available: + +```javascript +RichTextColorBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/bits/rich-text-date.md b/docs/bits/rich-text-date.md new file mode 100644 index 00000000..365ae953 --- /dev/null +++ b/docs/bits/rich-text-date.md @@ -0,0 +1,62 @@ +# Rich Text Date + +?> **Note:** This document is a reference to the `RichTextDateBuilder` object in **Block Builder**. For creating formatted date/time elements in rich text. + +### Creating an Instance + +```javascript +import { RichTextDate } from 'slack-block-builder'; + +const myObj = RichTextDate(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextDate(params?); +``` + +### Params + +`timestamp` – *Number* – Unix timestamp in seconds + +`format` – *String* – Date format template (e.g., `'{date_long}'`, `'{time}'`) + +`url` – *String* – Optional URL to link the date + +`fallback` – *String* – Fallback text if date can't be displayed + +### Available Format Tokens + +- `{date_num}` – YYYY-MM-DD +- `{date_short}` – Aug 9, 2020 +- `{date_long}` – Monday, December 23rd, 2013 +- `{date}` – Same as date_long_full without year +- `{time}` – Time of day (12 or 24 hour) +- `{ago}` – e.g., "3 minutes ago" + +### Styling Methods + +```javascript +RichTextDateBuilder.bold(); +RichTextDateBuilder.italic(); +RichTextDateBuilder.strike(); +RichTextDateBuilder.code(); +``` + +### Example + +```javascript +import { RichTextDate } from 'slack-block-builder'; + +RichTextDate({ + timestamp: 1628633820, + format: '{date_long} at {time}' +}); +``` + +### Other Methods + +```javascript +RichTextDateBuilder.end(); +``` diff --git a/docs/bits/rich-text-emoji.md b/docs/bits/rich-text-emoji.md new file mode 100644 index 00000000..36beb696 --- /dev/null +++ b/docs/bits/rich-text-emoji.md @@ -0,0 +1,42 @@ +# Rich Text Emoji + +?> **Note:** This document is a reference to the `RichTextEmojiBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [Rich Text Block docs](https://docs.slack.dev/reference/block-kit/blocks#element-types) on Slack's doc site. + +### Creating an Instance + +```javascript +import { RichTextEmoji } from 'slack-block-builder'; + +const myObj = RichTextEmoji(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextEmoji(params?); +``` + +### Params + +`name` – *String* – The emoji name without colons (e.g., `'wave'`) + +`unicode` – *String* – Lowercase hexadecimal Unicode representation + +`url` – *String* – URL for custom emoji + +### Example + +```javascript +import { RichTextEmoji } from 'slack-block-builder'; + +RichTextEmoji({ name: 'wave' }); +RichTextEmoji({ name: 'thumbsup' }); +``` + +### Other Methods + +```javascript +RichTextEmojiBuilder.end(); +``` + +Performs no alterations to the object on which it is called. diff --git a/docs/bits/rich-text-link.md b/docs/bits/rich-text-link.md new file mode 100644 index 00000000..c8beef4c --- /dev/null +++ b/docs/bits/rich-text-link.md @@ -0,0 +1,48 @@ +# Rich Text Link + +?> **Note:** This document is a reference to the `RichTextLinkBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [Rich Text Block docs](https://docs.slack.dev/reference/block-kit/blocks#element-types) on Slack's doc site. + +### Creating an Instance + +```javascript +import { RichTextLink } from 'slack-block-builder'; + +const myObj = RichTextLink(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextLink(params?); +``` + +### Params + +`url` – *String* – The URL to link to + +`text` – *String* – The display text for the link + +`unsafe` – *Boolean* – Whether the link is unsafe + +### Styling Methods + +```javascript +RichTextLinkBuilder.bold(); +RichTextLinkBuilder.italic(); +RichTextLinkBuilder.strike(); +RichTextLinkBuilder.code(); +``` + +### Example + +```javascript +import { RichTextLink } from 'slack-block-builder'; + +RichTextLink({ url: 'https://example.com', text: 'Click here' }).bold(); +``` + +### Other Methods + +```javascript +RichTextLinkBuilder.end(); +``` diff --git a/docs/bits/rich-text-list.md b/docs/bits/rich-text-list.md new file mode 100644 index 00000000..818f1ab6 --- /dev/null +++ b/docs/bits/rich-text-list.md @@ -0,0 +1,55 @@ +# Rich Text List + +?> **Note:** This document is a reference to the `RichTextListBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [Rich Text Block docs](https://docs.slack.dev/reference/block-kit/blocks#rich_text_list) on Slack's doc site. + +### Creating an Instance + +```javascript +import { RichTextList } from 'slack-block-builder'; + +const myObj = RichTextList(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextList(params?); +``` + +### Params + +`style` – *String* – Either `'bullet'` or `'ordered'` + +`indent` – *Number* – Indentation level (0-8) + +`border` – *Number* – Whether to show a border (0 or 1) + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextListBuilder` on which it is called. + +```javascript +RichTextListBuilder.elements(...elements); +``` + +Adds list items to the list. Each item should be a `RichTextSection` builder. + +### Example + +```javascript +import { RichTextList, RichTextSection, RichTextText } from 'slack-block-builder'; + +RichTextList({ style: 'bullet' }) + .elements( + RichTextSection().elements(RichTextText({ text: 'First item' })), + RichTextSection().elements(RichTextText({ text: 'Second item' })) + ); +``` + +### Other Methods + +```javascript +RichTextListBuilder.end(); +``` + +Performs no alterations to the object on which it is called. diff --git a/docs/bits/rich-text-preformatted.md b/docs/bits/rich-text-preformatted.md new file mode 100644 index 00000000..06847487 --- /dev/null +++ b/docs/bits/rich-text-preformatted.md @@ -0,0 +1,50 @@ +# Rich Text Preformatted + +?> **Note:** This document is a reference to the `RichTextPreformattedBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [Rich Text Block docs](https://docs.slack.dev/reference/block-kit/blocks#rich_text_preformatted) on Slack's doc site. + +### Creating an Instance + +```javascript +import { RichTextPreformatted } from 'slack-block-builder'; + +const myObj = RichTextPreformatted(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextPreformatted(params?); +``` + +### Params + +`border` – *Number* – Whether to show a border (0 or 1) + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextPreformattedBuilder` on which it is called. + +```javascript +RichTextPreformattedBuilder.elements(...elements); +``` + +Adds text or link elements to the code block. Accepts `RichTextText` and `RichTextLink` builders only. + +### Example + +```javascript +import { RichTextPreformatted, RichTextText } from 'slack-block-builder'; + +RichTextPreformatted() + .elements( + RichTextText({ text: 'const greeting = "Hello, World!";' }) + ); +``` + +### Other Methods + +```javascript +RichTextPreformattedBuilder.end(); +``` + +Performs no alterations to the object on which it is called. diff --git a/docs/bits/rich-text-quote.md b/docs/bits/rich-text-quote.md new file mode 100644 index 00000000..26845142 --- /dev/null +++ b/docs/bits/rich-text-quote.md @@ -0,0 +1,50 @@ +# Rich Text Quote + +?> **Note:** This document is a reference to the `RichTextQuoteBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [Rich Text Block docs](https://docs.slack.dev/reference/block-kit/blocks#rich_text_quote) on Slack's doc site. + +### Creating an Instance + +```javascript +import { RichTextQuote } from 'slack-block-builder'; + +const myObj = RichTextQuote(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextQuote(params?); +``` + +### Params + +`border` – *Number* – Whether to show a border (0 or 1) + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextQuoteBuilder` on which it is called. + +```javascript +RichTextQuoteBuilder.elements(...elements); +``` + +Adds inline rich text elements to the quote. Accepts `RichTextText`, `RichTextEmoji`, `RichTextLink`, and other inline elements. + +### Example + +```javascript +import { RichTextQuote, RichTextText } from 'slack-block-builder'; + +RichTextQuote() + .elements( + RichTextText({ text: 'This is a quoted text block.' }).italic() + ); +``` + +### Other Methods + +```javascript +RichTextQuoteBuilder.end(); +``` + +Performs no alterations to the object on which it is called. diff --git a/docs/bits/rich-text-section.md b/docs/bits/rich-text-section.md new file mode 100644 index 00000000..70917dd2 --- /dev/null +++ b/docs/bits/rich-text-section.md @@ -0,0 +1,49 @@ +# Rich Text Section + +?> **Note:** This document is a reference to the `RichTextSectionBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [Rich Text Block docs](https://docs.slack.dev/reference/block-kit/blocks#rich_text_section) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `RichTextSectionBuilder` is available as both a top-level import and as a member of its 'category', `Bits`: + +```javascript +import { RichTextSection } from 'slack-block-builder'; + +const myObj = RichTextSection(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextSection(params?); +``` + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextSectionBuilder` on which it is called. + +```javascript +RichTextSectionBuilder.elements(...elements); +``` + +Adds inline rich text elements to the section. Accepts `RichTextText`, `RichTextEmoji`, `RichTextLink`, `RichTextUser`, `RichTextChannel`, `RichTextUsergroup`, `RichTextBroadcast`, and `RichTextDate` builders. + +### Example + +```javascript +import { RichTextSection, RichTextText, RichTextEmoji } from 'slack-block-builder'; + +RichTextSection() + .elements( + RichTextText({ text: 'Hello ' }).bold(), + RichTextEmoji({ name: 'wave' }) + ); +``` + +### Other Methods + +```javascript +RichTextSectionBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing tag for those who prefer an explicit end. diff --git a/docs/bits/rich-text-team.md b/docs/bits/rich-text-team.md new file mode 100644 index 00000000..4bd4cd3e --- /dev/null +++ b/docs/bits/rich-text-team.md @@ -0,0 +1,73 @@ +# Rich Text Team + +?> **Note:** This document is a reference to the `RichTextTeamBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Rich Text element docs](https://docs.slack.dev/reference/block-kit/blocks#element-types) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `RichTextTeamBuilder` is available as both a top-level import and as a member of its 'category', `Bits`: + +```javascript +import { RichTextTeam } from 'slack-block-builder'; + +const myObj = RichTextTeam(params?); + +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextTeam(params?); +``` + +### Params + +Each instance of the `RichTextTeamBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`teamId` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextTeamBuilder` on which it is called. + +```javascript +RichTextTeamBuilder.teamId(string); +``` + +Sets the team/workspace ID for the mention (e.g., 'T1234ABCD'). + +```javascript +RichTextTeamBuilder.bold(); +``` + +Makes the team mention bold. + +```javascript +RichTextTeamBuilder.italic(); +``` + +Makes the team mention italic. + +```javascript +RichTextTeamBuilder.strike(); +``` + +Adds strikethrough to the team mention. + +```javascript +RichTextTeamBuilder.code(); +``` + +Formats the team mention as inline code. + +### Other Methods + +The `RichTextTeamBuilder` object also has other methods available: + +```javascript +RichTextTeamBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/bits/rich-text-text.md b/docs/bits/rich-text-text.md new file mode 100644 index 00000000..4bf673f4 --- /dev/null +++ b/docs/bits/rich-text-text.md @@ -0,0 +1,65 @@ +# Rich Text Text + +?> **Note:** This document is a reference to the `RichTextTextBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [Rich Text Block docs](https://docs.slack.dev/reference/block-kit/blocks#element-types) on Slack's doc site. + +### Creating an Instance + +```javascript +import { RichTextText } from 'slack-block-builder'; + +const myObj = RichTextText(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextText(params?); +``` + +### Params + +`text` – *String* – The text content + +### Styling Methods + +All styling methods return `this`, enabling chaining. + +```javascript +RichTextTextBuilder.bold(); +``` + +Makes the text bold. + +```javascript +RichTextTextBuilder.italic(); +``` + +Makes the text italic. + +```javascript +RichTextTextBuilder.strike(); +``` + +Adds strikethrough to the text. + +```javascript +RichTextTextBuilder.code(); +``` + +Formats the text as inline code. + +### Example + +```javascript +import { RichTextText } from 'slack-block-builder'; + +RichTextText({ text: 'Important message' }).bold().italic(); +``` + +### Other Methods + +```javascript +RichTextTextBuilder.end(); +``` + +Performs no alterations to the object on which it is called. diff --git a/docs/bits/rich-text-user.md b/docs/bits/rich-text-user.md new file mode 100644 index 00000000..3109b7db --- /dev/null +++ b/docs/bits/rich-text-user.md @@ -0,0 +1,44 @@ +# Rich Text User + +?> **Note:** This document is a reference to the `RichTextUserBuilder` object in **Block Builder**. For creating @user mentions in rich text. + +### Creating an Instance + +```javascript +import { RichTextUser } from 'slack-block-builder'; + +const myObj = RichTextUser(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextUser(params?); +``` + +### Params + +`userId` – *String* – The user ID to mention (e.g., `'U1234ABCD'`) + +### Styling Methods + +```javascript +RichTextUserBuilder.bold(); +RichTextUserBuilder.italic(); +RichTextUserBuilder.strike(); +RichTextUserBuilder.code(); +``` + +### Example + +```javascript +import { RichTextUser } from 'slack-block-builder'; + +RichTextUser({ userId: 'U1234ABCD' }).bold(); +``` + +### Other Methods + +```javascript +RichTextUserBuilder.end(); +``` diff --git a/docs/bits/rich-text-usergroup.md b/docs/bits/rich-text-usergroup.md new file mode 100644 index 00000000..ae5c312a --- /dev/null +++ b/docs/bits/rich-text-usergroup.md @@ -0,0 +1,44 @@ +# Rich Text Usergroup + +?> **Note:** This document is a reference to the `RichTextUsergroupBuilder` object in **Block Builder**. For creating @usergroup mentions in rich text. + +### Creating an Instance + +```javascript +import { RichTextUsergroup } from 'slack-block-builder'; + +const myObj = RichTextUsergroup(params?); +``` + +```javascript +import { Bits } from 'slack-block-builder'; + +const myObj = Bits.RichTextUsergroup(params?); +``` + +### Params + +`usergroupId` – *String* – The usergroup ID to mention (e.g., `'S1234ABCD'`) + +### Styling Methods + +```javascript +RichTextUsergroupBuilder.bold(); +RichTextUsergroupBuilder.italic(); +RichTextUsergroupBuilder.strike(); +RichTextUsergroupBuilder.code(); +``` + +### Example + +```javascript +import { RichTextUsergroup } from 'slack-block-builder'; + +RichTextUsergroup({ usergroupId: 'S1234ABCD' }); +``` + +### Other Methods + +```javascript +RichTextUsergroupBuilder.end(); +``` diff --git a/docs/blocks/context-actions.md b/docs/blocks/context-actions.md new file mode 100644 index 00000000..2e7fce95 --- /dev/null +++ b/docs/blocks/context-actions.md @@ -0,0 +1,55 @@ +# Context Actions + +?> **Note:** This document is a reference to the `ContextActionsBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Context Actions docs](https://docs.slack.dev/reference/block-kit/blocks#context_actions) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `ContextActionsBuilder` is available as both a top-level import and as a member of its 'category', `Blocks`: + +```javascript +import { ContextActions } from 'slack-block-builder'; + +const myObj = ContextActions(params?); + +``` + +```javascript +import { Blocks } from 'slack-block-builder'; + +const myObj = Blocks.ContextActions(params?); +``` + +### Params + +Each instance of the `ContextActionsBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`blockId` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `ContextActionsBuilder` on which it is called. + +```javascript +ContextActionsBuilder.blockId(string); +``` + +Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. + +```javascript +ContextActionsBuilder.elements(...elements); +``` + +Adds elements to the context actions block. Accepts FeedbackButtons or IconButton elements. + +### Other Methods + +The `ContextActionsBuilder` object also has other methods available: + +```javascript +ContextActionsBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/blocks/markdown.md b/docs/blocks/markdown.md new file mode 100644 index 00000000..76534cd8 --- /dev/null +++ b/docs/blocks/markdown.md @@ -0,0 +1,57 @@ +# Markdown + +?> **Note:** This document is a reference to the `MarkdownBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Markdown docs](https://docs.slack.dev/reference/block-kit/blocks#markdown) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `MarkdownBuilder` is available as both a top-level import and as a member of its 'category', `Blocks`: + +```javascript +import { Markdown } from 'slack-block-builder'; + +const myObj = Markdown(params?); + +``` + +```javascript +import { Blocks } from 'slack-block-builder'; + +const myObj = Blocks.Markdown(params?); +``` + +### Params + +Each instance of the `MarkdownBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`blockId` – *String* + +`text` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `MarkdownBuilder` on which it is called. + +```javascript +MarkdownBuilder.blockId(string); +``` + +Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. + +```javascript +MarkdownBuilder.text(string); +``` + +Sets the markdown text content. Standard markdown is supported and will be translated by Slack. Maximum of 12,000 characters. + +### Other Methods + +The `MarkdownBuilder` object also has other methods available: + +```javascript +MarkdownBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/blocks/rich-text.md b/docs/blocks/rich-text.md new file mode 100644 index 00000000..b00a9a52 --- /dev/null +++ b/docs/blocks/rich-text.md @@ -0,0 +1,81 @@ +# Rich Text + +?> **Note:** This document is a reference to the `RichTextBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Rich Text docs](https://docs.slack.dev/reference/block-kit/blocks#rich_text) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `RichTextBuilder` is available as both a top-level import and as a member of its 'category', `Blocks`: + +```javascript +import { RichText } from 'slack-block-builder'; + +const myObj = RichText(params?); + +``` + +```javascript +import { Blocks } from 'slack-block-builder'; + +const myObj = Blocks.RichText(params?); +``` + +### Params + +Each instance of the `RichTextBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`blockId` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextBuilder` on which it is called. + +```javascript +RichTextBuilder.blockId(string); +``` + +Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and v iew submissions for your app to process. + +```javascript +RichTextBuilder.elements(...elements); +``` + +Adds rich text elements to the block. Accepts `RichTextSection`, `RichTextList`, `RichTextQuote`, and `RichTextPreformatted` builders. + +!> **Warning:** When using `RichText` elements inside a `Table` block, only `RichTextSection` is supported. `RichTextList`, `RichTextQuote`, and `RichTextPreformatted` cannot be used in table cells. + +### Example Usage + +```javascript +import { RichText, RichTextSection, RichTextText, RichTextEmoji, RichTextList } from 'slack-block-builder'; + +const block = RichText() + .elements( + RichTextSection() + .elements( + RichTextText({ text: 'Hello ' }).bold(), + RichTextEmoji({ name: 'wave' }), + RichTextText({ text: ' Welcome to the team!' }) + ), + RichTextList({ style: 'bullet' }) + .elements( + RichTextSection() + .elements(RichTextText({ text: 'First item' })), + RichTextSection() + .elements(RichTextText({ text: 'Second item' })) + ) + ) + .buildToJSON(); +``` + +### Other Methods + +The `RichTextBuilder` object also has other methods available: + +```javascript +RichTextBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/blocks/table.md b/docs/blocks/table.md new file mode 100644 index 00000000..fbcb3302 --- /dev/null +++ b/docs/blocks/table.md @@ -0,0 +1,68 @@ +# Table + +?> **Note:** This document is a reference to the `TableBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Table docs](https://docs.slack.dev/reference/block-kit/blocks#table) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `TableBuilder` is available as both a top-level import and as a member of its 'category', `Blocks`: + +```javascript +import { Table } from 'slack-block-builder'; + +const myObj = Table(params?); + +``` + +```javascript +import { Blocks } from 'slack-block-builder'; + +const myObj = Blocks.Table(params?); +``` + +### Params + +Each instance of the `TableBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`blockId` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `TableBuilder` on which it is called. + +```javascript +TableBuilder.blockId(string); +``` + +Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. + +```javascript +TableBuilder.rows(array); +``` + +TableBuilder.rows(array); +``` + +Sets the table rows. Each row is an array of cells containing `rich_text` or raw text objects. + +?> **Note:** To simplify usage, you can pass plain strings or simple text objects (e.g., `{ type: 'text', text: '...' }`) and **Block Builder** will automatically wrap them in the required `RichText` -> `RichTextSection` -> `RichTextText` structure. + +!> **Warning:** Table cells only support `RichTextSection`. You cannot use `RichTextList`, `RichTextQuote`, or `RichTextPreformatted` inside a table cell. The builder will throw an error if you attempt to do so. + +```javascript +TableBuilder.columnSettings(array); +``` + +Sets column behavior settings. Each item can have `align` ('left', 'center', 'right') and `is_wrapped` (boolean) properties. + +### Other Methods + +The `TableBuilder` object also has other methods available: + +```javascript +TableBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/elements/feedback-buttons.md b/docs/elements/feedback-buttons.md new file mode 100644 index 00000000..e294c937 --- /dev/null +++ b/docs/elements/feedback-buttons.md @@ -0,0 +1,61 @@ +# Feedback Buttons + +?> **Note:** This document is a reference to the `FeedbackButtonsBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Feedback Buttons docs](https://docs.slack.dev/reference/block-kit/block-elements#feedback_buttons) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `FeedbackButtonsBuilder` is available as both a top-level import and as a member of its 'category', `Elements`: + +```javascript +import { FeedbackButtons } from 'slack-block-builder'; + +const myObj = FeedbackButtons(params?); + +``` + +```javascript +import { Elements } from 'slack-block-builder'; + +const myObj = Elements.FeedbackButtons(params?); +``` + +### Params + +Each instance of the `FeedbackButtonsBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`actionId` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `FeedbackButtonsBuilder` on which it is called. + +```javascript +FeedbackButtonsBuilder.actionId(string); +``` + +Sets a string to be an identifier for the source of an action in interaction payloads. + +```javascript +FeedbackButtonsBuilder.positiveButton(config); +``` + +Sets the positive feedback button configuration. Config object should have: `text` (string), `value` (string), and optional `accessibilityLabel` (string). + +```javascript +FeedbackButtonsBuilder.negativeButton(config); +``` + +Sets the negative feedback button configuration. Config object should have: `text` (string), `value` (string), and optional `accessibilityLabel` (string). + +### Other Methods + +The `FeedbackButtonsBuilder` object also has other methods available: + +```javascript +FeedbackButtonsBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/elements/icon-button.md b/docs/elements/icon-button.md new file mode 100644 index 00000000..2091c42b --- /dev/null +++ b/docs/elements/icon-button.md @@ -0,0 +1,93 @@ +# Icon Button + +?> **Note:** This document is a reference to the `IconButtonBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Icon Button docs](https://docs.slack.dev/reference/block-kit/block-elements#icon_button) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `IconButtonBuilder` is available as both a top-level import and as a member of its 'category', `Elements`: + +```javascript +import { IconButton } from 'slack-block-builder'; + +const myObj = IconButton(params?); + +``` + +```javascript +import { Elements } from 'slack-block-builder'; + +const myObj = Elements.IconButton(params?); +``` + +### Params + +Each instance of the `IconButtonBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`accessibilityLabel` – *String* + +`actionId` – *String* + +`icon` – *String* + +`text` – *String* + +`value` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `IconButtonBuilder` on which it is called. + +```javascript +IconButtonBuilder.actionId(string); +``` + +Sets a string to be an identifier for the source of an action in interaction payloads. + +```javascript +IconButtonBuilder.icon(string); +``` + +Sets the icon to display on the button (e.g., 'trash', 'edit'). + +```javascript +IconButtonBuilder.text(string); +``` + +Sets the text for the button (used for accessibility). + +```javascript +IconButtonBuilder.value(string); +``` + +Sets the value to be passed to your app when this button is clicked. + +```javascript +IconButtonBuilder.accessibilityLabel(string); +``` + +Sets a longer descriptive text that will be read out by screen readers. + +```javascript +IconButtonBuilder.visibleToUserIds(...userIds); +``` + +Sets user IDs for which the icon button appears. + +```javascript +IconButtonBuilder.confirm(ConfirmationDialogBuilder); +``` + +Sets a confirmation dialog to be shown before the action is executed. + +### Other Methods + +The `IconButtonBuilder` object also has other methods available: + +```javascript +IconButtonBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/elements/rich-text-input.md b/docs/elements/rich-text-input.md new file mode 100644 index 00000000..9fd5fe7c --- /dev/null +++ b/docs/elements/rich-text-input.md @@ -0,0 +1,75 @@ +# Rich Text Input + +?> **Note:** This document is a reference to the `RichTextInputBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Rich Text Input docs](https://docs.slack.dev/reference/block-kit/block-elements#rich_text_input) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `RichTextInputBuilder` is available as both a top-level import and as a member of its 'category', `Elements`: + +```javascript +import { RichTextInput } from 'slack-block-builder'; + +const myObj = RichTextInput(params?); + +``` + +```javascript +import { Elements } from 'slack-block-builder'; + +const myObj = Elements.RichTextInput(params?); +``` + +### Params + +Each instance of the `RichTextInputBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`actionId` – *String* + +`placeholder` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `RichTextInputBuilder` on which it is called. + +```javascript +RichTextInputBuilder.actionId(string); +``` + +Sets a string to be an identifier for the source of an action in interaction payloads. + +```javascript +RichTextInputBuilder.placeholder(string); +``` + +Sets placeholder text displayed in the input when empty. + +```javascript +RichTextInputBuilder.initialValue(RichTextBuilder); +``` + +Sets the initial value for the rich text input using a RichText block builder. + +```javascript +RichTextInputBuilder.focusOnLoad(boolean?); +``` + +Sets the element to have auto focus on opening the view. Defaults to true if called without argument. + +```javascript +RichTextInputBuilder.dispatchActionConfig(config); +``` + +Configures when to dispatch actions for this input. Config object has `trigger_actions_on` array with values like 'on_enter_pressed' or 'on_character_entered'. + +### Other Methods + +The `RichTextInputBuilder` object also has other methods available: + +```javascript +RichTextInputBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/elements/workflow-button.md b/docs/elements/workflow-button.md new file mode 100644 index 00000000..4c477f9a --- /dev/null +++ b/docs/elements/workflow-button.md @@ -0,0 +1,81 @@ +# Workflow Button + +?> **Note:** This document is a reference to the `WorkflowButtonBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Workflow Button docs](https://docs.slack.dev/reference/block-kit/block-elements#workflow_button) on Slack's doc site. + +### Creating an Instance + +The function that creates a new instance of `WorkflowButtonBuilder` is available as both a top-level import and as a member of its 'category', `Elements`: + +```javascript +import { WorkflowButton } from 'slack-block-builder'; + +const myObj = WorkflowButton(params?); + +``` + +```javascript +import { Elements } from 'slack-block-builder'; + +const myObj = Elements.WorkflowButton(params?); +``` + +### Params + +Each instance of the `WorkflowButtonBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer: + +`accessibilityLabel` – *String* + +`text` – *String* + + +?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below. + +### Setter Methods + +All setter methods return `this`, the instance of `WorkflowButtonBuilder` on which it is called. + +```javascript +WorkflowButtonBuilder.text(string); +``` + +Sets the display text for the button. + +```javascript +WorkflowButtonBuilder.accessibilityLabel(string); +``` + +Sets a longer descriptive text that will be read out by screen readers instead of the button text object. + +```javascript +WorkflowButtonBuilder.workflow(object); +``` + +Sets the workflow configuration with a trigger URL and optional customizable input parameters. + +```javascript +WorkflowButtonBuilder.confirm(ConfirmationDialogBuilder); +``` + +Sets a confirmation dialog to be shown before the workflow is triggered. + +```javascript +WorkflowButtonBuilder.primary(); +``` + +Sets the button style to primary (green). + +```javascript +WorkflowButtonBuilder.danger(); +``` + +Sets the button style to danger (red). + +### Other Methods + +The `WorkflowButtonBuilder` object also has other methods available: + +```javascript +WorkflowButtonBuilder.end(); +``` + +Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. diff --git a/docs/support.md b/docs/support.md index b2e8a948..8c07f5ba 100644 --- a/docs/support.md +++ b/docs/support.md @@ -4,7 +4,7 @@ At the time of writing this doc, **Block Builder** supports every component prov Below is a list of supported components and how to access them in **Block Builder**. -?> **Note:** A few of the [composition objects](https://api.slack.com/reference/block-kit/composition-objects), such as the plain-text and markdown objects are not mentioned here, as they are built in the background, as part of a more UI-focus component. +?> **Note:** A few of the [composition objects](https://docs.slack.dev/reference/block-kit/composition-objects), such as the plain-text and markdown objects are not mentioned here, as they are built in the background, as part of a more UI-focus component. | **Name** | **Type** | **Support** | **Accessed Via** | **Docs** |---------------------|--------------------|---------------------|--------------------------------|-------------- @@ -20,6 +20,10 @@ Below is a list of supported components and how to access them in **Block Builde | Input | Block | **Yes** | `Blocks.Input()` | [View Docs](/blocks/input.md) | Section | Block | **Yes** | `Blocks.Section()` | [View Docs](/blocks/section.md) | Video | Video | **Yes** | `Blocks.Video()` | [View Docs](/blocks/video.md) +| Rich Text | Block | **Yes** | `Blocks.RichText()` | [View Docs](/blocks/rich-text.md) +| Markdown | Block | **Yes** | `Blocks.Markdown()` | [View Docs](/blocks/markdown.md) +| Table | Block | **Yes** | `Blocks.Table()` | [View Docs](/blocks/table.md) +| Context Actions | Block | **Yes** | `Blocks.ContextActions()` | [View Docs](/blocks/context-actions.md) | Button | Element | **Yes**️ | `Elements.Button()` | [View Docs](/elements/button.md) | Checkboxes | Element | **Yes** | `Elements.Checkboxes()` | [View Docs](/elements/checkboxes.md) | Date Picker | Element | **Yes** | `Elements.DatePicker()` | [View Docs](/elements/date-picker.md) @@ -34,8 +38,27 @@ Below is a list of supported components and how to access them in **Block Builde | Select Menus | Element | **Yes** | `Elements.[Type]Select()` | | Multi-Select Menus | Element | **Yes** | `Elements.[Type]MultiSelect()` | | URL Input | Element | **Yes** | `Elements.URLInput()` | [View Docs](/elements/url-input.md) +| Workflow Button | Element | **Yes** | `Elements.WorkflowButton()` | [View Docs](/elements/workflow-button.md) +| Icon Button | Element | **Yes** | `Elements.IconButton()` | [View Docs](/elements/icon-button.md) +| Feedback Buttons | Element | **Yes** | `Elements.FeedbackButtons()` | [View Docs](/elements/feedback-buttons.md) +| Rich Text Input | Element | **Yes** | `Elements.RichTextInput()` | [View Docs](/elements/rich-text-input.md) +| File Input | Element | **Yes** | `Elements.FileInput()` | [View Docs](/elements/file-input.md) | Attachment | Legacy Feature | **Yes** | `Bits.Attachment()` | [View Docs](/bits/attachment.md) | Confirmation Dialog | Composition Object | **Yes** | `Bits.ConfirmationDialog()` | [View Docs](/bits/confirmation-dialog.md) | Option | Composition Object | **Yes** | `Bits.Option()` | [View Docs](/bits/option.md) | Option Group | Composition Object | **Yes** | `Bits.OptionGroup()` | [View Docs](/bits/option-group.md) +| Rich Text Section | Composition Object | **Yes** | `Bits.RichTextSection()` | [View Docs](/bits/rich-text-section.md) +| Rich Text List | Composition Object | **Yes** | `Bits.RichTextList()` | [View Docs](/bits/rich-text-list.md) +| Rich Text Quote | Composition Object | **Yes** | `Bits.RichTextQuote()` | [View Docs](/bits/rich-text-quote.md) +| Rich Text Preformatted | Composition Object | **Yes** | `Bits.RichTextPreformatted()` | [View Docs](/bits/rich-text-preformatted.md) +| Rich Text Text | Composition Object | **Yes** | `Bits.RichTextText()` | [View Docs](/bits/rich-text-text.md) +| Rich Text Emoji | Composition Object | **Yes** | `Bits.RichTextEmoji()` | [View Docs](/bits/rich-text-emoji.md) +| Rich Text Link | Composition Object | **Yes** | `Bits.RichTextLink()` | [View Docs](/bits/rich-text-link.md) +| Rich Text User | Composition Object | **Yes** | `Bits.RichTextUser()` | [View Docs](/bits/rich-text-user.md) +| Rich Text Channel | Composition Object | **Yes** | `Bits.RichTextChannel()` | [View Docs](/bits/rich-text-channel.md) +| Rich Text Usergroup | Composition Object | **Yes** | `Bits.RichTextUsergroup()` | [View Docs](/bits/rich-text-usergroup.md) +| Rich Text Broadcast | Composition Object | **Yes** | `Bits.RichTextBroadcast()` | [View Docs](/bits/rich-text-broadcast.md) +| Rich Text Date | Composition Object | **Yes** | `Bits.RichTextDate()` | [View Docs](/bits/rich-text-date.md) +| Rich Text Color | Composition Object | **Yes** | `Bits.RichTextColor()` | [View Docs](/bits/rich-text-color.md) +| Rich Text Team | Composition Object | **Yes** | `Bits.RichTextTeam()` | [View Docs](/bits/rich-text-team.md) diff --git a/src/bits/attachment.ts b/src/bits/attachment.ts index 151ca4cb..980d83eb 100644 --- a/src/bits/attachment.ts +++ b/src/bits/attachment.ts @@ -23,7 +23,7 @@ export interface AttachmentBuilder extends Blocks, } /** - * @@link https://api.slack.com/reference/messaging/attachments + * @@link https://docs.slack.dev/reference/messaging/attachments * @@displayName Attachment */ diff --git a/src/bits/confirmation-dialog.ts b/src/bits/confirmation-dialog.ts index 8a0af63d..6c568734 100644 --- a/src/bits/confirmation-dialog.ts +++ b/src/bits/confirmation-dialog.ts @@ -28,7 +28,7 @@ export interface ConfirmationDialogBuilder extends Confirm, } /** - * @@link https://api.slack.com/reference/block-kit/composition-objects#confirm + * @@link https://docs.slack.dev/reference/block-kit/composition-objects/confirmation-dialog-object * @@displayName Confirmation Dialog */ diff --git a/src/bits/index.ts b/src/bits/index.ts index 4fdb2a51..4f0d9a48 100644 --- a/src/bits/index.ts +++ b/src/bits/index.ts @@ -4,6 +4,20 @@ import { AttachmentBuilder, AttachmentParams } from './attachment'; import { ConfirmationDialogBuilder, ConfirmationDialogParams } from './confirmation-dialog'; import { OptionBuilder, OptionParams } from './option'; import { OptionGroupBuilder, OptionGroupParams } from './option-group'; +import { RichTextSectionBuilder, RichTextSectionParams } from './rich-text-section'; +import { RichTextListBuilder, RichTextListParams } from './rich-text-list'; +import { RichTextQuoteBuilder, RichTextQuoteParams } from './rich-text-quote'; +import { RichTextPreformattedBuilder, RichTextPreformattedParams } from './rich-text-preformatted'; +import { RichTextTextBuilder, RichTextTextParams } from './rich-text-text'; +import { RichTextEmojiBuilder, RichTextEmojiParams } from './rich-text-emoji'; +import { RichTextLinkBuilder, RichTextLinkParams } from './rich-text-link'; +import { RichTextUserBuilder, RichTextUserParams } from './rich-text-user'; +import { RichTextChannelBuilder, RichTextChannelParams } from './rich-text-channel'; +import { RichTextUsergroupBuilder, RichTextUsergroupParams } from './rich-text-usergroup'; +import { RichTextBroadcastBuilder, RichTextBroadcastParams } from './rich-text-broadcast'; +import { RichTextDateBuilder, RichTextDateParams } from './rich-text-date'; +import { RichTextColorBuilder, RichTextColorParams } from './rich-text-color'; +import { RichTextTeamBuilder, RichTextTeamParams } from './rich-text-team'; export type { AttachmentBuilder, @@ -14,6 +28,34 @@ export type { OptionParams, OptionGroupBuilder, OptionGroupParams, + RichTextSectionBuilder, + RichTextSectionParams, + RichTextListBuilder, + RichTextListParams, + RichTextQuoteBuilder, + RichTextQuoteParams, + RichTextPreformattedBuilder, + RichTextPreformattedParams, + RichTextTextBuilder, + RichTextTextParams, + RichTextEmojiBuilder, + RichTextEmojiParams, + RichTextLinkBuilder, + RichTextLinkParams, + RichTextUserBuilder, + RichTextUserParams, + RichTextChannelBuilder, + RichTextChannelParams, + RichTextUsergroupBuilder, + RichTextUsergroupParams, + RichTextBroadcastBuilder, + RichTextBroadcastParams, + RichTextDateBuilder, + RichTextDateParams, + RichTextColorBuilder, + RichTextColorParams, + RichTextTeamBuilder, + RichTextTeamParams, }; /** @@ -24,7 +66,7 @@ export type { * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.color] Sets the color of the block quote border. * - * {@link https://api.slack.com/reference/messaging/attachments|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/messaging/attachments|View in Slack API Documentation} */ export function Attachment(params?: AttachmentParams): AttachmentBuilder { @@ -36,9 +78,9 @@ export function Attachment(params?: AttachmentParams): AttachmentBuilder { * @param {string} [params.title] Sets the title displayed in the confirmation dialog. * @param {string} [params.text] Sets the textual content of the confirmation dialog. * @param {string} [params.confirm] Sets the text for the button that confirms the action. - * @param {string} [params.deny]Sets the text for the button that cancels the action. + * @param {string} [params.deny] Sets the text for the button that cancels the action. * - * {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/composition-objects/confirmation-dialog-object|View in Slack API Documentation} */ export function ConfirmationDialog(params?: ConfirmationDialogParams): ConfirmationDialogBuilder { @@ -52,7 +94,7 @@ export function ConfirmationDialog(params?: ConfirmationDialogParams): Confirmat * @param {string} [params.description] Sets a description shown next to the option, if in a radio button input. * @param {string} [params.url] Sets the URL to redirect the user to when this option is clicked, if in an overlow menu. * - * {@link https://api.slack.com/reference/block-kit/composition-objects#option|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/composition-objects/option-object|View in Slack API Documentation} */ export function Option(params?: OptionParams): OptionBuilder { @@ -63,18 +105,179 @@ export function Option(params?: OptionParams): OptionBuilder { * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.label] Sets the label shown above the group of option. * - * {@link https://api.slack.com/reference/block-kit/composition-objects#option_group|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/composition-objects/option-group-object|View in Slack API Documentation} */ export function OptionGroup(params?: OptionGroupParams): OptionGroupBuilder { return new OptionGroupBuilder(params); } +/** + * @description Creates a rich text section element. + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextSection(params?: RichTextSectionParams): RichTextSectionBuilder { + return new RichTextSectionBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.style] The list style - 'bullet' or 'ordered'. + * @param {number} [params.indent] The indentation level (0-8). + * @param {number} [params.border] Whether to show a border (0 or 1). + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextList(params?: RichTextListParams): RichTextListBuilder { + return new RichTextListBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {number} [params.border] Whether to show a border (0 or 1). + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextQuote(params?: RichTextQuoteParams): RichTextQuoteBuilder { + return new RichTextQuoteBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {number} [params.border] Whether to show a border (0 or 1). + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextPreformatted(params?: RichTextPreformattedParams): RichTextPreformattedBuilder { + return new RichTextPreformattedBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.text] The text content. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextText(params?: RichTextTextParams): RichTextTextBuilder { + return new RichTextTextBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.name] The emoji name without colons. + * @param {string} [params.unicode] The unicode representation. + * @param {string} [params.url] URL for custom emoji. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextEmoji(params?: RichTextEmojiParams): RichTextEmojiBuilder { + return new RichTextEmojiBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.url] The URL to link to. + * @param {string} [params.text] The link text. + * @param {boolean} [params.unsafe] Whether the link is unsafe. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextLink(params?: RichTextLinkParams): RichTextLinkBuilder { + return new RichTextLinkBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.userId] The user ID to mention. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextUser(params?: RichTextUserParams): RichTextUserBuilder { + return new RichTextUserBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.channelId] The channel ID to mention. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextChannel(params?: RichTextChannelParams): RichTextChannelBuilder { + return new RichTextChannelBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.usergroupId] The usergroup ID to mention. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextUsergroup(params?: RichTextUsergroupParams): RichTextUsergroupBuilder { + return new RichTextUsergroupBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.range] The broadcast range - 'here', 'channel', or 'everyone'. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextBroadcast(params?: RichTextBroadcastParams): RichTextBroadcastBuilder { + return new RichTextBroadcastBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {number} [params.timestamp] Unix timestamp in seconds. + * @param {string} [params.format] The date format template. + * @param {string} [params.url] Optional URL to link the date. + * @param {string} [params.fallback] Fallback text if date can't be displayed. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextDate(params?: RichTextDateParams): RichTextDateBuilder { + return new RichTextDateBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.value] The hex color value. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextColor(params?: RichTextColorParams): RichTextColorBuilder { + return new RichTextColorBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.teamId] The team/workspace ID to mention. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ +export function RichTextTeam(params?: RichTextTeamParams): RichTextTeamBuilder { + return new RichTextTeamBuilder(params); +} + const bits = { Attachment, ConfirmationDialog, Option, OptionGroup, + RichTextSection, + RichTextList, + RichTextQuote, + RichTextPreformatted, + RichTextText, + RichTextEmoji, + RichTextLink, + RichTextUser, + RichTextChannel, + RichTextUsergroup, + RichTextBroadcast, + RichTextDate, + RichTextColor, + RichTextTeam, }; // Strange export. I know. For IDE highlighting purposes. diff --git a/src/bits/option-group.ts b/src/bits/option-group.ts index b4f75c21..e6591c69 100644 --- a/src/bits/option-group.ts +++ b/src/bits/option-group.ts @@ -17,7 +17,7 @@ export interface OptionGroupBuilder extends End, } /** - * @@link https://api.slack.com/reference/block-kit/composition-objects#option_group + * @@link https://docs.slack.dev/reference/block-kit/composition-objects/option-group-object * @@displayName Option Group */ diff --git a/src/bits/option.ts b/src/bits/option.ts index 5642cb40..ff2f6d25 100644 --- a/src/bits/option.ts +++ b/src/bits/option.ts @@ -26,7 +26,7 @@ export interface OptionBuilder extends Description, } /** - * @@link https://api.slack.com/reference/block-kit/composition-objects#option + * @@link https://docs.slack.dev/reference/block-kit/composition-objects/option-object * @@displayName Option */ diff --git a/src/bits/rich-text-broadcast.ts b/src/bits/rich-text-broadcast.ts new file mode 100644 index 00000000..ab0105f6 --- /dev/null +++ b/src/bits/rich-text-broadcast.ts @@ -0,0 +1,62 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextBroadcastParams { + range?: 'here' | 'channel' | 'everyone'; +} + +export interface RichTextBroadcastBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Broadcast Mention + */ + +export class RichTextBroadcastBuilder extends BitBuilderBase { + /** @internal */ + + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Broadcast, + range: this.props.range, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextBroadcastBuilder, [ + End, +]); diff --git a/src/bits/rich-text-channel.ts b/src/bits/rich-text-channel.ts new file mode 100644 index 00000000..172a993a --- /dev/null +++ b/src/bits/rich-text-channel.ts @@ -0,0 +1,62 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextChannelParams { + channelId?: string; +} + +export interface RichTextChannelBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Channel Mention + */ + +export class RichTextChannelBuilder extends BitBuilderBase { + /** @internal */ + + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Channel, + channelId: this.props.channelId, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextChannelBuilder, [ + End, +]); diff --git a/src/bits/rich-text-color.ts b/src/bits/rich-text-color.ts new file mode 100644 index 00000000..2276cfb0 --- /dev/null +++ b/src/bits/rich-text-color.ts @@ -0,0 +1,83 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextColorParams { + value?: string; +} + +export interface RichTextColorBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Color + */ + +export class RichTextColorBuilder extends BitBuilderBase { + /** @internal */ + + /** + * @description Sets the hex color value. + * @param {string} value - The hex color value (e.g., '#FF5733'). + */ + public value(value: string): this { + this.props.value = value; + return this; + } + + /** + * @description Makes the color text bold. + */ + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + /** + * @description Makes the color text italic. + */ + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + /** + * @description Adds strikethrough to the color text. + */ + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + /** + * @description Formats the color text as inline code. + */ + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Color, + value: this.props.value, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextColorBuilder, [ + End, +]); diff --git a/src/bits/rich-text-date.ts b/src/bits/rich-text-date.ts new file mode 100644 index 00000000..5de5d755 --- /dev/null +++ b/src/bits/rich-text-date.ts @@ -0,0 +1,68 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextDateParams { + timestamp?: number; + format?: string; + url?: string; + fallback?: string; +} + +export interface RichTextDateBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Date + */ + +export class RichTextDateBuilder extends BitBuilderBase { + /** @internal */ + + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Date, + timestamp: this.props.timestamp, + format: this.props.format, + url: this.props.url, + fallback: this.props.fallback, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextDateBuilder, [ + End, +]); diff --git a/src/bits/rich-text-emoji.ts b/src/bits/rich-text-emoji.ts new file mode 100644 index 00000000..7864c696 --- /dev/null +++ b/src/bits/rich-text-emoji.ts @@ -0,0 +1,36 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextEmojiParams { + name?: string; + unicode?: string; + url?: string; +} + +export interface RichTextEmojiBuilder extends End { +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Emoji + */ + +export class RichTextEmojiBuilder extends BitBuilderBase { + /** @internal */ + + public build(): Readonly { + return this.getResult(SlackDto, { + type: RichTextElementType.Emoji, + name: this.props.name, + unicode: this.props.unicode, + url: this.props.url, + }); + } +} + +applyMixins(RichTextEmojiBuilder, [ + End, +]); diff --git a/src/bits/rich-text-link.ts b/src/bits/rich-text-link.ts new file mode 100644 index 00000000..4a18f49a --- /dev/null +++ b/src/bits/rich-text-link.ts @@ -0,0 +1,78 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextLinkParams { + url?: string; + text?: string; + unsafe?: boolean; +} + +export interface RichTextLinkBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Link + */ + +export class RichTextLinkBuilder extends BitBuilderBase { + /** @internal */ + + /** + * @description Makes the link text bold. + */ + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + /** + * @description Makes the link text italic. + */ + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + /** + * @description Adds strikethrough to the link text. + */ + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + /** + * @description Formats the link text as inline code. + */ + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Link, + url: this.props.url, + text: this.props.text, + unsafe: this.props.unsafe, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextLinkBuilder, [ + End, +]); diff --git a/src/bits/rich-text-list.ts b/src/bits/rich-text-list.ts new file mode 100644 index 00000000..24c6192f --- /dev/null +++ b/src/bits/rich-text-list.ts @@ -0,0 +1,43 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins, getBuilderResults } from '../internal/helpers'; +import { + Elements, + End, +} from '../internal/methods'; + +export interface RichTextListParams { + style?: 'bullet' | 'ordered'; + indent?: number; + border?: 0 | 1; +} + +export interface RichTextListBuilder extends End, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Elements { +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text List + */ + +export class RichTextListBuilder extends BitBuilderBase { + /** @internal */ + + public build(): Readonly { + return this.getResult(SlackDto, { + type: RichTextElementType.List, + elements: getBuilderResults(this.props.elements), + style: this.props.style, + indent: this.props.indent, + border: this.props.border, + }); + } +} + +applyMixins(RichTextListBuilder, [ + End, + Elements, +]); diff --git a/src/bits/rich-text-preformatted.ts b/src/bits/rich-text-preformatted.ts new file mode 100644 index 00000000..5cb7bb8a --- /dev/null +++ b/src/bits/rich-text-preformatted.ts @@ -0,0 +1,39 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins, getBuilderResults } from '../internal/helpers'; +import { + Elements, + End, +} from '../internal/methods'; + +export interface RichTextPreformattedParams { + border?: 0 | 1; +} + +export interface RichTextPreformattedBuilder extends End, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Elements { +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Preformatted + */ + +export class RichTextPreformattedBuilder extends BitBuilderBase { + /** @internal */ + + public build(): Readonly { + return this.getResult(SlackDto, { + type: RichTextElementType.Preformatted, + elements: getBuilderResults(this.props.elements), + border: this.props.border, + }); + } +} + +applyMixins(RichTextPreformattedBuilder, [ + End, + Elements, +]); diff --git a/src/bits/rich-text-quote.ts b/src/bits/rich-text-quote.ts new file mode 100644 index 00000000..5e1564c9 --- /dev/null +++ b/src/bits/rich-text-quote.ts @@ -0,0 +1,39 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins, getBuilderResults } from '../internal/helpers'; +import { + Elements, + End, +} from '../internal/methods'; + +export interface RichTextQuoteParams { + border?: 0 | 1; +} + +export interface RichTextQuoteBuilder extends End, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Elements { +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Quote + */ + +export class RichTextQuoteBuilder extends BitBuilderBase { + /** @internal */ + + public build(): Readonly { + return this.getResult(SlackDto, { + type: RichTextElementType.Quote, + elements: getBuilderResults(this.props.elements), + border: this.props.border, + }); + } +} + +applyMixins(RichTextQuoteBuilder, [ + End, + Elements, +]); diff --git a/src/bits/rich-text-section.ts b/src/bits/rich-text-section.ts new file mode 100644 index 00000000..9137099d --- /dev/null +++ b/src/bits/rich-text-section.ts @@ -0,0 +1,36 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins, getBuilderResults } from '../internal/helpers'; +import { + Elements, + End, +} from '../internal/methods'; + +export interface RichTextSectionParams { } + +export interface RichTextSectionBuilder extends End, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Elements { +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Section + */ + +export class RichTextSectionBuilder extends BitBuilderBase { + /** @internal */ + + public build(): Readonly { + return this.getResult(SlackDto, { + type: RichTextElementType.Section, + elements: getBuilderResults(this.props.elements), + }); + } +} + +applyMixins(RichTextSectionBuilder, [ + End, + Elements, +]); diff --git a/src/bits/rich-text-team.ts b/src/bits/rich-text-team.ts new file mode 100644 index 00000000..2289fe8a --- /dev/null +++ b/src/bits/rich-text-team.ts @@ -0,0 +1,84 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextTeamParams { + teamId?: string; +} + +export interface RichTextTeamBuilder extends End { + teamId(teamId: string): this; + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Team + */ + +export class RichTextTeamBuilder extends BitBuilderBase { + /** @internal */ + + /** + * @description Sets the team/workspace ID for the mention. + * @param {string} teamId - The encoded team ID (e.g., T1234ABCD). + */ + public teamId(teamId: string): this { + this.props.teamId = teamId; + return this; + } + + /** + * @description Makes the team mention bold. + */ + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + /** + * @description Makes the team mention italic. + */ + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + /** + * @description Adds strikethrough to the team mention. + */ + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + /** + * @description Formats the team mention as inline code. + */ + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Team, + teamId: this.props.teamId, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextTeamBuilder, [ + End, +]); diff --git a/src/bits/rich-text-text.ts b/src/bits/rich-text-text.ts new file mode 100644 index 00000000..adac7506 --- /dev/null +++ b/src/bits/rich-text-text.ts @@ -0,0 +1,74 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextTextParams { + text?: string; +} + +export interface RichTextTextBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Text + */ + +export class RichTextTextBuilder extends BitBuilderBase { + /** @internal */ + + /** + * @description Makes the text bold. + */ + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + /** + * @description Makes the text italic. + */ + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + /** + * @description Adds strikethrough to the text. + */ + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + /** + * @description Formats the text as inline code. + */ + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Text, + text: this.props.text, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextTextBuilder, [ + End, +]); diff --git a/src/bits/rich-text-user.ts b/src/bits/rich-text-user.ts new file mode 100644 index 00000000..0a0480fe --- /dev/null +++ b/src/bits/rich-text-user.ts @@ -0,0 +1,62 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextUserParams { + userId?: string; +} + +export interface RichTextUserBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text User Mention + */ + +export class RichTextUserBuilder extends BitBuilderBase { + /** @internal */ + + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.User, + userId: this.props.userId, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextUserBuilder, [ + End, +]); diff --git a/src/bits/rich-text-usergroup.ts b/src/bits/rich-text-usergroup.ts new file mode 100644 index 00000000..dcb69875 --- /dev/null +++ b/src/bits/rich-text-usergroup.ts @@ -0,0 +1,62 @@ +import { BitBuilderBase } from '../internal/base'; +import { RichTextElementType } from '../internal/constants'; +import { SlackDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { End } from '../internal/methods'; + +export interface RichTextUsergroupParams { + usergroupId?: string; +} + +export interface RichTextUsergroupBuilder extends End { + bold(): this; + italic(): this; + strike(): this; + code(): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text Usergroup Mention + */ + +export class RichTextUsergroupBuilder extends BitBuilderBase { + /** @internal */ + + public bold(): this { + this.props.style = { ...this.props.style, bold: true }; + return this; + } + + public italic(): this { + this.props.style = { ...this.props.style, italic: true }; + return this; + } + + public strike(): this { + this.props.style = { ...this.props.style, strike: true }; + return this; + } + + public code(): this { + this.props.style = { ...this.props.style, code: true }; + return this; + } + + public build(): Readonly { + const result: Record = { + type: RichTextElementType.Usergroup, + usergroupId: this.props.usergroupId, + }; + + if (this.props.style && Object.keys(this.props.style).length > 0) { + result.style = this.props.style; + } + + return this.getResult(SlackDto, result); + } +} + +applyMixins(RichTextUsergroupBuilder, [ + End, +]); diff --git a/src/blocks/actions.ts b/src/blocks/actions.ts index d34a2bda..40eb3708 100644 --- a/src/blocks/actions.ts +++ b/src/blocks/actions.ts @@ -21,7 +21,7 @@ export interface ActionsBuilder extends BlockId, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#actions + * @@link https://docs.slack.dev/reference/block-kit/blocks/actions-block * @@displayName Actions */ diff --git a/src/blocks/context-actions.ts b/src/blocks/context-actions.ts new file mode 100644 index 00000000..730a54d1 --- /dev/null +++ b/src/blocks/context-actions.ts @@ -0,0 +1,47 @@ +import { BlockBuilderBase } from '../internal/base'; +import { BlockType } from '../internal/constants'; +import { SlackBlockDto } from '../internal/dto'; +import { applyMixins, getBuilderResults } from '../internal/helpers'; +import { + BlockId, + End, +} from '../internal/methods'; + +export interface ContextActionsParams { + blockId?: string; +} + +export interface ContextActionsBuilder extends BlockId, + End { + elements(...elements: unknown[]): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/context-actions-block + * @@displayName Context Actions + */ + +export class ContextActionsBuilder extends BlockBuilderBase { + /** @internal */ + + /** + * @description Adds elements (FeedbackButtons or IconButton) to the context actions block. + * @param {...unknown[]} elements - FeedbackButtons or IconButton elements. + */ + public elements(...elements: unknown[]): this { + this.props.elements = [...(this.props.elements || []), ...elements].flat(); + return this; + } + + public build(): Readonly { + return this.getResult(SlackBlockDto, { + type: BlockType.ContextActions, + elements: getBuilderResults(this.props.elements), + }); + } +} + +applyMixins(ContextActionsBuilder, [ + BlockId, + End, +]); diff --git a/src/blocks/context.ts b/src/blocks/context.ts index fa173f75..e5175c54 100644 --- a/src/blocks/context.ts +++ b/src/blocks/context.ts @@ -20,7 +20,7 @@ export interface ContextBuilder extends BlockId, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#context + * @@link https://docs.slack.dev/reference/block-kit/blocks/context-block * @@displayName Context */ diff --git a/src/blocks/divider.ts b/src/blocks/divider.ts index fcede8aa..314cba9d 100644 --- a/src/blocks/divider.ts +++ b/src/blocks/divider.ts @@ -13,7 +13,7 @@ export interface DividerBuilder extends BlockId, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#divider + * @@link https://docs.slack.dev/reference/block-kit/blocks/divider-block * @@displayName Divider */ diff --git a/src/blocks/file.ts b/src/blocks/file.ts index c44f661e..adc48e22 100644 --- a/src/blocks/file.ts +++ b/src/blocks/file.ts @@ -19,7 +19,7 @@ export interface FileBuilder extends BlockId, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#file + * @@link https://docs.slack.dev/reference/block-kit/blocks/file-block * @@displayName File */ diff --git a/src/blocks/header.ts b/src/blocks/header.ts index 2df46461..39ba62c7 100644 --- a/src/blocks/header.ts +++ b/src/blocks/header.ts @@ -19,7 +19,7 @@ export interface HeaderBuilder extends BlockId, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#header + * @@link https://docs.slack.dev/reference/block-kit/blocks/header-block * @@displayName Header */ diff --git a/src/blocks/image.ts b/src/blocks/image.ts index 7e266e3d..e4c03dbd 100644 --- a/src/blocks/image.ts +++ b/src/blocks/image.ts @@ -25,7 +25,7 @@ export interface ImageBuilder extends AltText, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#image + * @@link https://docs.slack.dev/reference/block-kit/blocks/image-block * @@displayName Image */ diff --git a/src/blocks/index.ts b/src/blocks/index.ts index 4648636d..18645711 100644 --- a/src/blocks/index.ts +++ b/src/blocks/index.ts @@ -9,6 +9,10 @@ import { ImageBuilder, ImageParams } from './image'; import { InputBuilder, InputParams } from './input'; import { SectionBuilder, SectionParams } from './section'; import { VideoBuilder, VideoParams } from './video'; +import { RichTextBuilder, RichTextParams } from './rich-text'; +import { MarkdownBuilder, MarkdownParams } from './markdown'; +import { TableBuilder, TableParams } from './table'; +import { ContextActionsBuilder, ContextActionsParams } from './context-actions'; export type { ActionsBuilder, @@ -29,6 +33,14 @@ export type { SectionParams, VideoBuilder, VideoParams, + RichTextBuilder, + RichTextParams, + MarkdownBuilder, + MarkdownParams, + TableBuilder, + TableParams, + ContextActionsBuilder, + ContextActionsParams, }; /** @@ -39,7 +51,7 @@ export type { * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. * - * {@link https://api.slack.com/reference/block-kit/blocks#actions|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/actions-block|View in Slack API Documentation} */ export function Actions(params?: ActionsParams): ActionsBuilder { @@ -50,7 +62,7 @@ export function Actions(params?: ActionsParams): ActionsBuilder { * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. * - * {@link https://api.slack.com/reference/block-kit/blocks#context|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/context-block|View in Slack API Documentation} */ export function Context(params?: ContextParams): ContextBuilder { @@ -61,7 +73,7 @@ export function Context(params?: ContextParams): ContextBuilder { * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. * - * {@link https://api.slack.com/reference/block-kit/blocks#divider|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/divider-block|View in Slack API Documentation} */ export function Divider(params?: DividerParams): DividerBuilder { @@ -73,7 +85,7 @@ export function Divider(params?: DividerParams): DividerBuilder { * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. * @param {string} [params.externalId] Sets a custom identifier for the file that must be unique for all images on a per-team basis. * - * {@link https://api.slack.com/reference/block-kit/blocks#file|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/file-block|View in Slack API Documentation} */ export function File(params?: FileParams): FileBuilder { @@ -85,7 +97,7 @@ export function File(params?: FileParams): FileBuilder { * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. * @param {string} [params.text] Sets the text to be displayed in the header block. * - * {@link https://api.slack.com/reference/block-kit/blocks#header|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/header-block|View in Slack API Documentation} */ export function Header(params?: HeaderParams): HeaderBuilder { @@ -99,7 +111,7 @@ export function Header(params?: HeaderParams): HeaderBuilder { * @param {string} [params.altText] Sets a textual summary for the image. * @param {string} [params.title] Sets an optional title for the image. * - * {@link https://api.slack.com/reference/block-kit/blocks#image|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/image-block|View in Slack API Documentation} */ export function Image(params?: ImageParams): ImageBuilder { @@ -112,7 +124,7 @@ export function Image(params?: ImageParams): ImageBuilder { * @param {string} [params.label] Sets the label to be displayed above the input. * @param {string} [params.hint] Sets the hint to be displayed under the input. * - * {@link https://api.slack.com/reference/block-kit/blocks#input|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/input-block|View in Slack API Documentation} */ export function Input(params?: InputParams): InputBuilder { @@ -124,7 +136,7 @@ export function Input(params?: InputParams): InputBuilder { * @param {string} [params.blockId] Sets a string to be an identifier for the block, that will be available in interaction payloadsSets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. * @param {string} [params.text] Sets the text to be displayed in the section block. * - * {@link https://api.slack.com/reference/block-kit/blocks#section|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/section-block|View in Slack API Documentation} */ export function Section(params?: SectionParams): SectionBuilder { @@ -142,13 +154,58 @@ export function Section(params?: SectionParams): SectionBuilder { * @param {string} [params.titleUrl] A hyperlink for the video's title text. * @param {string} [params.videoUrl] The URL of the video to embed in the Video block. * - * {@link https://api.slack.com/reference/block-kit/blocks#section|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/blocks/section-block|View in Slack API Documentation} */ export function Video(params?: VideoParams): VideoBuilder { return new VideoBuilder(params); } +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. This is sent back to your app in interaction payloads and view submissions for your app to process. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block|View in Slack API Documentation} + */ + +export function RichText(params?: RichTextParams): RichTextBuilder { + return new RichTextBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. + * @param {string} [params.text] Sets the markdown text content. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/markdown-block|View in Slack API Documentation} + */ + +export function Markdown(params?: MarkdownParams): MarkdownBuilder { + return new MarkdownBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/table-block|View in Slack API Documentation} + */ + +export function Table(params?: TableParams): TableBuilder { + return new TableBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.blockId] Sets a string to be an identifier for any given block in a view or message. + * + * {@link https://docs.slack.dev/reference/block-kit/blocks/context-block_actions|View in Slack API Documentation} + */ + +export function ContextActions(params?: ContextActionsParams): ContextActionsBuilder { + return new ContextActionsBuilder(params); +} + const blocks = { Actions, Context, @@ -159,8 +216,13 @@ const blocks = { Input, Section, Video, + RichText, + Markdown, + Table, + ContextActions, }; // Strange export. I know. For IDE highlighting purposes. export { blocks as Blocks }; + diff --git a/src/blocks/input.ts b/src/blocks/input.ts index dfccf6fa..b38678e2 100644 --- a/src/blocks/input.ts +++ b/src/blocks/input.ts @@ -31,7 +31,7 @@ export interface InputBuilder extends BlockId, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#input + * @@link https://docs.slack.dev/reference/block-kit/blocks/input-block * @@displayName Input */ diff --git a/src/blocks/markdown.ts b/src/blocks/markdown.ts new file mode 100644 index 00000000..d1451b63 --- /dev/null +++ b/src/blocks/markdown.ts @@ -0,0 +1,42 @@ +import { BlockBuilderBase } from '../internal/base'; +import { BlockType } from '../internal/constants'; +import { SlackBlockDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { + BlockId, + End, + Text, +} from '../internal/methods'; + +export interface MarkdownParams { + blockId?: string; + text?: string; +} + +export interface MarkdownBuilder extends BlockId, + End, + Text { +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/markdown-block + * @@displayName Markdown + */ + +export class MarkdownBuilder extends BlockBuilderBase { + /** @internal */ + + public build(): Readonly { + return this.getResult(SlackBlockDto, { + type: BlockType.Markdown, + text: this.props.text, + }); + } +} + +applyMixins(MarkdownBuilder, [ + BlockId, + End, + Text, +]); + diff --git a/src/blocks/rich-text.ts b/src/blocks/rich-text.ts new file mode 100644 index 00000000..afedb509 --- /dev/null +++ b/src/blocks/rich-text.ts @@ -0,0 +1,43 @@ +import { BlockBuilderBase } from '../internal/base'; +import { BlockType } from '../internal/constants'; +import { SlackBlockDto } from '../internal/dto'; +import { applyMixins, getBuilderResults } from '../internal/helpers'; +import { + BlockId, + Elements, + End, +} from '../internal/methods'; + +import type { SlackDto } from '../internal/dto'; + +export interface RichTextParams { + blockId?: string; +} + +export interface RichTextBuilder extends BlockId, + End, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Elements { +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block + * @@displayName Rich Text + */ + +export class RichTextBuilder extends BlockBuilderBase { + /** @internal */ + + public build(): Readonly { + return this.getResult(SlackBlockDto, { + type: BlockType.RichText, + elements: getBuilderResults(this.props.elements), + }); + } +} + +applyMixins(RichTextBuilder, [ + BlockId, + End, + Elements, +]); diff --git a/src/blocks/section.ts b/src/blocks/section.ts index 95930e08..33f809de 100644 --- a/src/blocks/section.ts +++ b/src/blocks/section.ts @@ -30,7 +30,7 @@ export interface SectionBuilder extends Accessory, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#section + * @@link https://docs.slack.dev/reference/block-kit/blocks/section-block * @@displayName Section */ @@ -38,11 +38,17 @@ export class SectionBuilder extends BlockBuilderBase { /** @internal */ public build(): Readonly { + const accessory = getBuilderResult(this.props.accessory); + + if (accessory && (accessory as any).type === BlockType.RichText) { + throw new Error('Accessory cannot be a Rich Text block. Rich Text blocks are not supported in Section blocks.'); + } + return this.getResult(SlackBlockDto, { type: BlockType.Section, text: getMarkdownObject(this.props.text), fields: getFields(this.props.fields), - accessory: getBuilderResult(this.props.accessory), + accessory, }); } } diff --git a/src/blocks/table.ts b/src/blocks/table.ts new file mode 100644 index 00000000..7a1eeb5a --- /dev/null +++ b/src/blocks/table.ts @@ -0,0 +1,119 @@ +import { BlockBuilderBase } from '../internal/base'; +import { BlockType, RichTextElementType } from '../internal/constants'; +import { SlackBlockDto } from '../internal/dto'; +import { applyMixins } from '../internal/helpers'; +import { + BlockId, + End, +} from '../internal/methods'; +import { RichTextBuilder } from './rich-text'; +import { RichTextSectionBuilder } from '../bits/rich-text-section'; +import { RichTextTextBuilder } from '../bits/rich-text-text'; + +interface ColumnSettings { + align?: 'left' | 'center' | 'right'; + is_wrapped?: boolean; +} + +export interface TableParams { + blockId?: string; +} + +export interface TableBuilder extends BlockId, + End { + rows(rows: unknown[][]): this; + columnSettings(settings: ColumnSettings[]): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/blocks/table-block + * @@displayName Table + */ + +export class TableBuilder extends BlockBuilderBase { + /** @internal */ + + /** + * @description Sets the table rows. Each row is an array of cells (rich_text or raw_text). + * @param {unknown[][]} rows - Array of rows, each containing cell objects. + */ + public rows(rows: unknown[][]): this { + this.props.rows = rows.map((row) => row.map((cell) => { + let cellResult = cell; + + if (typeof cell === 'string') { + cellResult = new RichTextBuilder() + .elements( + new RichTextSectionBuilder() + .elements( + new RichTextTextBuilder({ text: cell }), + ), + ) + .build(); + } else { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const cellObj = cell as any; + + if (cellObj.type === 'text' && typeof cellObj.text === 'string' && !cellObj.style) { + cellResult = new RichTextBuilder() + .elements( + new RichTextSectionBuilder() + .elements( + new RichTextTextBuilder({ text: cellObj.text }), + ), + ) + .build(); + } else if (typeof cellObj.build === 'function') { + cellResult = cellObj.build(); + } + } + + // Validate cell content + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const cellAny = cellResult as any; + + if (cellAny.type !== BlockType.RichText) { + throw new Error(`Table cells must be of type '${BlockType.RichText}', but found '${cellAny.type}'. Verify that you are passing a RichText block or a string to the table rows.`); + } + + if (cellAny?.elements && Array.isArray(cellAny.elements)) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + cellAny.elements.forEach((element: any) => { + if ([ + RichTextElementType.List, + RichTextElementType.Quote, + RichTextElementType.Preformatted, + ].includes(element.type)) { + throw new Error(`Table cells cannot contain ${element.type}. Only rich_text_section is supported.`); + } + }); + } + + return cellResult; + })); + + return this; + } + + /** + * @description Sets column behavior settings. + * @param {ColumnSettings[]} settings - Array of column settings with align and is_wrapped options. + */ + public columnSettings(settings: ColumnSettings[]): this { + this.props.columnSettings = settings; + return this; + } + + public build(): Readonly { + return this.getResult(SlackBlockDto, { + type: BlockType.Table, + rows: this.props.rows, + columnSettings: this.props.columnSettings, + }); + } +} + +applyMixins(TableBuilder, [ + BlockId, + End, +]); diff --git a/src/blocks/video.ts b/src/blocks/video.ts index f81c1e04..9023dc85 100644 --- a/src/blocks/video.ts +++ b/src/blocks/video.ts @@ -42,7 +42,7 @@ export interface VideoBuilder extends AltText, } /** - * @@link https://api.slack.com/reference/block-kit/blocks#video + * @@link https://docs.slack.dev/reference/block-kit/blocks/video-block * @@displayName Video */ diff --git a/src/elements/button.ts b/src/elements/button.ts index 2f9b9038..bd8f296d 100644 --- a/src/elements/button.ts +++ b/src/elements/button.ts @@ -37,7 +37,7 @@ export interface ButtonBuilder extends AccessibilityLabel, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#button + * @@link https://docs.slack.dev/reference/block-kit/block-elements/button-element * @@displayName Button */ diff --git a/src/elements/channel-multi-select.ts b/src/elements/channel-multi-select.ts index 83ce6221..71eda548 100644 --- a/src/elements/channel-multi-select.ts +++ b/src/elements/channel-multi-select.ts @@ -31,7 +31,7 @@ export interface ChannelMultiSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#channel_multi_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#channel_multi_select * @@displayName Channel Multi-Select */ diff --git a/src/elements/channel-select.ts b/src/elements/channel-select.ts index 9efdff33..317ffb14 100644 --- a/src/elements/channel-select.ts +++ b/src/elements/channel-select.ts @@ -31,7 +31,7 @@ export interface ChannelSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#channel_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#channels_select * @@displayName Channel Select */ diff --git a/src/elements/checkboxes.ts b/src/elements/checkboxes.ts index d2f29b01..08f63d92 100644 --- a/src/elements/checkboxes.ts +++ b/src/elements/checkboxes.ts @@ -27,7 +27,7 @@ export interface CheckboxesBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#checkboxes + * @@link https://docs.slack.dev/reference/block-kit/block-elements/checkboxes-element * @@displayName Checkboxes */ diff --git a/src/elements/conversation-multi-select.ts b/src/elements/conversation-multi-select.ts index 254dca16..83fdb509 100644 --- a/src/elements/conversation-multi-select.ts +++ b/src/elements/conversation-multi-select.ts @@ -44,7 +44,7 @@ export interface ConversationMultiSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#conversation_multi_select * @@displayName Conversation Multi-Select */ diff --git a/src/elements/conversation-select.ts b/src/elements/conversation-select.ts index f8bbac59..d1ef27ab 100644 --- a/src/elements/conversation-select.ts +++ b/src/elements/conversation-select.ts @@ -44,7 +44,7 @@ export interface ConversationSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#conversation_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#conversations_select * @@displayName Conversation Select */ diff --git a/src/elements/date-picker.ts b/src/elements/date-picker.ts index 214643bf..aec317ff 100644 --- a/src/elements/date-picker.ts +++ b/src/elements/date-picker.ts @@ -34,7 +34,7 @@ export interface DatePickerBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#datepicker + * @@link https://docs.slack.dev/reference/block-kit/block-elements/date-picker-element * @@displayName Date Picker */ diff --git a/src/elements/date-time-picker.ts b/src/elements/date-time-picker.ts index e4e43c6d..576c5589 100644 --- a/src/elements/date-time-picker.ts +++ b/src/elements/date-time-picker.ts @@ -26,7 +26,7 @@ export interface DateTimePickerBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#datetimepicker + * @@link https://docs.slack.dev/reference/block-kit/block-elements/datetime-picker-element * @@displayName Date Picker */ diff --git a/src/elements/email-input.ts b/src/elements/email-input.ts index b8bf324a..471c6be3 100644 --- a/src/elements/email-input.ts +++ b/src/elements/email-input.ts @@ -28,7 +28,7 @@ export interface EmailInputBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#email + * @@link https://docs.slack.dev/reference/block-kit/block-elements/email-input-element * @@displayName Email Input */ diff --git a/src/elements/external-multi-select.ts b/src/elements/external-multi-select.ts index 1bd47e25..82805de1 100644 --- a/src/elements/external-multi-select.ts +++ b/src/elements/external-multi-select.ts @@ -39,7 +39,7 @@ export interface ExternalMultiSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#external_multi_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#external_multi_select * @@displayName External Multi-Select */ diff --git a/src/elements/external-select.ts b/src/elements/external-select.ts index 3020ff18..95891378 100644 --- a/src/elements/external-select.ts +++ b/src/elements/external-select.ts @@ -31,7 +31,7 @@ export interface ExternalSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#external_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#external_select * @@displayName External Select */ diff --git a/src/elements/feedback-buttons.ts b/src/elements/feedback-buttons.ts new file mode 100644 index 00000000..c64b2c9d --- /dev/null +++ b/src/elements/feedback-buttons.ts @@ -0,0 +1,72 @@ +import { ElementBuilderBase } from '../internal/base'; +import { ElementType } from '../internal/constants'; +import { SlackElementDto } from '../internal/dto'; +import { applyMixins, getPlainTextObject } from '../internal/helpers'; +import { + ActionId, + End, +} from '../internal/methods'; + +interface FeedbackButtonConfig { + text: string; + value: string; + accessibilityLabel?: string; +} + +export interface FeedbackButtonsParams { + actionId?: string; +} + +export interface FeedbackButtonsBuilder extends ActionId, + End { + positiveButton(config: FeedbackButtonConfig): this; + negativeButton(config: FeedbackButtonConfig): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/block-elements/feedback-buttons-element + * @@displayName Feedback Buttons + */ + +export class FeedbackButtonsBuilder extends ElementBuilderBase { + /** @internal */ + + /** + * @description Sets the positive feedback button configuration. + * @param {FeedbackButtonConfig} config - Button configuration with text, value, and optional accessibility label. + */ + public positiveButton(config: FeedbackButtonConfig): this { + this.props.positiveButton = { + text: getPlainTextObject(config.text), + value: config.value, + accessibility_label: config.accessibilityLabel, + }; + return this; + } + + /** + * @description Sets the negative feedback button configuration. + * @param {FeedbackButtonConfig} config - Button configuration with text, value, and optional accessibility label. + */ + public negativeButton(config: FeedbackButtonConfig): this { + this.props.negativeButton = { + text: getPlainTextObject(config.text), + value: config.value, + accessibility_label: config.accessibilityLabel, + }; + return this; + } + + public build(): Readonly { + return this.getResult(SlackElementDto, { + type: ElementType.FeedbackButtons, + positive_button: this.props.positiveButton, + negative_button: this.props.negativeButton, + }); + } +} + +applyMixins(FeedbackButtonsBuilder, [ + ActionId, + End, +]); diff --git a/src/elements/file-input.ts b/src/elements/file-input.ts index 95053070..40e97287 100644 --- a/src/elements/file-input.ts +++ b/src/elements/file-input.ts @@ -22,7 +22,7 @@ export interface FileInputBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#file_input + * @@link https://docs.slack.dev/reference/block-kit/block-elements/file-input-element * @@displayName File Input Builder */ diff --git a/src/elements/icon-button.ts b/src/elements/icon-button.ts new file mode 100644 index 00000000..4d13d5d8 --- /dev/null +++ b/src/elements/icon-button.ts @@ -0,0 +1,87 @@ +import { ElementBuilderBase } from '../internal/base'; +import { ElementType } from '../internal/constants'; +import { SlackElementDto } from '../internal/dto'; +import { applyMixins, getPlainTextObject, getBuilderResult } from '../internal/helpers'; +import { + AccessibilityLabel, + ActionId, + End, + Text, + Value, +} from '../internal/methods'; + +import type { SlackDto } from '../internal/dto'; +import type { ConfirmationDialogBuilder } from '../bits'; + +export interface IconButtonParams { + accessibilityLabel?: string; + actionId?: string; + icon?: string; + text?: string; + value?: string; +} + +export interface IconButtonBuilder extends AccessibilityLabel, + ActionId, + End, + Text, + Value { + icon(icon: string): this; + visibleToUserIds(...userIds: string[]): this; + confirm(dialog: ConfirmationDialogBuilder): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/block-elements/icon-button-element + * @@displayName Icon Button + */ + +export class IconButtonBuilder extends ElementBuilderBase { + /** @internal */ + + /** + * @description Sets the icon to display on the button (e.g., 'trash', 'edit'). + * @param {string} icon - The icon name. + */ + public icon(icon: string): this { + this.props.icon = icon; + return this; + } + + /** + * @description Sets user IDs for which the icon appears. + * @param {...string[]} userIds - User IDs who can see this button. + */ + public visibleToUserIds(...userIds: string[]): this { + this.props.visibleToUserIds = userIds.flat(); + return this; + } + + /** + * @description Sets a confirmation dialog to be shown before the action is executed. + * @param {ConfirmationDialogBuilder} dialog - A ConfirmationDialog builder. + */ + public confirm(dialog: ConfirmationDialogBuilder): this { + this.props.confirm = dialog; + return this; + } + + public build(): Readonly { + return this.getResult(SlackElementDto, { + type: ElementType.IconButton, + icon: this.props.icon, + text: getPlainTextObject(this.props.text), + confirm: getBuilderResult(this.props.confirm), + visible_to_user_ids: this.props.visibleToUserIds, + }); + } +} + +applyMixins(IconButtonBuilder, [ + AccessibilityLabel, + ActionId, + End, + Text, + Value, +]); + diff --git a/src/elements/img.ts b/src/elements/img.ts index 4a1dccf0..d468d7a8 100644 --- a/src/elements/img.ts +++ b/src/elements/img.ts @@ -19,7 +19,7 @@ export interface ImgBuilder extends AltText, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#image + * @@link https://docs.slack.dev/reference/block-kit/block-elements/image-element * @@displayName Image */ diff --git a/src/elements/index.ts b/src/elements/index.ts index d70c0585..3c427e61 100644 --- a/src/elements/index.ts +++ b/src/elements/index.ts @@ -23,6 +23,10 @@ import { TimePickerBuilder, TimePickerParams } from './timepicker'; import { URLInputBuilder, URLInputParams } from './url-input'; import { UserMultiSelectBuilder, UserMultiSelectParams } from './user-multi-select'; import { UserSelectBuilder, UserSelectParams } from './user-select'; +import { WorkflowButtonBuilder, WorkflowButtonParams } from './workflow-button'; +import { IconButtonBuilder, IconButtonParams } from './icon-button'; +import { FeedbackButtonsBuilder, FeedbackButtonsParams } from './feedback-buttons'; +import { RichTextInputBuilder, RichTextInputParams } from './rich-text-input'; export type { ButtonBuilder, @@ -71,6 +75,14 @@ export type { UserSelectParams, FileInputBuilder, FileInputParams, + WorkflowButtonBuilder, + WorkflowButtonParams, + IconButtonBuilder, + IconButtonParams, + FeedbackButtonsBuilder, + FeedbackButtonsParams, + RichTextInputBuilder, + RichTextInputParams, }; /** @@ -85,7 +97,7 @@ export type { * @param {string} [params.url] Sets the URL to redirect the user to when this button is clicked. * @param {string} [params.value] Sets the value to be passed to your app when this button is clicked. * - * {@link https://api.slack.com/reference/block-kit/block-elements#button|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/button-element|View in Slack API Documentation} */ export function Button(params?: ButtonParams): ButtonBuilder { @@ -98,7 +110,7 @@ export function Button(params?: ButtonParams): ButtonBuilder { * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {int} [params.maxSelectedItems] Sets a limit to how many items the user can select. * - * {@link https://api.slack.com/reference/block-kit/block-elements#channel_multi_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#channel_multi_select|View in Slack API Documentation} */ export function ChannelMultiSelect(params?: ChannelMultiSelectParams): ChannelMultiSelectBuilder { @@ -111,7 +123,7 @@ export function ChannelMultiSelect(params?: ChannelMultiSelectParams): ChannelMu * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {string} [params.initialChannel] Sets the default selected item in the menu. * - * {@link https://api.slack.com/reference/block-kit/block-elements#channel_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#channels_select|View in Slack API Documentation} */ export function ChannelSelect(params?: ChannelSelectParams): ChannelSelectBuilder { @@ -122,7 +134,7 @@ export function ChannelSelect(params?: ChannelSelectParams): ChannelSelectBuilde * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action in interaction payloads. * - * {@link https://api.slack.com/reference/block-kit/block-elements#checkboxes|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/checkboxes-element|View in Slack API Documentation} */ export function Checkboxes(params?: CheckboxesParams): CheckboxesBuilder { @@ -135,7 +147,7 @@ export function Checkboxes(params?: CheckboxesParams): CheckboxesBuilder { * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {int} [params.maxSelectedItems] Sets a limit to how many items the user can select. * - * {@link https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#conversation_multi_select|View in Slack API Documentation} */ export function ConversationMultiSelect(params?: ConversationMultiSelectParams): ConversationMultiSelectBuilder { @@ -148,7 +160,7 @@ export function ConversationMultiSelect(params?: ConversationMultiSelectParams): * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {string} [params.initialConversation] Sets the default selected item in the menu. * - * {@link https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#conversations_select|View in Slack API Documentation} */ export function ConversationSelect(params?: ConversationSelectParams): ConversationSelectBuilder { @@ -161,7 +173,7 @@ export function ConversationSelect(params?: ConversationSelectParams): Conversat * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {string} [params.initialDate] Sets the default selected date in the menu. * - * {@link https://api.slack.com/reference/block-kit/block-elements#datepicker|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/date-picker-element|View in Slack API Documentation} */ export function DatePicker(params?: DatePickerParams): DatePickerBuilder { @@ -173,7 +185,7 @@ export function DatePicker(params?: DatePickerParams): DatePickerBuilder { * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action in interaction payloads. * @param {string} [params.initialDateTime] Sets the default selected date and time for the date time picker. * - * {@link https://api.slack.com/reference/block-kit/block-elements#datetimepicker|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/datetime-picker-element|View in Slack API Documentation} */ export function DateTimePicker(params?: DateTimePickerParams): DateTimePickerBuilder { @@ -186,7 +198,7 @@ export function DateTimePicker(params?: DateTimePickerParams): DateTimePickerBui * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {string} [params.initialValue] Sets the default email entered into the Email input at modal render. * - * {@link https://api.slack.com/reference/block-kit/block-elements#email|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/email-input-element|View in Slack API Documentation} */ export function EmailInput(params?: EmailInputParams): EmailInputBuilder { @@ -200,7 +212,7 @@ export function EmailInput(params?: EmailInputParams): EmailInputBuilder { * @param {int} [params.maxSelectedItems] Sets a limit to how many items the user can select. * @param {int} [params.minQueryLength] Sets a minimum number of characters types before querying your options URL. * - * {@link https://api.slack.com/reference/block-kit/block-elements#external_multi_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#external_multi_select|View in Slack API Documentation} */ export function ExternalMultiSelect(params?: ExternalMultiSelectParams): ExternalMultiSelectBuilder { @@ -213,7 +225,7 @@ export function ExternalMultiSelect(params?: ExternalMultiSelectParams): Externa * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {int} [params.minQueryLength] Sets a minimum number of characters types before querying your options URL. * - * {@link https://api.slack.com/reference/block-kit/block-elements#external_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#external_select|View in Slack API Documentation} */ export function ExternalSelect(params?: ExternalSelectParams): ExternalSelectBuilder { @@ -225,7 +237,7 @@ export function ExternalSelect(params?: ExternalSelectParams): ExternalSelectBui * @param {string} [params.imageUrl] Sets the source URL from which the image will be loaded. * @param {string} [params.altText] Sets the textual summary of the image. * - * {@link https://api.slack.com/reference/block-kit/block-elements#image|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/image-element|View in Slack API Documentation} */ export function Img(params?: ImgParams): ImgBuilder { @@ -237,7 +249,7 @@ export function Img(params?: ImgParams): ImgBuilder { * @param {string} [params.filetypes] Sets the accepted filetypes. * @param {string} [params.maxFiles] Sets the maximum number of files to upload. * - * {@link https://api.slack.com/reference/block-kit/block-elements#file_input|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/file-input-element|View in Slack API Documentation} */ export function FileInput(params?: FileInputParams): FileInputBuilder { @@ -253,7 +265,7 @@ export function FileInput(params?: FileInputParams): FileInputBuilder { * @param {int} [params.minValue] Sets a minimum value for the number input. * @param {int} [params.maxValue] Sets a maximum value for the number input. * - * {@link https://api.slack.com/reference/block-kit/block-elements#number|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/number-input-element|View in Slack API Documentation} */ export function NumberInput(params?: NumberInputParams): NumberInputBuilder { @@ -264,7 +276,7 @@ export function NumberInput(params?: NumberInputParams): NumberInputBuilder { * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action in interaction payloads. * - * {@link https://api.slack.com/reference/block-kit/block-elements#overflow|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/overflow-menu-element|View in Slack API Documentation} */ export function OverflowMenu(params?: OverflowMenuParams): OverflowMenuBuilder { @@ -275,7 +287,7 @@ export function OverflowMenu(params?: OverflowMenuParams): OverflowMenuBuilder { * @param {Object} [params] Parameters passed to the constructor. * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action in interaction payloads. * - * {@link https://api.slack.com/reference/block-kit/block-elements#radio|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/radio-button-group-element|View in Slack API Documentation} */ export function RadioButtons(params?: RadioButtonsParams): RadioButtonsBuilder { @@ -288,7 +300,7 @@ export function RadioButtons(params?: RadioButtonsParams): RadioButtonsBuilder { * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {int} [params.maxSelectedItems] Sets a limit to how many items the user can select. * - * {@link https://api.slack.com/reference/block-kit/block-elements#static_multi_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#static_multi_select|View in Slack API Documentation} */ export function StaticMultiSelect(params?: StaticMultiSelectParams): StaticMultiSelectBuilder { @@ -300,7 +312,7 @@ export function StaticMultiSelect(params?: StaticMultiSelectParams): StaticMulti * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action in interaction payloads. * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * - * {@link https://api.slack.com/reference/block-kit/block-elements#static_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#static_select|View in Slack API Documentation} */ export function StaticSelect(params?: StaticSelectParams): StaticSelectBuilder { @@ -316,7 +328,7 @@ export function StaticSelect(params?: StaticSelectParams): StaticSelectBuilder { * @param {int} [params.minLength] Sets a minimum character count in order for the user to submit the form. * @param {int} [params.maxLength] Sets a maximum character count allowed to send the form. * - * {@link https://api.slack.com/reference/block-kit/block-elements#input|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/plain-text-input-element|View in Slack API Documentation} */ export function TextInput(params?: TextInputParams): TextInputBuilder { @@ -329,7 +341,7 @@ export function TextInput(params?: TextInputParams): TextInputBuilder { * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {string} [params.initialTime] Sets the default selected time in the menu. * - * {@link https://api.slack.com/reference/block-kit/block-elements#timepicker|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/time-picker-element|View in Slack API Documentation} */ export function TimePicker(params?: TimePickerParams): TimePickerBuilder { @@ -342,7 +354,7 @@ export function TimePicker(params?: TimePickerParams): TimePickerBuilder { * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {string} [params.initialValue] Sets the default URL entered into the URL input at modal render. * - * {@link https://api.slack.com/reference/block-kit/block-elements#url|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/url-input-element|View in Slack API Documentation} */ export function URLInput(params?: URLInputParams): URLInputBuilder { @@ -355,7 +367,7 @@ export function URLInput(params?: URLInputParams): URLInputBuilder { * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {int} [params.maxSelectedItems] Sets a limit to how many items the user can select. * - * {@link https://api.slack.com/reference/block-kit/block-elements#users_multi_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#users_multi_select|View in Slack API Documentation} */ export function UserMultiSelect(params?: UserMultiSelectParams): UserMultiSelectBuilder { @@ -368,13 +380,61 @@ export function UserMultiSelect(params?: UserMultiSelectParams): UserMultiSelect * @param {string} [params.placeholder] Adds the text in place of the input before selected or interacted with. * @param {string} [params.initialUser] Setts the default selected user in the menu. * - * {@link https://api.slack.com/reference/block-kit/block-elements#users_select|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#users_select|View in Slack API Documentation} */ export function UserSelect(params?: UserSelectParams): UserSelectBuilder { return new UserSelectBuilder(params); } +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.text] Sets the display text for the workflow button. + * @param {string} [params.accessibilityLabel] Sets accessibility label. + * + * {@link https://docs.slack.dev/reference/block-kit/block-elements/workflow-button-element|View in Slack API Documentation} + */ + +export function WorkflowButton(params?: WorkflowButtonParams): WorkflowButtonBuilder { + return new WorkflowButtonBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action. + * @param {string} [params.icon] Sets the icon to display. + * @param {string} [params.text] Sets the text for the button. + * + * {@link https://docs.slack.dev/reference/block-kit/block-elements/icon-button-element|View in Slack API Documentation} + */ + +export function IconButton(params?: IconButtonParams): IconButtonBuilder { + return new IconButtonBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action. + * + * {@link https://docs.slack.dev/reference/block-kit/block-elements/feedback-buttons-element|View in Slack API Documentation} + */ + +export function FeedbackButtons(params?: FeedbackButtonsParams): FeedbackButtonsBuilder { + return new FeedbackButtonsBuilder(params); +} + +/** + * @param {Object} [params] Parameters passed to the constructor. + * @param {string} [params.actionId] Sets a string to be an identifier for the source of an action. + * @param {string} [params.placeholder] Sets placeholder text. + * + * {@link https://docs.slack.dev/reference/block-kit/block-elements/rich-text-input-element|View in Slack API Documentation} + */ + +export function RichTextInput(params?: RichTextInputParams): RichTextInputBuilder { + return new RichTextInputBuilder(params); +} + const elements = { Button, ChannelMultiSelect, @@ -399,6 +459,10 @@ const elements = { UserMultiSelect, UserSelect, FileInput, + WorkflowButton, + IconButton, + FeedbackButtons, + RichTextInput, }; // Strange export. I know. For IDE highlighting purposes. diff --git a/src/elements/number-input.ts b/src/elements/number-input.ts index cacd1c64..9154cbfc 100644 --- a/src/elements/number-input.ts +++ b/src/elements/number-input.ts @@ -42,7 +42,7 @@ export interface NumberInputBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#number + * @@link https://docs.slack.dev/reference/block-kit/block-elements/number-input-element * @@displayName Email Input */ diff --git a/src/elements/overflow-menu.ts b/src/elements/overflow-menu.ts index 2c2ccdb6..21ac2a12 100644 --- a/src/elements/overflow-menu.ts +++ b/src/elements/overflow-menu.ts @@ -23,7 +23,7 @@ export interface OverflowMenuBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#overflow + * @@link https://docs.slack.dev/reference/block-kit/block-elements/overflow-menu-element * @@displayName Overflow Menu */ diff --git a/src/elements/radio-buttons.ts b/src/elements/radio-buttons.ts index 1781dc52..cf956111 100644 --- a/src/elements/radio-buttons.ts +++ b/src/elements/radio-buttons.ts @@ -27,7 +27,7 @@ export interface RadioButtonsBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#radio + * @@link https://docs.slack.dev/reference/block-kit/block-elements/radio-button-group-element * @@displayName Radio Buttons */ diff --git a/src/elements/rich-text-input.ts b/src/elements/rich-text-input.ts new file mode 100644 index 00000000..36a16050 --- /dev/null +++ b/src/elements/rich-text-input.ts @@ -0,0 +1,73 @@ +import { ElementBuilderBase } from '../internal/base'; +import { ElementType } from '../internal/constants'; +import { SlackElementDto } from '../internal/dto'; +import { applyMixins, getPlainTextObject, getBuilderResult } from '../internal/helpers'; +import { + ActionId, + End, + FocusOnLoad, + Placeholder, +} from '../internal/methods'; + +import type { SlackDto } from '../internal/dto'; +import type { RichTextBuilder } from '../blocks/rich-text'; + +interface DispatchActionConfig { + trigger_actions_on?: ('on_enter_pressed' | 'on_character_entered')[]; +} + +export interface RichTextInputParams { + actionId?: string; + placeholder?: string; +} + +export interface RichTextInputBuilder extends ActionId, + End, + FocusOnLoad, + Placeholder { + initialValue(value: RichTextBuilder): this; + dispatchActionConfig(config: DispatchActionConfig): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/block-elements/rich-text-input-element + * @@displayName Rich Text Input + */ + +export class RichTextInputBuilder extends ElementBuilderBase { + /** @internal */ + + /** + * @description Sets the initial value for the rich text input. + * @param {RichTextBuilder} value - A RichText block builder with initial content. + */ + public initialValue(value: RichTextBuilder): this { + this.props.initialValue = value; + return this; + } + + /** + * @description Configures when to dispatch actions for this input. + * @param {DispatchActionConfig} config - Configuration for action dispatch triggers. + */ + public dispatchActionConfig(config: DispatchActionConfig): this { + this.props.dispatchActionConfig = config; + return this; + } + + public build(): Readonly { + return this.getResult(SlackElementDto, { + type: ElementType.RichTextInput, + placeholder: getPlainTextObject(this.props.placeholder), + initial_value: getBuilderResult(this.props.initialValue), + dispatch_action_config: this.props.dispatchActionConfig, + }); + } +} + +applyMixins(RichTextInputBuilder, [ + ActionId, + End, + FocusOnLoad, + Placeholder, +]); diff --git a/src/elements/static-multi-select.ts b/src/elements/static-multi-select.ts index bd78e8fc..15b03c80 100644 --- a/src/elements/static-multi-select.ts +++ b/src/elements/static-multi-select.ts @@ -29,7 +29,7 @@ export interface StaticMultiSelectParams { } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#static_multi_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#static_multi_select * @@displayName Static Multi-Select */ diff --git a/src/elements/static-select.ts b/src/elements/static-select.ts index 36f06b3b..c479e926 100644 --- a/src/elements/static-select.ts +++ b/src/elements/static-select.ts @@ -37,7 +37,7 @@ export interface StaticSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#static_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#static_select * @@displayName Static Select */ diff --git a/src/elements/text-input.ts b/src/elements/text-input.ts index 8ea2f54c..d1b3e884 100644 --- a/src/elements/text-input.ts +++ b/src/elements/text-input.ts @@ -37,7 +37,7 @@ export interface TextInputBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#input + * @@link https://docs.slack.dev/reference/block-kit/block-elements/plain-text-input-element * @@displayName Plain-Text Input */ diff --git a/src/elements/timepicker.ts b/src/elements/timepicker.ts index cc33569e..7acc9c60 100644 --- a/src/elements/timepicker.ts +++ b/src/elements/timepicker.ts @@ -29,7 +29,7 @@ export interface TimePickerBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#timepicker + * @@link https://docs.slack.dev/reference/block-kit/block-elements/time-picker-element * @@displayName Time Picker */ diff --git a/src/elements/url-input.ts b/src/elements/url-input.ts index ba07849f..e0d23e49 100644 --- a/src/elements/url-input.ts +++ b/src/elements/url-input.ts @@ -28,7 +28,7 @@ export interface URLInputBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#url + * @@link https://docs.slack.dev/reference/block-kit/block-elements/url-input-element * @@displayName URL Input */ diff --git a/src/elements/user-multi-select.ts b/src/elements/user-multi-select.ts index 75ddf660..fcd1fae8 100644 --- a/src/elements/user-multi-select.ts +++ b/src/elements/user-multi-select.ts @@ -30,7 +30,7 @@ export interface UserMultiSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#users_multi_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/multi-select-menu-element#users_multi_select * @@displayName User Multi-Select */ diff --git a/src/elements/user-select.ts b/src/elements/user-select.ts index c66556c4..9ad09abb 100644 --- a/src/elements/user-select.ts +++ b/src/elements/user-select.ts @@ -28,7 +28,7 @@ export interface UserSelectBuilder extends ActionId, } /** - * @@link https://api.slack.com/reference/block-kit/block-elements#users_select + * @@link https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element#users_select * @@displayName User Select */ diff --git a/src/elements/workflow-button.ts b/src/elements/workflow-button.ts new file mode 100644 index 00000000..fe641c61 --- /dev/null +++ b/src/elements/workflow-button.ts @@ -0,0 +1,84 @@ +import { ElementBuilderBase } from '../internal/base'; +import { ElementType } from '../internal/constants'; +import { SlackElementDto } from '../internal/dto'; +import { applyMixins, getPlainTextObject, getBuilderResult } from '../internal/helpers'; +import { + AccessibilityLabel, + Danger, + End, + Primary, + Text, +} from '../internal/methods'; + +import type { SlackDto } from '../internal/dto'; +import type { ConfirmationDialogBuilder } from '../bits'; + +interface WorkflowTrigger { + url: string; + customizable_input_parameters?: Array<{ + name: string; + value: string; + }>; +} + +interface Workflow { + trigger: WorkflowTrigger; +} + +export interface WorkflowButtonParams { + accessibilityLabel?: string; + text?: string; +} + +export interface WorkflowButtonBuilder extends AccessibilityLabel, + Danger, + End, + Primary, + Text { + workflow(workflow: Workflow): this; + confirm(dialog: ConfirmationDialogBuilder): this; +} + +/** + * @@link https://docs.slack.dev/reference/block-kit/block-elements/workflow-button-element + * @@displayName Workflow Button + */ + +export class WorkflowButtonBuilder extends ElementBuilderBase { + /** @internal */ + + /** + * @description Sets the workflow configuration with trigger URL and optional input parameters. + * @param {Workflow} workflow - The workflow configuration object. + */ + public workflow(workflow: Workflow): this { + this.props.workflow = workflow; + return this; + } + + /** + * @description Sets a confirmation dialog to be shown before the workflow is triggered. + * @param {ConfirmationDialogBuilder} dialog - A ConfirmationDialog builder. + */ + public confirm(dialog: ConfirmationDialogBuilder): this { + this.props.confirm = dialog; + return this; + } + + public build(): Readonly { + return this.getResult(SlackElementDto, { + type: ElementType.WorkflowButton, + text: getPlainTextObject(this.props.text), + workflow: this.props.workflow, + confirm: getBuilderResult(this.props.confirm), + }); + } +} + +applyMixins(WorkflowButtonBuilder, [ + AccessibilityLabel, + Danger, + End, + Primary, + Text, +]); diff --git a/src/internal/constants/block-types.ts b/src/internal/constants/block-types.ts index 8044d44e..b69f04f7 100644 --- a/src/internal/constants/block-types.ts +++ b/src/internal/constants/block-types.ts @@ -8,4 +8,8 @@ export enum BlockType { Image = 'image', Header = 'header', Video = 'video', + RichText = 'rich_text', + Markdown = 'markdown', + Table = 'table', + ContextActions = 'context_actions', } diff --git a/src/internal/constants/element-types.ts b/src/internal/constants/element-types.ts index e3db3418..89950e7c 100644 --- a/src/internal/constants/element-types.ts +++ b/src/internal/constants/element-types.ts @@ -22,4 +22,8 @@ export enum ElementType { EmailInput = 'email_text_input', NumberInput = 'number_input', FileInput = 'file_input', + WorkflowButton = 'workflow_button', + IconButton = 'icon_button', + FeedbackButtons = 'feedback_buttons', + RichTextInput = 'rich_text_input', } diff --git a/src/internal/constants/index.ts b/src/internal/constants/index.ts index 29c2cac2..ec56fa11 100644 --- a/src/internal/constants/index.ts +++ b/src/internal/constants/index.ts @@ -10,3 +10,4 @@ export * from './paginator-button-id'; export * from './props'; export * from './response-types'; export * from './surface-types'; +export * from './rich-text-element-types'; diff --git a/src/internal/constants/rich-text-element-types.ts b/src/internal/constants/rich-text-element-types.ts new file mode 100644 index 00000000..662de8e5 --- /dev/null +++ b/src/internal/constants/rich-text-element-types.ts @@ -0,0 +1,18 @@ +export enum RichTextElementType { + // Block-level elements + Section = 'rich_text_section', + List = 'rich_text_list', + Quote = 'rich_text_quote', + Preformatted = 'rich_text_preformatted', + // Inline elements + Text = 'text', + Emoji = 'emoji', + Link = 'link', + User = 'user', + Usergroup = 'usergroup', + Channel = 'channel', + Team = 'team', + Broadcast = 'broadcast', + Color = 'color', + Date = 'date', +} diff --git a/src/internal/dto/slack-dto.ts b/src/internal/dto/slack-dto.ts index 6595fe15..ca3c7e26 100644 --- a/src/internal/dto/slack-dto.ts +++ b/src/internal/dto/slack-dto.ts @@ -88,6 +88,20 @@ export enum Param { maxFiles = 'max_files', filetypes = 'filetypes', source = 'source', + rows = 'rows', + columnSettings = 'column_settings', + border = 'border', + indent = 'indent', + name = 'name', + unicode = 'unicode', + unsafe = 'unsafe', + format = 'format', + range = 'range', + teamId = 'team_id', + userId = 'user_id', + usergroupId = 'usergroup_id', + channelId = 'channel_id', + timestamp = 'timestamp', } export class SlackDto implements ObjectLiteral { diff --git a/src/internal/helpers/build-helpers.ts b/src/internal/helpers/build-helpers.ts index 28039e6f..47cbf5e7 100644 --- a/src/internal/helpers/build-helpers.ts +++ b/src/internal/helpers/build-helpers.ts @@ -40,6 +40,10 @@ export function getBuilderResults( } export function getPlainTextObject(text: string): Undefinable { + if (text !== undefined && typeof text !== 'string') { + throw new Error(`Text must be a string, but found ${typeof text}. If you are trying to pass a Rich Text block, please note that it is not supported in this field.`); + } + return valueOrUndefined(text) ? new PlainTextObject(text) : undefined; } @@ -48,6 +52,10 @@ export function getStringFromNumber(value: number): Undefinable { } export function getMarkdownObject(text: string): Undefinable { + if (text !== undefined && typeof text !== 'string') { + throw new Error(`Text must be a string, but found ${typeof text}. If you are trying to pass a Rich Text block, please note that it is not supported in this field.`); + } + return valueOrUndefined(text) ? new MarkdownObject(text) : undefined; } diff --git a/src/internal/methods/append-methods.ts b/src/internal/methods/append-methods.ts index 41e3c13f..0aa2708b 100644 --- a/src/internal/methods/append-methods.ts +++ b/src/internal/methods/append-methods.ts @@ -11,7 +11,7 @@ export abstract class Attachments extends Builder { /** * @description Adds attachments to your message. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -28,7 +28,7 @@ export abstract class Blocks extends Builder { * * **Required for modals, home tabs, and workflow steps** ⚠ * * Maximum of 100 blocks. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -46,7 +46,7 @@ export abstract class Elements extends Builder { * * Maximum of 5 elements. * * Supported elements are buttons, select and overflow menus, and date pickers. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -65,7 +65,7 @@ export abstract class Fields extends Builder { * * Maximum of 2000 characters for each field. * * Markdown supported. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -81,7 +81,7 @@ export abstract class Filter extends Builder { * **Slack Validation Rules and Tips:** * * Possible values are *im*, *impm*, *private*, and *public*. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -94,7 +94,7 @@ export abstract class InitialChannels extends Builder { /** * @description Pre-populates the menu with selected, default channels. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -107,7 +107,7 @@ export abstract class InitialConversations extends Builder { /** * @description Pre-populates the menu with selected, default conversations. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -123,7 +123,7 @@ export abstract class InitialOptions extends Builder { * **Slack Validation Rules and Tips:** * * Must be exact matches to options in the menu. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -136,7 +136,7 @@ export abstract class InitialUsers extends Builder { /** * @description Pre-populates the menu with selected, default users. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -153,7 +153,7 @@ export abstract class OptionGroups extends Builder { * * Maximum of 100 options. * * Both options and options groups cannot be defined at the same time for any element. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -171,7 +171,7 @@ export abstract class Options extends Builder { * * Maximum of 100 options. * * Both options and options groups cannot be defined at the same time for any element. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ diff --git a/src/internal/methods/configuration-methods.ts b/src/internal/methods/configuration-methods.ts index 2c425f84..228f987c 100644 --- a/src/internal/methods/configuration-methods.ts +++ b/src/internal/methods/configuration-methods.ts @@ -13,7 +13,7 @@ export abstract class AsUser extends Builder { /** * @description Sets the message to be sent as either the user whose auth token is being used or as the bot user associated with your app. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -26,7 +26,7 @@ export abstract class ClearOnClose extends Builder { /** * @description Instructs the Slack API to close all open views in the view stack when this particular view is closed. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -39,7 +39,7 @@ export abstract class Danger extends Builder { /** * @description For a button element, this changes the color to red. For confirmation dialogs, this sets the main button in the bottom right corner to red, indicating that an action is potentially destructive. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -55,7 +55,7 @@ export abstract class DefaultToCurrentConversation extends Builder { * **Slack Validation Rules and Tips:** * * If initial conversations are provided, this option is ignored. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -68,7 +68,7 @@ export abstract class DeleteOriginal extends Builder { /** * @description Instructs the Slack API to delete the message from which the interaction originated when sending the current message. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -81,7 +81,7 @@ export abstract class DispatchAction extends Builder { /** * @description Instructs the Slack API to send an interaction event to your app when the element in the input block has been interacted with. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -94,7 +94,7 @@ export abstract class DispatchActionOnCharacterEntered extends Builder { /** * @description Instructs the Slack API to dispatch an interaction payload to your app when the user enters or deletes a character in the input. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -107,7 +107,7 @@ export abstract class DispatchActionOnEnterPressed extends Builder { /** * @description Instructs the Slack API to dispatch an interaction payload to your app when the user presses the enter key while the input is in focus. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -120,7 +120,7 @@ export abstract class Ephemeral extends Builder { /** * @description Instructs the Slack API to display the message only to the user who invoked the interaction payload or slash command. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -133,7 +133,7 @@ export abstract class ExcludeExternalSharedChannels extends Builder { /** * @description Excludes conversations shared with external organizations from the menu's options. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -146,7 +146,7 @@ export abstract class ExcludeBotUsers extends Builder { /** * @description Excludes conversations with bot users from the menu's options. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -159,7 +159,7 @@ export abstract class FocusOnLoad extends Builder { /** * @description Sets an element to have auto focus on opening the view * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -172,7 +172,7 @@ export abstract class IgnoreMarkdown extends Builder { /** * @description Instructs the Slack API to ignore any markdown in the text property of the message. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -185,7 +185,7 @@ export abstract class InChannel extends Builder { /** * @description Instructs the Slack API to make the message visible to everyone in the channel from which the interaction payload or slash command originated. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -198,7 +198,7 @@ export abstract class Multiline extends Builder { /** * @description Sets the text input to be a larger, multi-line input for larger portions of text. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -211,7 +211,7 @@ export abstract class NotifyOnClose extends Builder { /** * @description Instructs the Slack API to send an interaction payload to your app when the view is closed. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -224,7 +224,7 @@ export abstract class Optional extends Builder { /** * @description Lets the Slack API know that inputting data in the the input is not required for the view to be successfully submitted. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -237,7 +237,7 @@ export abstract class Primary extends Builder { /** * @description For a button element, this changes the color to green. For confirmation dialogs, this sets the main button in the bottom right corner to green, which is meant to confirm the action. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -250,7 +250,7 @@ export abstract class ReplaceOriginal extends Builder { /** * @description Instructs the Slack API to replace the original message, from which the interaction payload originated, with the current message. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -266,7 +266,7 @@ export abstract class ResponseUrlEnabled extends Builder { * **Slack Validation Rules and Tips:** * * Only available in views with input blocks. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -279,7 +279,7 @@ export abstract class SubmitDisabled extends Builder { /** * @description Configures the workflow step to have a disabled submit button until the user has input data into one or more inputs. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ diff --git a/src/internal/methods/other-methods.ts b/src/internal/methods/other-methods.ts index 42e0cdfd..e6ae25ac 100644 --- a/src/internal/methods/other-methods.ts +++ b/src/internal/methods/other-methods.ts @@ -30,7 +30,7 @@ export abstract class End extends Builder { /** * @description Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -43,7 +43,7 @@ export abstract class GetAttachments extends Builder { /** * @description Builds the view and returns a Slack API-compatible array of attachments. * - * {@link https://api.slack.com/reference/messaging/attachments|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/messaging/attachments|View in Slack API Documentation} */ public getAttachments(): Readonly[] { @@ -55,7 +55,7 @@ export abstract class GetBlocks extends Builder { /** * @description Builds the view and returns a Slack API-compatible array of blocks. * - * {@link https://api.slack.com/block-kit|View in Slack API Documentation} + * {@link https://docs.slack.dev/reference/block-kit|View in Slack API Documentation} */ public getBlocks(): Readonly[] { diff --git a/src/internal/methods/set-methods.ts b/src/internal/methods/set-methods.ts index 3c7bbf1e..36e95055 100644 --- a/src/internal/methods/set-methods.ts +++ b/src/internal/methods/set-methods.ts @@ -14,7 +14,7 @@ export abstract class AccessibilityLabel extends Builder { * **Slack Validation Rules and Tips:** * * Maximum of 75 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -31,7 +31,7 @@ export abstract class Accessory extends Builder { * * Maximum of 1 element. * * Can be any one of the elements. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -49,7 +49,7 @@ export abstract class ActionId extends Builder { * * Each element in a view or message must have its own unique action ID. * * Maximum of 255 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -68,7 +68,7 @@ export abstract class AltText extends Builder { * * Maximum of 2000 characters. * * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -85,7 +85,7 @@ export abstract class AuthorName extends Builder { * * Maximum of 50 characters. * * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -103,7 +103,7 @@ export abstract class BlockId extends Builder { * * Each block in a view or message must have its own unique action ID. * * If the contents of a block is updated, the block ID should also be updated. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -120,7 +120,7 @@ export abstract class CallbackId extends Builder { * * Maximum of 255 characters. * * It is recommended that sensitive data not be stored in the callback ID. Instead, use the `privateMetaData()` method. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -133,7 +133,7 @@ export abstract class Channel extends Builder { /** * @description Sets the Slack channel ID to which the message will be sent via the API. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -149,7 +149,7 @@ export abstract class Close extends Builder { * **Slack Validation Rules and Tips:** * * Maximum of 24 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -162,7 +162,7 @@ export abstract class Color extends Builder { /** * @description Sets the color for the blockquote border to the left of the attachment. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -175,7 +175,7 @@ export abstract class Confirm extends Builder { /** * @description For confirmation dialogs, sets the text of the button that confirms the action to which the confirmation dialog has been added. For elements, adds a confirmation dialog that is displayed when the user interacts with the element to confirm the selection or action. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -192,7 +192,7 @@ export abstract class Deny extends Builder { * * **Required** ⚠ * * Maximum of 30 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -208,7 +208,7 @@ export abstract class Description extends Builder { * **Slack Validation Rules and Tips:** * * Maximum of 75 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -226,7 +226,7 @@ export abstract class Element extends Builder { * * Maximum of 1 element. * * Supports text inputs, select and multi-select menus, as well as date pickers and checkbox inputs. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -243,7 +243,7 @@ export abstract class ExternalId extends Builder { * * Maximum of 255 characters. * * When used, an external ID must be unique to a certain view. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -256,7 +256,7 @@ export abstract class Fallback extends Builder { /** * @description Sets the plain text summary of the attachment used in clients that can't display formatted text (eg. IRC, mobile notifications). * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -272,7 +272,7 @@ export abstract class Hint extends Builder { * **Slack Validation Rules and Tips:** * * Maximum of 2000 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -289,7 +289,7 @@ export abstract class ImageUrl extends Builder { * * **Required** ⚠ * * Maximum of 2000 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -302,7 +302,7 @@ export abstract class InitialChannel extends Builder { /** * @description Pre-populates the menu with a selected, default channel. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -315,7 +315,7 @@ export abstract class InitialConversation extends Builder { /** * @description Pre-populates the menu with a selected, default conversation. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -328,7 +328,7 @@ export abstract class InitialDate extends Builder { /** * @description Pre-populates the date picker with a selected, default date. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -341,7 +341,7 @@ export abstract class InitialDateTime extends Builder { /** * @description Pre-populates the date time picker with a selected, default date and time. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -357,7 +357,7 @@ export abstract class InitialOption extends Builder { * **Slack Validation Rules and Tips:** * * Must be an exact match for one of the options in the menu. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -373,7 +373,7 @@ export abstract class InitialTime extends Builder { * **Slack Validation Rules and Tips:** * * Set in HH:mm format, where HH is 24-hour hour format and mm is minutes with a leading zero. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -386,7 +386,7 @@ export abstract class InitialUser extends Builder { /** * @description Pre-populates the menu with a selected, default user. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -399,7 +399,7 @@ export abstract class InitialValue extends Builder { /** * @description Pre-populates the input with a default value. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -415,7 +415,7 @@ export abstract class IsDecimalAllowed extends Builder { * **Slack Validation Rules and Tips:** * * **Required** ⚠ * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -433,7 +433,7 @@ export abstract class Label extends Builder { * * For input blocks, maximum of 2000 characters. * * For option groups, maximum of 75 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -446,7 +446,7 @@ export abstract class MaxLength extends Builder { /** * @description Sets a maximum character count allowed in the given text input. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -459,7 +459,7 @@ export abstract class MaxSelectedItems extends Builder { /** * @description Sets a limit to how many items the user can select in the multi-select menu. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -475,7 +475,7 @@ export abstract class MaxValue extends Builder { * **Slack Validation Rules and Tips:** * * Cannot be less than the minimum value. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -491,7 +491,7 @@ export abstract class MinQueryLength extends Builder { * **Slack Validation Rules and Tips:** * * If not set, the request will be sent on every character entered or removed. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -507,7 +507,7 @@ export abstract class MinLength extends Builder { * **Slack Validation Rules and Tips:** * * Maximum 3000 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -523,7 +523,7 @@ export abstract class MinValue extends Builder { * **Slack Validation Rules and Tips:** * * Cannot be less than the maximum value. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -539,7 +539,7 @@ export abstract class Placeholder extends Builder { * **Slack Validation Rules and Tips:** * * Maximum of 150 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -552,7 +552,7 @@ export abstract class PostAt extends Builder { /** * @description Sets a time in the future for the message to be sent to the channel or user, as a scheduled message. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -569,7 +569,7 @@ export abstract class PrivateMetaData extends Builder { * * Maximum 3000 characters. * * Typically used to persist data or store context between views. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -582,7 +582,7 @@ export abstract class ProviderIconUrl extends Builder { /** * @description Icon for the video provider - ex. YouTube or Vimeo icon. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -595,7 +595,7 @@ export abstract class ProviderName extends Builder { /** * @description The originating application or domain of the video ex. YouTube or Vimeo. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -611,7 +611,7 @@ export abstract class Submit extends Builder { * **Slack Validation Rules and Tips:** * * Maximum of 24 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -631,7 +631,7 @@ export abstract class Text extends Builder { * * For confirmation dialogs, maximum of 75 characters. * * For section and header blocks, maximum of 3000 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -644,7 +644,7 @@ export abstract class ThreadTs extends Builder { /** * @description Instructs the Slack API to send the message to the thread of the message associated with the timestamp. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -660,7 +660,7 @@ export abstract class ThumbnailUrl extends Builder { * **Slack Validation Rules and Tips:** * * **Required property for Video blocks** ⚠ * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -679,7 +679,7 @@ export abstract class Title extends Builder { * * For images, maximum of 2000 characters. * * For confirmation dialogs, maximum of 100 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -696,7 +696,7 @@ export abstract class TitleUrl extends Builder { * * Must correspond to the non-embeddable URL for the video. * * Must go to an HTTPS URL. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -709,7 +709,7 @@ export abstract class Ts extends Builder { /** * @description Instructs the Slack API to use the message to replaced an existing message. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -726,7 +726,7 @@ export abstract class Url extends Builder { * * Maximum of 3000 characters. * * For options, it is only supported for options in an overflow menu. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -743,7 +743,7 @@ export abstract class Value extends Builder { * * For buttons, maximum of 2000 characters. * * For options, maximum of 75 characters. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -761,7 +761,7 @@ export abstract class VideoUrl extends Builder { * * Must match any existing unfurl domains within the app. * * Must point to an HTTPS URL. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -774,7 +774,7 @@ export abstract class MaxFiles extends Builder { /** * @description Maximum number of files that can be uploaded for this file_input element. Minimum of 1, maximum of 10. Defaults to 10 if not specified. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ @@ -793,7 +793,7 @@ export abstract class Filetypes extends Builder { * * Maximum of 2000 characters for each field. * * Markdown supported. * - * {@link https://api.slack.com/block-kit|Open Official Slack Block Kit Documentation} + * {@link https://docs.slack.dev/reference/block-kit|Open Official Slack Block Kit Documentation} * {@link https://www.blockbuilder.dev|Open Block Builder Documentation} */ diff --git a/src/surfaces/home-tab.ts b/src/surfaces/home-tab.ts index ac7316bc..d39ac55f 100644 --- a/src/surfaces/home-tab.ts +++ b/src/surfaces/home-tab.ts @@ -35,7 +35,7 @@ export interface HomeTabBuilder extends Blocks, } /** - * @@link https://api.slack.com/reference/surfaces/views + * @@link https://docs.slack.dev/surfaces/app-home * @@displayName Home Tab */ diff --git a/src/surfaces/index.ts b/src/surfaces/index.ts index e9aeb295..943f3634 100644 --- a/src/surfaces/index.ts +++ b/src/surfaces/index.ts @@ -26,7 +26,7 @@ export type { * @param {string} [params.externalId] Sets a custom identifier that must be unique for all views on a per-team basis. * @param {string} [params.privateMetaData] Sets a string sent back to your server together with all action and submission events. * - * {@link https://api.slack.com/surfaces/tabs|View in Slack API Documentation} + * {@link https://docs.slack.dev/surfaces/app-home|View in Slack API Documentation} */ export function HomeTab(params?: HomeTabParams): HomeTabBuilder { @@ -40,7 +40,7 @@ export function HomeTab(params?: HomeTabParams): HomeTabBuilder { * @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. * - * {@link https://api.slack.com/messaging/composing|View in Slack API Documentation} + * {@link https://docs.slack.dev/messaging/composing|View in Slack API Documentation} */ export function Message(params?: MessageParams): MessageBuilder { @@ -56,7 +56,7 @@ export function Message(params?: MessageParams): MessageBuilder { * @param {string} [params.externalId] Sets a custom identifier that must be unique for all views on a per-team basis. * @param {string} [params.privateMetaData] Sets a string sent back to your server together with all action and submission events. * - * {@link https://api.slack.com/reference/surfaces/views|View in Slack API Documentation} + * {@link https://docs.slack.dev/surfaces/modals|View in Slack API Documentation} */ export function Modal(params?: ModalParams): ModalBuilder { @@ -68,7 +68,7 @@ export function Modal(params?: ModalParams): ModalBuilder { * @param {string} [params.callbackId] Sets a string sent back to your server together with all action and submission events. * @param {string} [params.privateMetaData] Sets a string sent back to your server together with all action and submission events. * - * {@link https://api.slack.com/reference/surfaces/views|View in Slack API Documentation} + * {@link https://docs.slack.dev/surfaces/modals|View in Slack API Documentation} */ export function WorkflowStep(params?: WorkflowStepParams): WorkflowStepBuilder { diff --git a/src/surfaces/message.ts b/src/surfaces/message.ts index 40f43dea..3130cc0c 100644 --- a/src/surfaces/message.ts +++ b/src/surfaces/message.ts @@ -56,7 +56,7 @@ export interface MessageBuilder extends AsUser, } /** - * @@link https://api.slack.com/messaging/composing + * @@link https://docs.slack.dev/messaging/composing * @@displayName Message */ diff --git a/src/surfaces/modal.ts b/src/surfaces/modal.ts index c4820c53..e1755056 100644 --- a/src/surfaces/modal.ts +++ b/src/surfaces/modal.ts @@ -49,7 +49,7 @@ export interface ModalBuilder extends Blocks, } /** - * @@link https://api.slack.com/reference/surfaces/views + * @@link https://docs.slack.dev/surfaces/modals * @@displayName Modal */ diff --git a/src/surfaces/workflow-step.ts b/src/surfaces/workflow-step.ts index 2ec5fcfd..68e8a9c0 100644 --- a/src/surfaces/workflow-step.ts +++ b/src/surfaces/workflow-step.ts @@ -34,7 +34,7 @@ export interface WorkflowStepBuilder extends Blocks, } /** - * @@link https://api.slack.com/reference/workflows/configuration-view + * @@link https://docs.slack.dev/workflows/workflow-steps * @@displayName Workflow Step */ diff --git a/tests/bits/mocks/index.ts b/tests/bits/mocks/index.ts index 5767d3ac..c9d8300b 100644 --- a/tests/bits/mocks/index.ts +++ b/tests/bits/mocks/index.ts @@ -2,3 +2,15 @@ export * as Attachment from './attachment.mock'; export * as ConfirmationDialog from './confirmation-dialog.mock'; export * as Option from './option.mock'; export * as OptionGroup from './option-group.mock'; +export * as RichTextSection from './rich-text-section.mock'; +export * as RichTextList from './rich-text-list.mock'; +export * as RichTextQuote from './rich-text-quote.mock'; +export * as RichTextPreformatted from './rich-text-preformatted.mock'; +export * as RichTextText from './rich-text-text.mock'; +export * as RichTextEmoji from './rich-text-emoji.mock'; +export * as RichTextLink from './rich-text-link.mock'; +export * as RichTextUser from './rich-text-user.mock'; +export * as RichTextChannel from './rich-text-channel.mock'; +export * as RichTextUsergroup from './rich-text-usergroup.mock'; +export * as RichTextBroadcast from './rich-text-broadcast.mock'; +export * as RichTextDate from './rich-text-date.mock'; diff --git a/tests/bits/mocks/rich-text-broadcast.mock.ts b/tests/bits/mocks/rich-text-broadcast.mock.ts new file mode 100644 index 00000000..efb55d21 --- /dev/null +++ b/tests/bits/mocks/rich-text-broadcast.mock.ts @@ -0,0 +1,7 @@ +import { RichTextBroadcastBuilder } from '../../../src/bits/rich-text-broadcast'; + +export const params = { + range: 'here' as const, +}; + +export const mock = new RichTextBroadcastBuilder(params); diff --git a/tests/bits/mocks/rich-text-channel.mock.ts b/tests/bits/mocks/rich-text-channel.mock.ts new file mode 100644 index 00000000..7b1ad04c --- /dev/null +++ b/tests/bits/mocks/rich-text-channel.mock.ts @@ -0,0 +1,7 @@ +import { RichTextChannelBuilder } from '../../../src/bits/rich-text-channel'; + +export const params = { + channelId: 'C1234ABCD', +}; + +export const mock = new RichTextChannelBuilder(params); diff --git a/tests/bits/mocks/rich-text-color.mock.ts b/tests/bits/mocks/rich-text-color.mock.ts new file mode 100644 index 00000000..7a975bef --- /dev/null +++ b/tests/bits/mocks/rich-text-color.mock.ts @@ -0,0 +1,7 @@ +import { RichTextColorBuilder } from '../../../src/bits/rich-text-color'; + +export const params = { + value: '#FF5733', +}; + +export const mock = new RichTextColorBuilder(params); diff --git a/tests/bits/mocks/rich-text-date.mock.ts b/tests/bits/mocks/rich-text-date.mock.ts new file mode 100644 index 00000000..51a2cb35 --- /dev/null +++ b/tests/bits/mocks/rich-text-date.mock.ts @@ -0,0 +1,8 @@ +import { RichTextDateBuilder } from '../../../src/bits/rich-text-date'; + +export const params = { + timestamp: 1628633820, + format: '{date_long}', +}; + +export const mock = new RichTextDateBuilder(params); diff --git a/tests/bits/mocks/rich-text-emoji.mock.ts b/tests/bits/mocks/rich-text-emoji.mock.ts new file mode 100644 index 00000000..80fd9804 --- /dev/null +++ b/tests/bits/mocks/rich-text-emoji.mock.ts @@ -0,0 +1,7 @@ +import { RichTextEmojiBuilder } from '../../../src/bits/rich-text-emoji'; + +export const params = { + name: 'wave', +}; + +export const mock = new RichTextEmojiBuilder(params); diff --git a/tests/bits/mocks/rich-text-link.mock.ts b/tests/bits/mocks/rich-text-link.mock.ts new file mode 100644 index 00000000..08e36b04 --- /dev/null +++ b/tests/bits/mocks/rich-text-link.mock.ts @@ -0,0 +1,8 @@ +import { RichTextLinkBuilder } from '../../../src/bits/rich-text-link'; + +export const params = { + url: 'https://example.com', + text: 'Click here', +}; + +export const mock = new RichTextLinkBuilder(params); diff --git a/tests/bits/mocks/rich-text-list.mock.ts b/tests/bits/mocks/rich-text-list.mock.ts new file mode 100644 index 00000000..f669d8c6 --- /dev/null +++ b/tests/bits/mocks/rich-text-list.mock.ts @@ -0,0 +1,9 @@ +import { RichTextListBuilder } from '../../../src/bits/rich-text-list'; + +export const params = { + style: 'bullet' as const, + indent: 0, + border: 0 as const, +}; + +export const mock = new RichTextListBuilder(params); diff --git a/tests/bits/mocks/rich-text-preformatted.mock.ts b/tests/bits/mocks/rich-text-preformatted.mock.ts new file mode 100644 index 00000000..cc4c1100 --- /dev/null +++ b/tests/bits/mocks/rich-text-preformatted.mock.ts @@ -0,0 +1,7 @@ +import { RichTextPreformattedBuilder } from '../../../src/bits/rich-text-preformatted'; + +export const params = { + border: 0 as const, +}; + +export const mock = new RichTextPreformattedBuilder(params); diff --git a/tests/bits/mocks/rich-text-quote.mock.ts b/tests/bits/mocks/rich-text-quote.mock.ts new file mode 100644 index 00000000..30edb024 --- /dev/null +++ b/tests/bits/mocks/rich-text-quote.mock.ts @@ -0,0 +1,7 @@ +import { RichTextQuoteBuilder } from '../../../src/bits/rich-text-quote'; + +export const params = { + border: 0 as const, +}; + +export const mock = new RichTextQuoteBuilder(params); diff --git a/tests/bits/mocks/rich-text-section.mock.ts b/tests/bits/mocks/rich-text-section.mock.ts new file mode 100644 index 00000000..656b76da --- /dev/null +++ b/tests/bits/mocks/rich-text-section.mock.ts @@ -0,0 +1,5 @@ +import { RichTextSectionBuilder } from '../../../src/bits/rich-text-section'; + +export const params = {}; + +export const mock = new RichTextSectionBuilder(params); diff --git a/tests/bits/mocks/rich-text-team.mock.ts b/tests/bits/mocks/rich-text-team.mock.ts new file mode 100644 index 00000000..67156edd --- /dev/null +++ b/tests/bits/mocks/rich-text-team.mock.ts @@ -0,0 +1,7 @@ +import { RichTextTeamBuilder } from '../../../src/bits/rich-text-team'; + +export const params = { + teamId: 'T1234ABCD', +}; + +export const mock = new RichTextTeamBuilder(params); diff --git a/tests/bits/mocks/rich-text-text.mock.ts b/tests/bits/mocks/rich-text-text.mock.ts new file mode 100644 index 00000000..e9c5355e --- /dev/null +++ b/tests/bits/mocks/rich-text-text.mock.ts @@ -0,0 +1,7 @@ +import { RichTextTextBuilder } from '../../../src/bits/rich-text-text'; + +export const params = { + text: 'Hello, world!', +}; + +export const mock = new RichTextTextBuilder(params); diff --git a/tests/bits/mocks/rich-text-user.mock.ts b/tests/bits/mocks/rich-text-user.mock.ts new file mode 100644 index 00000000..82436040 --- /dev/null +++ b/tests/bits/mocks/rich-text-user.mock.ts @@ -0,0 +1,7 @@ +import { RichTextUserBuilder } from '../../../src/bits/rich-text-user'; + +export const params = { + userId: 'U1234ABCD', +}; + +export const mock = new RichTextUserBuilder(params); diff --git a/tests/bits/mocks/rich-text-usergroup.mock.ts b/tests/bits/mocks/rich-text-usergroup.mock.ts new file mode 100644 index 00000000..efc553d1 --- /dev/null +++ b/tests/bits/mocks/rich-text-usergroup.mock.ts @@ -0,0 +1,7 @@ +import { RichTextUsergroupBuilder } from '../../../src/bits/rich-text-usergroup'; + +export const params = { + usergroupId: 'S1234ABCD', +}; + +export const mock = new RichTextUsergroupBuilder(params); diff --git a/tests/bits/rich-text-broadcast.spec.ts b/tests/bits/rich-text-broadcast.spec.ts new file mode 100644 index 00000000..72910465 --- /dev/null +++ b/tests/bits/rich-text-broadcast.spec.ts @@ -0,0 +1,19 @@ +import { RichTextBroadcastBuilder } from '../../src/bits/rich-text-broadcast'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextBroadcastBuilder', () => { + it('should build with type broadcast', () => { + const result = new RichTextBroadcastBuilder({ range: 'here' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Broadcast); + }); + + it('should apply styles', () => { + const result = new RichTextBroadcastBuilder({ range: 'here' }) + .bold() + .italic() + .build() as any; + expect(result.style).toEqual({ bold: true, italic: true }); + }); +}); diff --git a/tests/bits/rich-text-channel.spec.ts b/tests/bits/rich-text-channel.spec.ts new file mode 100644 index 00000000..f30c9b51 --- /dev/null +++ b/tests/bits/rich-text-channel.spec.ts @@ -0,0 +1,19 @@ +import { RichTextChannelBuilder } from '../../src/bits/rich-text-channel'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextChannelBuilder', () => { + it('should build with type channel', () => { + const result = new RichTextChannelBuilder({ channelId: 'C1234ABCD' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Channel); + }); + + it('should apply styles', () => { + const result = new RichTextChannelBuilder({ channelId: 'C1234ABCD' }) + .bold() + .italic() + .build() as any; + expect(result.style).toEqual({ bold: true, italic: true }); + }); +}); diff --git a/tests/bits/rich-text-color.spec.ts b/tests/bits/rich-text-color.spec.ts new file mode 100644 index 00000000..ad86ea04 --- /dev/null +++ b/tests/bits/rich-text-color.spec.ts @@ -0,0 +1,19 @@ +import { RichTextColorBuilder as Class } from '../../src/bits/rich-text-color'; +import { SlackDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/rich-text-color.mock'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'RichTextColor'; +const category = 'Bits'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig: unknown[] = []; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/bits/rich-text-date.spec.ts b/tests/bits/rich-text-date.spec.ts new file mode 100644 index 00000000..fb8c7b9a --- /dev/null +++ b/tests/bits/rich-text-date.spec.ts @@ -0,0 +1,19 @@ +import { RichTextDateBuilder } from '../../src/bits/rich-text-date'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextDateBuilder', () => { + it('should build with type date', () => { + const result = new RichTextDateBuilder({ timestamp: 1628633820 }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Date); + }); + + it('should apply styles', () => { + const result = new RichTextDateBuilder({ timestamp: 1628633820 }) + .bold() + .italic() + .build() as any; + expect(result.style).toEqual({ bold: true, italic: true }); + }); +}); diff --git a/tests/bits/rich-text-emoji.spec.ts b/tests/bits/rich-text-emoji.spec.ts new file mode 100644 index 00000000..54de5eb8 --- /dev/null +++ b/tests/bits/rich-text-emoji.spec.ts @@ -0,0 +1,11 @@ +import { RichTextEmojiBuilder } from '../../src/bits/rich-text-emoji'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextEmojiBuilder', () => { + it('should build with type emoji', () => { + const result = new RichTextEmojiBuilder({ name: 'wave' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Emoji); + }); +}); diff --git a/tests/bits/rich-text-link.spec.ts b/tests/bits/rich-text-link.spec.ts new file mode 100644 index 00000000..135ce1a6 --- /dev/null +++ b/tests/bits/rich-text-link.spec.ts @@ -0,0 +1,26 @@ +import { RichTextLinkBuilder } from '../../src/bits/rich-text-link'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextLinkBuilder', () => { + it('should build with type link', () => { + const result = new RichTextLinkBuilder({ url: 'https://example.com' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Link); + }); + + it('should apply bold style', () => { + const result = new RichTextLinkBuilder({ url: 'https://example.com' }) + .bold() + .build() as any; + expect(result.style).toEqual({ bold: true }); + }); + + it('should apply multiple styles', () => { + const result = new RichTextLinkBuilder({ url: 'https://example.com' }) + .bold() + .italic() + .build() as any; + expect(result.style).toEqual({ bold: true, italic: true }); + }); +}); diff --git a/tests/bits/rich-text-list.spec.ts b/tests/bits/rich-text-list.spec.ts new file mode 100644 index 00000000..bc889361 --- /dev/null +++ b/tests/bits/rich-text-list.spec.ts @@ -0,0 +1,11 @@ +import { RichTextListBuilder } from '../../src/bits/rich-text-list'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextListBuilder', () => { + it('should build with type rich_text_list', () => { + const result = new RichTextListBuilder({ style: 'bullet' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.List); + }); +}); diff --git a/tests/bits/rich-text-preformatted.spec.ts b/tests/bits/rich-text-preformatted.spec.ts new file mode 100644 index 00000000..17d62c7d --- /dev/null +++ b/tests/bits/rich-text-preformatted.spec.ts @@ -0,0 +1,11 @@ +import { RichTextPreformattedBuilder } from '../../src/bits/rich-text-preformatted'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextPreformattedBuilder', () => { + it('should build with type rich_text_preformatted', () => { + const result = new RichTextPreformattedBuilder().build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Preformatted); + }); +}); diff --git a/tests/bits/rich-text-quote.spec.ts b/tests/bits/rich-text-quote.spec.ts new file mode 100644 index 00000000..92bf227e --- /dev/null +++ b/tests/bits/rich-text-quote.spec.ts @@ -0,0 +1,11 @@ +import { RichTextQuoteBuilder } from '../../src/bits/rich-text-quote'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextQuoteBuilder', () => { + it('should build with type rich_text_quote', () => { + const result = new RichTextQuoteBuilder().build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Quote); + }); +}); diff --git a/tests/bits/rich-text-section.spec.ts b/tests/bits/rich-text-section.spec.ts new file mode 100644 index 00000000..437a9ee7 --- /dev/null +++ b/tests/bits/rich-text-section.spec.ts @@ -0,0 +1,20 @@ +import { RichTextSectionBuilder } from '../../src/bits/rich-text-section'; +import { RichTextTextBuilder } from '../../src/bits/rich-text-text'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextSectionBuilder', () => { + it('should build with type rich_text_section', () => { + const result = new RichTextSectionBuilder().build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Section); + }); + + it('should build with elements', () => { + const result = new RichTextSectionBuilder() + .elements(new RichTextTextBuilder({ text: 'Hello' })) + .build() as any; + expect(result.elements).toHaveLength(1); + expect(result.elements[0].type).toBe(RichTextElementType.Text); + }); +}); diff --git a/tests/bits/rich-text-team.spec.ts b/tests/bits/rich-text-team.spec.ts new file mode 100644 index 00000000..b0be2ccc --- /dev/null +++ b/tests/bits/rich-text-team.spec.ts @@ -0,0 +1,19 @@ +import { RichTextTeamBuilder as Class } from '../../src/bits/rich-text-team'; +import { SlackDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/rich-text-team.mock'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'RichTextTeam'; +const category = 'Bits'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig: unknown[] = []; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/bits/rich-text-text.spec.ts b/tests/bits/rich-text-text.spec.ts new file mode 100644 index 00000000..0ad7c568 --- /dev/null +++ b/tests/bits/rich-text-text.spec.ts @@ -0,0 +1,44 @@ +import { RichTextTextBuilder } from '../../src/bits/rich-text-text'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextTextBuilder', () => { + it('should build with type text', () => { + const result = new RichTextTextBuilder({ text: 'Hello' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Text); + }); + + it('should apply bold style', () => { + const result = new RichTextTextBuilder({ text: 'Hello' }).bold().build() as any; + expect(result.style).toEqual({ bold: true }); + }); + + it('should apply italic style', () => { + const result = new RichTextTextBuilder({ text: 'Hello' }).italic().build() as any; + expect(result.style).toEqual({ italic: true }); + }); + + it('should apply strike style', () => { + const result = new RichTextTextBuilder({ text: 'Hello' }).strike().build() as any; + expect(result.style).toEqual({ strike: true }); + }); + + it('should apply code style', () => { + const result = new RichTextTextBuilder({ text: 'Hello' }).code().build() as any; + expect(result.style).toEqual({ code: true }); + }); + + it('should apply multiple styles', () => { + const result = new RichTextTextBuilder({ text: 'Hello' }) + .bold() + .italic() + .build() as any; + expect(result.style).toEqual({ bold: true, italic: true }); + }); + + it('should not include style when no styles applied', () => { + const result = new RichTextTextBuilder({ text: 'Hello' }).build() as any; + expect(result.style).toBeUndefined(); + }); +}); diff --git a/tests/bits/rich-text-user.spec.ts b/tests/bits/rich-text-user.spec.ts new file mode 100644 index 00000000..eadf235e --- /dev/null +++ b/tests/bits/rich-text-user.spec.ts @@ -0,0 +1,19 @@ +import { RichTextUserBuilder } from '../../src/bits/rich-text-user'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextUserBuilder', () => { + it('should build with type user', () => { + const result = new RichTextUserBuilder({ userId: 'U1234ABCD' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.User); + }); + + it('should apply styles', () => { + const result = new RichTextUserBuilder({ userId: 'U1234ABCD' }) + .bold() + .italic() + .build() as any; + expect(result.style).toEqual({ bold: true, italic: true }); + }); +}); diff --git a/tests/bits/rich-text-usergroup.spec.ts b/tests/bits/rich-text-usergroup.spec.ts new file mode 100644 index 00000000..794c1ae8 --- /dev/null +++ b/tests/bits/rich-text-usergroup.spec.ts @@ -0,0 +1,19 @@ +import { RichTextUsergroupBuilder } from '../../src/bits/rich-text-usergroup'; +import { SlackDto } from '../../src/internal'; +import { RichTextElementType } from '../../src/internal/constants'; + +describe('RichTextUsergroupBuilder', () => { + it('should build with type usergroup', () => { + const result = new RichTextUsergroupBuilder({ usergroupId: 'S1234ABCD' }).build() as any; + expect(result).toBeInstanceOf(SlackDto); + expect(result.type).toBe(RichTextElementType.Usergroup); + }); + + it('should apply styles', () => { + const result = new RichTextUsergroupBuilder({ usergroupId: 'S1234ABCD' }) + .bold() + .italic() + .build() as any; + expect(result.style).toEqual({ bold: true, italic: true }); + }); +}); diff --git a/tests/blocks/context-actions.spec.ts b/tests/blocks/context-actions.spec.ts new file mode 100644 index 00000000..7fcd38a0 --- /dev/null +++ b/tests/blocks/context-actions.spec.ts @@ -0,0 +1,22 @@ +import { ContextActionsBuilder as Class } from '../../src/blocks/context-actions'; +import { SlackBlockDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/context-actions.mock'; +import * as methods from '../methods'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'ContextActionsBuilder'; +const category = 'Blocks'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig = [ + methods.blockId, +]; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/blocks/markdown.spec.ts b/tests/blocks/markdown.spec.ts new file mode 100644 index 00000000..0c398293 --- /dev/null +++ b/tests/blocks/markdown.spec.ts @@ -0,0 +1,22 @@ +import { MarkdownBuilder as Class } from '../../src/blocks/markdown'; +import { SlackBlockDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/markdown.mock'; +import * as methods from '../methods'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'MarkdownBuilder'; +const category = 'Blocks'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig = [ + methods.blockId, +]; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/blocks/mocks/context-actions.mock.ts b/tests/blocks/mocks/context-actions.mock.ts new file mode 100644 index 00000000..7d9409a8 --- /dev/null +++ b/tests/blocks/mocks/context-actions.mock.ts @@ -0,0 +1,7 @@ +import { ContextActionsBuilder } from '../../../src/blocks/context-actions'; + +export const params = { + blockId: 'blockId', +}; + +export const mock = new ContextActionsBuilder(params); diff --git a/tests/blocks/mocks/markdown.mock.ts b/tests/blocks/mocks/markdown.mock.ts new file mode 100644 index 00000000..4ff822df --- /dev/null +++ b/tests/blocks/mocks/markdown.mock.ts @@ -0,0 +1,8 @@ +import { MarkdownBuilder } from '../../../src/blocks/markdown'; + +export const params = { + blockId: 'blockId', + text: '# Hello World', +}; + +export const mock = new MarkdownBuilder(params); diff --git a/tests/blocks/mocks/table.mock.ts b/tests/blocks/mocks/table.mock.ts new file mode 100644 index 00000000..62f56a68 --- /dev/null +++ b/tests/blocks/mocks/table.mock.ts @@ -0,0 +1,7 @@ +import { TableBuilder } from '../../../src/blocks/table'; + +export const params = { + blockId: 'blockId', +}; + +export const mock = new TableBuilder(params); diff --git a/tests/blocks/table.spec.ts b/tests/blocks/table.spec.ts new file mode 100644 index 00000000..c3411d90 --- /dev/null +++ b/tests/blocks/table.spec.ts @@ -0,0 +1,22 @@ +import { TableBuilder as Class } from '../../src/blocks/table'; +import { SlackBlockDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/table.mock'; +import * as methods from '../methods'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'TableBuilder'; +const category = 'Blocks'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig = [ + methods.blockId, +]; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/elements/feedback-buttons.spec.ts b/tests/elements/feedback-buttons.spec.ts new file mode 100644 index 00000000..33718b8f --- /dev/null +++ b/tests/elements/feedback-buttons.spec.ts @@ -0,0 +1,22 @@ +import { FeedbackButtonsBuilder as Class } from '../../src/elements/feedback-buttons'; +import { SlackElementDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/feedback-buttons.mock'; +import * as methods from '../methods'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'FeedbackButtons'; +const category = 'Elements'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig = [ + methods.actionId, +]; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/elements/icon-button.spec.ts b/tests/elements/icon-button.spec.ts new file mode 100644 index 00000000..5787e59e --- /dev/null +++ b/tests/elements/icon-button.spec.ts @@ -0,0 +1,25 @@ +import { IconButtonBuilder as Class } from '../../src/elements/icon-button'; +import { SlackElementDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/icon-button.mock'; +import * as methods from '../methods'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'IconButton'; +const category = 'Elements'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig = [ + methods.actionId, + methods.value, + methods.accessibilityLabel, + methods.text, +]; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/elements/mocks/feedback-buttons.mock.ts b/tests/elements/mocks/feedback-buttons.mock.ts new file mode 100644 index 00000000..9e3baf4d --- /dev/null +++ b/tests/elements/mocks/feedback-buttons.mock.ts @@ -0,0 +1,7 @@ +import { FeedbackButtonsBuilder } from '../../../src/elements/feedback-buttons'; + +export const params = { + actionId: 'actionId', +}; + +export const mock = new FeedbackButtonsBuilder(params); diff --git a/tests/elements/mocks/icon-button.mock.ts b/tests/elements/mocks/icon-button.mock.ts new file mode 100644 index 00000000..de96e8dc --- /dev/null +++ b/tests/elements/mocks/icon-button.mock.ts @@ -0,0 +1,11 @@ +import { IconButtonBuilder } from '../../../src/elements/icon-button'; + +export const params = { + actionId: 'actionId', + icon: 'trash', + text: 'Delete', + value: 'delete-value', + accessibilityLabel: 'Delete item', +}; + +export const mock = new IconButtonBuilder(params); diff --git a/tests/elements/mocks/rich-text-input.mock.ts b/tests/elements/mocks/rich-text-input.mock.ts new file mode 100644 index 00000000..6c480adc --- /dev/null +++ b/tests/elements/mocks/rich-text-input.mock.ts @@ -0,0 +1,8 @@ +import { RichTextInputBuilder } from '../../../src/elements/rich-text-input'; + +export const params = { + actionId: 'actionId', + placeholder: 'Enter rich text...', +}; + +export const mock = new RichTextInputBuilder(params); diff --git a/tests/elements/mocks/workflow-button.mock.ts b/tests/elements/mocks/workflow-button.mock.ts new file mode 100644 index 00000000..2be59edc --- /dev/null +++ b/tests/elements/mocks/workflow-button.mock.ts @@ -0,0 +1,8 @@ +import { WorkflowButtonBuilder } from '../../../src/elements/workflow-button'; + +export const params = { + accessibilityLabel: 'Run workflow button', + text: 'Run Workflow', +}; + +export const mock = new WorkflowButtonBuilder(params); diff --git a/tests/elements/rich-text-input.spec.ts b/tests/elements/rich-text-input.spec.ts new file mode 100644 index 00000000..4d0b11b0 --- /dev/null +++ b/tests/elements/rich-text-input.spec.ts @@ -0,0 +1,24 @@ +import { RichTextInputBuilder as Class } from '../../src/elements/rich-text-input'; +import { SlackElementDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/rich-text-input.mock'; +import * as methods from '../methods'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'RichTextInput'; +const category = 'Elements'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig = [ + methods.actionId, + methods.placeholder, + methods.focusOnLoad, +]; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/elements/workflow-button.spec.ts b/tests/elements/workflow-button.spec.ts new file mode 100644 index 00000000..33b51552 --- /dev/null +++ b/tests/elements/workflow-button.spec.ts @@ -0,0 +1,23 @@ +import { WorkflowButtonBuilder as Class } from '../../src/elements/workflow-button'; +import { SlackElementDto as DtoClass } from '../../src/internal'; +import { params } from './mocks/workflow-button.mock'; +import * as methods from '../methods'; +import { testCompositeBuilderClass } from '../test-composite-builder-class'; + +const className = 'WorkflowButton'; +const category = 'Elements'; + +const config = { + Class, + DtoClass, + params, + className, + category, +}; + +const methodsConfig = [ + methods.accessibilityLabel, + methods.text, +]; + +testCompositeBuilderClass({ config, methods: methodsConfig }); diff --git a/tests/surfaces/surface.spec.ts b/tests/surfaces/surface.spec.ts index 184ef22c..7b72c3bf 100644 --- a/tests/surfaces/surface.spec.ts +++ b/tests/surfaces/surface.spec.ts @@ -91,7 +91,7 @@ describe('Surfaces', () => { ]); const attachments = message.getAttachments(); - expect(attachments).toEqual(expect.arrayContaining(message.build().attachments)); + expect(attachments).toEqual(expect.arrayContaining(message.build().attachments!)); }); test('Calling \'getBlocks()\' for Modal should return an array of Blocks.', () => {