Skip to content

Commit

Permalink
Merge pull request #5 from rusq/edge-merge
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
rusq authored Nov 4, 2024
2 parents 41c992b + ac9b384 commit d9b6e02
Show file tree
Hide file tree
Showing 45 changed files with 3,506 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84 # v8.0.0
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e # v9.0.0
with:
any-of-labels: 'feedback given'
days-before-stale: 45
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
- '1.20'
- '1.21'
- '1.22'
- '1.23'
name: test go-${{ matrix.go }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: run test
Expand All @@ -31,14 +32,14 @@ jobs:
runs-on: ubuntu-22.04
name: lint
steps:
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20'
cache: false
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: golangci-lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
version: v1.52.2
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
134 changes: 133 additions & 1 deletion 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,14 +598,44 @@ 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
type RichTextInputBlockElement struct {
Type MessageElementType `json:"type"`
ActionID string `json:"action_id,omitempty"`
Placeholder *TextBlockObject `json:"placeholder,omitempty"`
InitialValue string `json:"initial_value,omitempty"`
InitialValue *RichTextBlock `json:"initial_value,omitempty"`
DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"`
FocusOnLoad bool `json:"focus_on_load,omitempty"`
}
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
20 changes: 15 additions & 5 deletions block_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ package slack
//
// More Information: https://api.slack.com/reference/messaging/blocks#image
type ImageBlock struct {
Type MessageBlockType `json:"type"`
ImageURL string `json:"image_url"`
AltText string `json:"alt_text"`
BlockID string `json:"block_id,omitempty"`
Title *TextBlockObject `json:"title,omitempty"`
Type MessageBlockType `json:"type"`
ImageURL string `json:"image_url,omitempty"`
AltText string `json:"alt_text"`
BlockID string `json:"block_id,omitempty"`
Title *TextBlockObject `json:"title,omitempty"`
SlackFile *SlackFileObject `json:"slack_file,omitempty"`
}

// SlackFileObject Defines an object containing Slack file information to be used in an
// image block or image element.
//
// More Information: https://api.slack.com/reference/block-kit/composition-objects#slack_file
type SlackFileObject struct {
ID string `json:"id,omitempty"`
URL string `json:"url,omitempty"`
}

// BlockType returns the type of the block
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
}
9 changes: 8 additions & 1 deletion block_rich_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ type RichTextSectionEmojiElement struct {
Type RichTextSectionElementType `json:"type"`
Name string `json:"name"`
SkinTone int `json:"skin_tone"`
Unicode string `json:"unicode,omitempty"`
Style *RichTextSectionTextStyle `json:"style,omitempty"`
}

Expand Down Expand Up @@ -414,16 +415,22 @@ func NewRichTextSectionUserGroupElement(usergroupID string) *RichTextSectionUser
type RichTextSectionDateElement struct {
Type RichTextSectionElementType `json:"type"`
Timestamp JSONTime `json:"timestamp"`
Format string `json:"format"`
URL *string `json:"url,omitempty"`
Fallback *string `json:"fallback,omitempty"`
}

func (r RichTextSectionDateElement) RichTextSectionElementType() RichTextSectionElementType {
return r.Type
}

func NewRichTextSectionDateElement(timestamp int64) *RichTextSectionDateElement {
func NewRichTextSectionDateElement(timestamp int64, format string, url *string, fallback *string) *RichTextSectionDateElement {
return &RichTextSectionDateElement{
Type: RTSEDate,
Timestamp: JSONTime(timestamp),
Format: format,
URL: url,
Fallback: fallback,
}
}

Expand Down
17 changes: 15 additions & 2 deletions block_rich_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ func TestRichTextSection_UnmarshalJSON(t *testing.T) {
err error
}{
{
[]byte(`{"elements":[{"type":"unknown","value":10},{"type":"text","text":"hi"},{"type":"date","timestamp":1636961629}]}`),
[]byte(`{"elements":[{"type":"unknown","value":10},{"type":"text","text":"hi"},{"type":"date","timestamp":1636961629,"format":"{date_short_pretty}"},{"type":"date","timestamp":1636961629,"format":"{date_short_pretty}","url":"https://example.com","fallback":"default"}]}`),
RichTextSection{
Type: RTESection,
Elements: []RichTextSectionElement{
&RichTextSectionUnknownElement{Type: RTSEUnknown, Raw: `{"type":"unknown","value":10}`},
&RichTextSectionTextElement{Type: RTSEText, Text: "hi"},
&RichTextSectionDateElement{Type: RTSEDate, Timestamp: JSONTime(1636961629)},
&RichTextSectionDateElement{Type: RTSEDate, Timestamp: JSONTime(1636961629), Format: "{date_short_pretty}"},
&RichTextSectionDateElement{Type: RTSEDate, Timestamp: JSONTime(1636961629), Format: "{date_short_pretty}", URL: strp("https://example.com"), Fallback: strp("default")},
},
},
nil,
Expand All @@ -186,6 +187,16 @@ func TestRichTextSection_UnmarshalJSON(t *testing.T) {
},
nil,
},
{
[]byte(`{"type": "rich_text_section","elements":[{"type": "emoji","name": "+1","unicode": "1f44d-1f3fb","skin_tone": 2}]}`),
RichTextSection{
Type: RTESection,
Elements: []RichTextSectionElement{
&RichTextSectionEmojiElement{Type: RTSEEmoji, Name: "+1", Unicode: "1f44d-1f3fb", SkinTone: 2},
},
},
nil,
},
}
for _, tc := range cases {
var actual RichTextSection
Expand Down Expand Up @@ -361,3 +372,5 @@ func TestRichTextQuote_Marshal(t *testing.T) {
}
})
}

func strp(in string) *string { return &in }
Loading

0 comments on commit d9b6e02

Please sign in to comment.