Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Video Block #1210

Merged
merged 3 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions block_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (b *Blocks) UnmarshalJSON(data []byte) error {
block = &RichTextBlock{}
case "section":
block = &SectionBlock{}
case "video":
block = &VideoBlock{}
default:
block = &UnknownBlock{}
}
Expand Down
65 changes: 65 additions & 0 deletions block_video.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
parsley42 marked this conversation as resolved.
Show resolved Hide resolved

// 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 *slack.TextBlockObject) *VideoBlock {

Check failure on line 50 in block_video.go

View workflow job for this annotation

GitHub Actions / test go-1.18

undefined: slack

Check failure on line 50 in block_video.go

View workflow job for this annotation

GitHub Actions / test go-1.19

undefined: slack

Check failure on line 50 in block_video.go

View workflow job for this annotation

GitHub Actions / test go-1.20

undefined: slack
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
}
23 changes: 23 additions & 0 deletions block_video_test.go
Original file line number Diff line number Diff line change
@@ -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")

}