Skip to content

Commit

Permalink
Add ID function to the Block interface
Browse files Browse the repository at this point in the history
  • Loading branch information
samstarling authored and nlopes committed Feb 1, 2025
1 parent 76e627a commit 1992e48
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
// to ensure consistency between blocks.
type Block interface {
BlockType() MessageBlockType
ID() string
}

// Blocks is a convenience struct defined to allow dynamic unmarshalling of
Expand Down
5 changes: 5 additions & 0 deletions block_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func (s ActionBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s ActionBlock) ID() string {
return s.BlockID
}

// NewActionBlock returns a new instance of an Action Block
func NewActionBlock(blockID string, elements ...BlockElement) *ActionBlock {
return &ActionBlock{
Expand Down
7 changes: 6 additions & 1 deletion block_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ func (s CallBlock) BlockType() MessageBlockType {
return s.Type
}

// NewFileBlock returns a new instance of a file block
// ID returns the ID of the block
func (s CallBlock) ID() string {
return s.BlockID
}

// NewCallBlock returns a new instance of a call block
func NewCallBlock(callID string) *CallBlock {
return &CallBlock{
Type: MBTCall,
Expand Down
5 changes: 5 additions & 0 deletions block_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func (s ContextBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s ContextBlock) ID() string {
return s.BlockID
}

type ContextElements struct {
Elements []MixedElement
}
Expand Down
6 changes: 5 additions & 1 deletion block_divider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ func (s DividerBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s DividerBlock) ID() string {
return s.BlockID
}

// NewDividerBlock returns a new instance of a divider block
func NewDividerBlock() *DividerBlock {
return &DividerBlock{
Type: MBTDivider,
}

}
5 changes: 5 additions & 0 deletions block_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func (s FileBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s FileBlock) ID() string {
return s.BlockID
}

// NewFileBlock returns a new instance of a file block
func NewFileBlock(blockID string, externalID string, source string) *FileBlock {
return &FileBlock{
Expand Down
5 changes: 5 additions & 0 deletions block_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func (s HeaderBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s HeaderBlock) ID() string {
return s.BlockID
}

// HeaderBlockOption allows configuration of options for a new header block
type HeaderBlockOption func(*HeaderBlock)

Expand Down
5 changes: 5 additions & 0 deletions block_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type ImageBlock struct {
SlackFile *SlackFileObject `json:"slack_file,omitempty"`
}

// ID returns the ID of the block
func (s ImageBlock) ID() string {
return s.BlockID
}

// SlackFileObject Defines an object containing Slack file information to be used in an
// image block or image element.
//
Expand Down
5 changes: 5 additions & 0 deletions block_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func (s InputBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s InputBlock) ID() string {
return s.BlockID
}

// NewInputBlock returns a new instance of an input block
func NewInputBlock(blockID string, label, hint *TextBlockObject, element BlockElement) *InputBlock {
return &InputBlock{
Expand Down
5 changes: 5 additions & 0 deletions block_rich_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func (b RichTextBlock) BlockType() MessageBlockType {
return b.Type
}

// ID returns the ID of the block
func (s RichTextBlock) ID() string {
return s.BlockID
}

func (e *RichTextBlock) UnmarshalJSON(b []byte) error {
var raw struct {
Type MessageBlockType `json:"type"`
Expand Down
5 changes: 5 additions & 0 deletions block_section.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ func (s SectionBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s SectionBlock) ID() string {
return s.BlockID
}

// SectionBlockOption allows configuration of options for a new section block
type SectionBlockOption func(*SectionBlock)

Expand Down
5 changes: 5 additions & 0 deletions block_unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ type UnknownBlock struct {
func (b UnknownBlock) BlockType() MessageBlockType {
return b.Type
}

// ID returns the ID of the block
func (s UnknownBlock) ID() string {
return s.BlockID
}
5 changes: 5 additions & 0 deletions block_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func (s VideoBlock) BlockType() MessageBlockType {
return s.Type
}

// ID returns the ID of the block
func (s VideoBlock) ID() string {
return s.BlockID
}

// NewVideoBlock returns an instance of a new Video Block type
func NewVideoBlock(videoURL, thumbnailURL, altText, blockID string, title *TextBlockObject) *VideoBlock {
return &VideoBlock{
Expand Down

0 comments on commit 1992e48

Please sign in to comment.