Repository: slack-go/slack
Pull request #1210 (2023-07-08 15:07:59)

Add Video Block
Add the support for Video Block.

Ref. https://api.slack.com/reference/block-kit/blocks#video

cf. https://github.com/slack-go/slack/discussions/1205

parsley42: Close/re-open to run checks.
parsley42: @ben-bourdin451 This project is currently looking for maintainers; I've been filling in on occasion as I have time, but I probably write 10 lines of Go/month so I'm not the best candidate - I just try to find/recruit maintainers. Are you interested in helping out? Seems like a manageable level of effort.
ben-bourdin451: > @ben-bourdin451 This project is currently looking for maintainers; I've been filling in on occasion as I have time, but I probably write 10 lines of Go/month so I'm not the best candidate - I just try to find/recruit maintainers. Are you interested in helping out? Seems like a manageable level of effort.

sure, happy to help where ever I can. I don't have a huge amount of spare time but I can definitely help out on triage or reviews here and there
parsley42: @ben-bourdin451 Ok, I've sent you an invite. Do you mind having a look at why the tests are failing?

Patch:
diff --git a/block.go b/block.go
index 18222bd..c28377a 100644
--- a/block.go
+++ b/block.go
@@ -18,6 +18,7 @@ const (
 	MBTInput    MessageBlockType = "input"
 	MBTHeader   MessageBlockType = "header"
 	MBTRichText MessageBlockType = "rich_text"
+	MBTVideo    MessageBlockType = "video"
 )
 
 // Block defines an interface all block types should implement
diff --git a/block_conv.go b/block_conv.go
index 4ab58de..d017c66 100644
--- a/block_conv.go
+++ b/block_conv.go
@@ -68,6 +68,8 @@ func (b *Blocks) UnmarshalJSON(data []byte) error {
 			block = &RichTextBlock{}
 		case "section":
 			block = &SectionBlock{}
+		case "video":
+			block = &VideoBlock{}
 		default:
 			block = &UnknownBlock{}
 		}
diff --git a/block_video.go b/block_video.go
new file mode 100644
index 0000000..322c614
--- /dev/null
+++ b/block_video.go
@@ -0,0 +1,65 @@
+package slack
+
+// VideoBlock defines data required to display a video as a block element
+//
+// More Information: https://api.slack.com/reference/block-kit/blocks#video
+type VideoBlock struct {
+	Type            MessageBlockType `json:"type"`
+	VideoURL        string           `json:"video_url"`
+	ThumbnailURL    string           `json:"thumbnail_url"`
+	AltText         string           `json:"alt_text"`
+	Title           *TextBlockObject `json:"title"`
+	BlockID         string           `json:"block_id,omitempty"`
+	TitleURL        string           `json:"title_url,omitempty"`
+	AuthorName      string           `json:"author_name,omitempty"`
+	ProviderName    string           `json:"provider_name,omitempty"`
+	ProviderIconURL string           `json:"provider_icon_url,omitempty"`
+	Description     *TextBlockObject `json:"description,omitempty"`
+}
+
+// BlockType returns the type of the block
+func (s VideoBlock) BlockType() MessageBlockType {
+	return s.Type
+}
+
+// NewVideoBlock returns an instance of a new Video Block type
+func NewVideoBlock(videoURL, thumbnailURL, altText, blockID string, title *TextBlockObject) *VideoBlock {
+	return &VideoBlock{
+		Type:         MBTVideo,
+		VideoURL:     videoURL,
+		ThumbnailURL: thumbnailURL,
+		AltText:      altText,
+		BlockID:      blockID,
+		Title:        title,
+	}
+}
+
+// WithAuthorName sets the author name for the VideoBlock
+func (s *VideoBlock) WithAuthorName(authorName string) *VideoBlock {
+	s.AuthorName = authorName
+	return s
+}
+
+// WithTitleURL sets the title URL for the VideoBlock
+func (s *VideoBlock) WithTitleURL(titleURL string) *VideoBlock {
+	s.TitleURL = titleURL
+	return s
+}
+
+// WithDescription sets the description for the VideoBlock
+func (s *VideoBlock) WithDescription(description *TextBlockObject) *VideoBlock {
+	s.Description = description
+	return s
+}
+
+// WithProviderIconURL sets the provider icon URL for the VideoBlock
+func (s *VideoBlock) WithProviderIconURL(providerIconURL string) *VideoBlock {
+	s.ProviderIconURL = providerIconURL
+	return s
+}
+
+// WithProviderName sets the provider name for the VideoBlock
+func (s *VideoBlock) WithProviderName(providerName string) *VideoBlock {
+	s.ProviderName = providerName
+	return s
+}


Test patch:
diff --git a/block_video_test.go b/block_video_test.go
new file mode 100644
index 0000000..d4b791f
--- /dev/null
+++ b/block_video_test.go
@@ -0,0 +1,23 @@
+package slack
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestNewVideoBlock(t *testing.T) {
+
+	videoTitle := NewTextBlockObject("plain_text", "VideoTitle", false, false)
+	videoBlock := NewVideoBlock(
+		"https://example.com/example.mp4",
+		"https://example.com/thumbnail.png",
+		"alternative text", "blockID", videoTitle)
+
+	assert.Equal(t, string(videoBlock.Type), "video")
+	assert.Equal(t, videoBlock.Title.Type, "plain_text")
+	assert.Equal(t, videoBlock.BlockID, "blockID")
+	assert.Contains(t, videoBlock.Title.Text, "VideoTitle")
+	assert.Contains(t, videoBlock.VideoURL, "example.mp4")
+
+}