Skip to content

Commit

Permalink
Merge branch 'master' into invite-shared
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoaiello authored Oct 14, 2024
2 parents 1181e47 + 21e61c5 commit aa7ebb8
Show file tree
Hide file tree
Showing 12 changed files with 877 additions and 0 deletions.
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"
MBTCall MessageBlockType = "call"
MBTVideo MessageBlockType = "video"
)

Expand Down
23 changes: 23 additions & 0 deletions block_call.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package slack

// CallBlock defines data that is used to display a call in slack.
//
// More Information: https://api.slack.com/apis/calls#post_to_channel
type CallBlock struct {
Type MessageBlockType `json:"type"`
BlockID string `json:"block_id,omitempty"`
CallID string `json:"call_id"`
}

// BlockType returns the type of the block
func (s CallBlock) BlockType() MessageBlockType {
return s.Type
}

// NewFileBlock returns a new instance of a file block
func NewCallBlock(callID string) *CallBlock {
return &CallBlock{
Type: MBTCall,
CallID: callID,
}
}
13 changes: 13 additions & 0 deletions block_call_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package slack

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewCallBlock(t *testing.T) {
callBlock := NewCallBlock("ACallID")
assert.Equal(t, string(callBlock.Type), "call")
assert.Equal(t, callBlock.CallID, "ACallID")
}
2 changes: 2 additions & 0 deletions block_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (b *Blocks) UnmarshalJSON(data []byte) error {
block = &RichTextBlock{}
case "section":
block = &SectionBlock{}
case "call":
block = &CallBlock{}
case "video":
block = &VideoBlock{}
default:
Expand Down
132 changes: 132 additions & 0 deletions block_element.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,36 @@ func NewOptionsSelectBlockElement(optType string, placeholder *TextBlockObject,
}
}

// WithInitialOption sets the initial option for the select element
func (s *SelectBlockElement) WithInitialOption(option *OptionBlockObject) *SelectBlockElement {
s.InitialOption = option
return s
}

// WithInitialUser sets the initial user for the select element
func (s *SelectBlockElement) WithInitialUser(user string) *SelectBlockElement {
s.InitialUser = user
return s
}

// WithInitialConversation sets the initial conversation for the select element
func (s *SelectBlockElement) WithInitialConversation(conversation string) *SelectBlockElement {
s.InitialConversation = conversation
return s
}

// WithInitialChannel sets the initial channel for the select element
func (s *SelectBlockElement) WithInitialChannel(channel string) *SelectBlockElement {
s.InitialChannel = channel
return s
}

// WithConfirm adds a confirmation dialogue to the select element
func (s *SelectBlockElement) WithConfirm(confirm *ConfirmationBlockObject) *SelectBlockElement {
s.Confirm = confirm
return s
}

// NewOptionsGroupSelectBlockElement returns a new instance of SelectBlockElement for use with
// the Options object only.
func NewOptionsGroupSelectBlockElement(
Expand Down Expand Up @@ -309,6 +339,48 @@ func NewOptionsMultiSelectBlockElement(optType string, placeholder *TextBlockObj
}
}

// WithInitialOptions sets the initial options for the multi-select element
func (s *MultiSelectBlockElement) WithInitialOptions(options ...*OptionBlockObject) *MultiSelectBlockElement {
s.InitialOptions = options
return s
}

// WithInitialUsers sets the initial users for the multi-select element
func (s *MultiSelectBlockElement) WithInitialUsers(users ...string) *MultiSelectBlockElement {
s.InitialUsers = users
return s
}

// WithInitialConversations sets the initial conversations for the multi-select element
func (s *MultiSelectBlockElement) WithInitialConversations(conversations ...string) *MultiSelectBlockElement {
s.InitialConversations = conversations
return s
}

// WithInitialChannels sets the initial channels for the multi-select element
func (s *MultiSelectBlockElement) WithInitialChannels(channels ...string) *MultiSelectBlockElement {
s.InitialChannels = channels
return s
}

// WithConfirm adds a confirmation dialogue to the multi-select element
func (s *MultiSelectBlockElement) WithConfirm(confirm *ConfirmationBlockObject) *MultiSelectBlockElement {
s.Confirm = confirm
return s
}

// WithMaxSelectedItems sets the maximum number of items that can be selected
func (s *MultiSelectBlockElement) WithMaxSelectedItems(maxSelectedItems int) *MultiSelectBlockElement {
s.MaxSelectedItems = &maxSelectedItems
return s
}

