-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There's a new block for markdown per changelog entry at https://api.slack.com/changelog#entry-february_2025_0. More information can be found in https://api.slack.com/reference/block-kit/blocks#markdown.
- Loading branch information
Showing
3 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package slack | ||
|
||
// MarkdownBlock defines a block that lets you use markdown to format your text. | ||
// | ||
// This block can be used with AI apps when you expect a markdown response from an LLM | ||
// that can get lost in translation rendering in Slack. Providing it in a markdown block | ||
// leaves the translating to Slack to ensure your message appears as intended. Note that | ||
// passing a single block may result in multiple blocks after translation. | ||
// | ||
// More Information: https://api.slack.com/reference/block-kit/blocks#markdown | ||
type MarkdownBlock struct { | ||
Type MessageBlockType `json:"type"` | ||
BlockID string `json:"block_id,omitempty"` | ||
Text string `json:"text"` | ||
} | ||
|
||
// BlockType returns the type of the block | ||
func (s MarkdownBlock) BlockType() MessageBlockType { | ||
return s.Type | ||
} | ||
|
||
// ID returns the ID of the block | ||
func (s MarkdownBlock) ID() string { | ||
return s.BlockID | ||
} | ||
|
||
// NewMarkdownBlock returns an instance of a new Markdown Block type | ||
func NewMarkdownBlock(blockID, text string) *MarkdownBlock { | ||
return &MarkdownBlock{ | ||
Type: MBTMarkdown, | ||
BlockID: blockID, | ||
Text: text, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package slack | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewMarkdownBlock(t *testing.T) { | ||
markdownBlock := NewMarkdownBlock("test", "*asfd*") | ||
|
||
assert.Equal(t, markdownBlock.BlockType(), MBTMarkdown) | ||
assert.Equal(t, string(markdownBlock.Type), "markdown") | ||
assert.Equal(t, markdownBlock.ID(), "test") | ||
assert.Equal(t, markdownBlock.BlockID, "test") | ||
assert.Equal(t, markdownBlock.Text, "*asfd*") | ||
} |