Skip to content

Commit

Permalink
Merge branch 'master' into email_url_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
ameliagapin authored Dec 9, 2022
2 parents 6958897 + 501365f commit 7a65b11
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 10 deletions.
4 changes: 4 additions & 0 deletions block_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error {
e = &OverflowBlockElement{}
case "radio_buttons":
e = &RadioButtonsBlockElement{}
case "number_input":
e = &NumberInputBlockElement{}
default:
return errors.New("unsupported block element type")
}
Expand Down Expand Up @@ -200,6 +202,8 @@ func (b *BlockElements) UnmarshalJSON(data []byte) error {
blockElement = &RadioButtonsBlockElement{}
case "static_select", "external_select", "users_select", "conversations_select", "channels_select":
blockElement = &SelectBlockElement{}
case "number_input":
blockElement = &NumberInputBlockElement{}
default:
return fmt.Errorf("unsupported block element type %v", blockElementType)
}
Expand Down
32 changes: 32 additions & 0 deletions block_element.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
METRadioButtons MessageElementType = "radio_buttons"
METEmailTextInput MessageElementType = "email_text_input"
METURLTextInput MessageElementType = "url_text_input"
METNumber MessageElementType = "number_input"

MixedElementImage MixedElementType = "mixed_image"
MixedElementText MixedElementType = "mixed_text"
Expand Down Expand Up @@ -535,3 +536,34 @@ func NewRadioButtonsBlockElement(actionID string, options ...*OptionBlockObject)
Options: options,
}
}

// NumberInputBlockElement creates a field where a user can enter number
// data.
// Number input elements are currently only available in modals.
//
// More Information: https://api.slack.com/reference/block-kit/block-elements#number
type NumberInputBlockElement struct {
Type MessageElementType `json:"type"`
IsDecimalAllowed bool `json:"is_decimal_allowed"`
ActionID string `json:"action_id,omitempty"`
Placeholder *TextBlockObject `json:"placeholder,omitempty"`
InitialValue string `json:"initial_value,omitempty"`
MinValue string `json:"min_value,omitempty"`
MaxValue string `json:"max_value,omitempty"`
DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"`
}

// ElementType returns the type of the Element
func (s NumberInputBlockElement) ElementType() MessageElementType {
return s.Type
}

// NewNumberInputBlockElement returns an instance of a number input element
func NewNumberInputBlockElement(placeholder *TextBlockObject, actionID string, isDecimalAllowed bool) *NumberInputBlockElement {
return &NumberInputBlockElement{
Type: METNumber,
ActionID: actionID,
Placeholder: placeholder,
IsDecimalAllowed: isDecimalAllowed,
}
}
10 changes: 10 additions & 0 deletions block_element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,13 @@ func TestNewRadioButtonsBlockElement(t *testing.T) {
assert.Equal(t, len(radioButtonsElement.Options), 3)

}

func TestNewNumberInputBlockElement(t *testing.T) {

numberInputElement := NewNumberInputBlockElement(nil, "test", true)

assert.Equal(t, string(numberInputElement.Type), "number_input")
assert.Equal(t, numberInputElement.ActionID, "test")
assert.Equal(t, numberInputElement.IsDecimalAllowed, true)

}
25 changes: 18 additions & 7 deletions conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type GetConversationsForUserParameters struct {
Types []string
Limit int
ExcludeArchived bool
TeamID string
}

type responseMetaData struct {
Expand Down Expand Up @@ -137,6 +138,10 @@ func (api *Client) GetConversationsForUserContext(ctx context.Context, params *G
if params.ExcludeArchived {
values.Add("exclude_archived", "true")
}
if params.TeamID != "" {
values.Add("team_id", params.TeamID)
}

response := struct {
Channels []Channel `json:"channels"`
ResponseMetaData responseMetaData `json:"response_metadata"`
Expand Down Expand Up @@ -398,13 +403,14 @@ func (api *Client) LeaveConversationContext(ctx context.Context, channelID strin
}

type GetConversationRepliesParameters struct {
ChannelID string
Timestamp string
Cursor string
Inclusive bool
Latest string
Limit int
Oldest string
ChannelID string
Timestamp string
Cursor string
Inclusive bool
Latest string
Limit int
Oldest string
IncludeAllMetadata bool
}

// GetConversationReplies retrieves a thread of messages posted to a conversation
Expand Down Expand Up @@ -436,6 +442,11 @@ func (api *Client) GetConversationRepliesContext(ctx context.Context, params *Ge
} else {
values.Add("inclusive", "0")
}
if params.IncludeAllMetadata {
values.Add("include_all_metadata", "1")
} else {
values.Add("include_all_metadata", "0")
}
response := struct {
SlackResponse
HasMore bool `json:"has_more"`
Expand Down
16 changes: 16 additions & 0 deletions team.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ func (api *Client) GetTeamInfo() (*TeamInfo, error) {
return api.GetTeamInfoContext(context.Background())
}

// GetOtherTeamInfo gets Team information for any team
func (api *Client) GetOtherTeamInfo(team string) (*TeamInfo, error) {
if team == "" {
return api.GetTeamInfo()
}
values := url.Values{
"token": {api.token},
}
values.Add("team", team)
response, err := api.teamRequest(context.Background(), "team.info", values)
if err != nil {
return nil, err
}
return &response.Team, nil
}

// GetTeamInfoContext gets the Team Information of the user with a custom context
func (api *Client) GetTeamInfoContext(ctx context.Context) (*TeamInfo, error) {
values := url.Values{
Expand Down
6 changes: 3 additions & 3 deletions workflow_step_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ type (
}
)

type WorkflowStepCompletedRequestOption func(opt WorkflowStepCompletedRequest) error
type WorkflowStepCompletedRequestOption func(opt *WorkflowStepCompletedRequest) error

func WorkflowStepCompletedRequestOptionOutput(outputs map[string]string) WorkflowStepCompletedRequestOption {
return func(opt WorkflowStepCompletedRequest) error {
return func(opt *WorkflowStepCompletedRequest) error {
if len(outputs) > 0 {
opt.Outputs = outputs
}
Expand All @@ -33,7 +33,7 @@ func WorkflowStepCompletedRequestOptionOutput(outputs map[string]string) Workflo
// WorkflowStepCompleted indicates step is completed
func (api *Client) WorkflowStepCompleted(workflowStepExecuteID string, options ...WorkflowStepCompletedRequestOption) error {
// More information: https://api.slack.com/methods/workflows.stepCompleted
r := WorkflowStepCompletedRequest{
r := &WorkflowStepCompletedRequest{
WorkflowStepExecuteID: workflowStepExecuteID,
}
for _, option := range options {
Expand Down

0 comments on commit 7a65b11

Please sign in to comment.