https://github.com/roziscoding/slack-rich-text
https://github.com/roziscoding/slack-rich-text
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/roziscoding/slack-rich-text
- Owner: roziscoding
- License: mit
- Created: 2024-02-17T01:07:17.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-25T18:39:00.000Z (over 1 year ago)
- Last Synced: 2025-02-27T02:55:48.123Z (about 1 year ago)
- Language: TypeScript
- Size: 106 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slack Rich Text
Small library to create slack messages with rich text using the BlockKit.
## Installing
`npm i slack-rich-text`
## Usage
Use the exported function as a template string tag to create a rich text message.
To apply the transformation to a string inside some other function, like using `bold` on a list, use the `section` function.
Example:
```javascript
import { bullets, emoji, ordered, richText, section } from "slack_rich_text";
const blocks = richText`
This is a test message for slack-rich-text.
It supports:
${bullets([
"Bullet lists",
"Yaay!",
ordered([
"Also",
"Ordered",
"Lists",
bullets([
"And",
"Nested",
"Lists",
section`${emoji("smile")} ${emoji("smile")} ${emoji("smile")}`
])
])
])}
`;
```
Renders as:

## Passing strings to `richText`
The `richText` function does not support receiving a string as a value. That means that the following code will not work:
```javascript
const name = "John";
const blocks = richText`
Hello, ${name}!
`; // This will throw an error
```
To fix this, use the `section` function to transform the string into a block:
```javascript
const name = "John";
const blocks = richText`
${section`Hello, ${name}!`}
`;
```
## API Reference
See the [API Reference](./API.md) for a detailed explanation of the available functions.