// WithMinQueryLength sets the minimum query length for the multi-select element
func (s *MultiSelectBlockElement) WithMinQueryLength(minQueryLength int) *MultiSelectBlockElement {
s.MinQueryLength = &minQueryLength
return s
}

// NewOptionsGroupMultiSelectBlockElement returns a new instance of MultiSelectBlockElement for use with
// the Options object only.
func NewOptionsGroupMultiSelectBlockElement(
Expand Down Expand Up @@ -352,6 +424,12 @@ func NewOverflowBlockElement(actionID string, options ...*OptionBlockObject) *Ov
}
}

// WithConfirm adds a confirmation dialogue to the overflow element
func (s *OverflowBlockElement) WithConfirm(confirm *ConfirmationBlockObject) *OverflowBlockElement {
s.Confirm = confirm
return s
}

// DatePickerBlockElement defines an element which lets users easily select a
// date from a calendar style UI. Date picker elements can be used inside of
// section and actions blocks.
Expand Down Expand Up @@ -520,6 +598,36 @@ func NewPlainTextInputBlockElement(placeholder *TextBlockObject, actionID string
}
}

// WithInitialValue sets the initial value for the plain-text input element
func (s *PlainTextInputBlockElement) WithInitialValue(initialValue string) *PlainTextInputBlockElement {
s.InitialValue = initialValue
return s
}

// WithMinLength sets the minimum length for the plain-text input element
func (s *PlainTextInputBlockElement) WithMinLength(minLength int) *PlainTextInputBlockElement {
s.MinLength = minLength
return s
}

// WithMaxLength sets the maximum length for the plain-text input element
func (s *PlainTextInputBlockElement) WithMaxLength(maxLength int) *PlainTextInputBlockElement {
s.MaxLength = maxLength
return s
}

// WithMultiline sets the multiline property for the plain-text input element
func (s *PlainTextInputBlockElement) WithMultiline(multiline bool) *PlainTextInputBlockElement {
s.Multiline = multiline
return s
}

// WithDispatchActionConfig sets the dispatch action config for the plain-text input element
func (s *PlainTextInputBlockElement) WithDispatchActionConfig(config *DispatchActionConfig) *PlainTextInputBlockElement {
s.DispatchActionConfig = config
return s
}

// RichTextInputBlockElement creates a field where allows users to enter formatted text
// in a WYSIWYG composer, offering the same messaging writing experience as in Slack
// More Information: https://api.slack.com/reference/block-kit/block-elements#rich_text_input
Expand Down Expand Up @@ -629,6 +737,30 @@ func NewNumberInputBlockElement(placeholder *TextBlockObject, actionID string, i
}
}

// WithInitialValue sets the initial value for the number input element
func (s *NumberInputBlockElement) WithInitialValue(initialValue string) *NumberInputBlockElement {
s.InitialValue = initialValue
return s
}

// WithMinValue sets the minimum value for the number input element
func (s *NumberInputBlockElement) WithMinValue(minValue string) *NumberInputBlockElement {
s.MinValue = minValue
return s
}

// WithMaxValue sets the maximum value for the number input element
func (s *NumberInputBlockElement) WithMaxValue(maxValue string) *NumberInputBlockElement {
s.MaxValue = maxValue
return s
}

// WithDispatchActionConfig sets the dispatch action config for the number input element
func (s *NumberInputBlockElement) WithDispatchActionConfig(config *DispatchActionConfig) *NumberInputBlockElement {
s.DispatchActionConfig = config
return s
}

// FileInputBlockElement creates a field where a user can upload a file.
//
// File input elements are currently only available in modals.
Expand Down
12 changes: 12 additions & 0 deletions block_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ func NewInputBlock(blockID string, label, hint *TextBlockObject, element BlockEl
Hint: hint,
}
}

// WithOptional sets the optional flag on the input block
func (s *InputBlock) WithOptional(optional bool) *InputBlock {
s.Optional = optional
return s
}

// WithDispatchAction sets the dispatch action flag on the input block
func (s *InputBlock) WithDispatchAction(dispatchAction bool) *InputBlock {
s.DispatchAction = dispatchAction
return s
}
Loading

0 comments on commit aa7ebb8

Please sign in to comment.