diff --git a/block_conv.go b/block_conv.go index 76d7eebcd..555e48117 100644 --- a/block_conv.go +++ b/block_conv.go @@ -112,6 +112,10 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error { e = &TimePickerBlockElement{} case "plain_text_input": e = &PlainTextInputBlockElement{} + case "email_text_input": + e = &EmailTextInputBlockElement{} + case "url_text_input": + e = &URLTextInputBlockElement{} case "static_select", "external_select", "users_select", "conversations_select", "channels_select": e = &SelectBlockElement{} case "multi_static_select", "multi_external_select", "multi_users_select", "multi_conversations_select", "multi_channels_select": @@ -188,6 +192,10 @@ func (b *BlockElements) UnmarshalJSON(data []byte) error { blockElement = &TimePickerBlockElement{} case "plain_text_input": blockElement = &PlainTextInputBlockElement{} + case "email_text_input": + blockElement = &EmailTextInputBlockElement{} + case "url_text_input": + blockElement = &URLTextInputBlockElement{} case "checkboxes": blockElement = &CheckboxGroupsBlockElement{} case "radio_buttons": diff --git a/block_element.go b/block_element.go index 71086740d..aba29c6ba 100644 --- a/block_element.go +++ b/block_element.go @@ -11,6 +11,8 @@ const ( METTimepicker MessageElementType = "timepicker" METPlainTextInput MessageElementType = "plain_text_input" METRadioButtons MessageElementType = "radio_buttons" + METEmailTextInput MessageElementType = "email_text_input" + METURLTextInput MessageElementType = "url_text_input" METNumber MessageElementType = "number_input" MixedElementImage MixedElementType = "mixed_image" @@ -390,6 +392,64 @@ func NewTimePickerBlockElement(actionID string) *TimePickerBlockElement { } } +// EmailTextInputBlockElement creates a field where a user can enter email +// data. +// email-text-input elements are currently only available in modals. +// +// More Information: https://api.slack.com/reference/block-kit/block-elements#email +type EmailTextInputBlockElement struct { + Type MessageElementType `json:"type"` + ActionID string `json:"action_id,omitempty"` + Placeholder *TextBlockObject `json:"placeholder,omitempty"` + InitialValue string `json:"initial_value,omitempty"` + DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"` + FocusOnLoad bool `json:"focus_on_load,omitempty"` +} + +// ElementType returns the type of the Element +func (s EmailTextInputBlockElement) ElementType() MessageElementType { + return s.Type +} + +// NewEmailTextInputBlockElement returns an instance of a plain-text input +// element +func NewEmailTextInputBlockElement(placeholder *TextBlockObject, actionID string) *EmailTextInputBlockElement { + return &EmailTextInputBlockElement{ + Type: METEmailTextInput, + ActionID: actionID, + Placeholder: placeholder, + } +} + +// URLTextInputBlockElement creates a field where a user can enter url data. +// +// url-text-input elements are currently only available in modals. +// +// More Information: https://api.slack.com/reference/block-kit/block-elements#url +type URLTextInputBlockElement struct { + Type MessageElementType `json:"type"` + ActionID string `json:"action_id,omitempty"` + Placeholder *TextBlockObject `json:"placeholder,omitempty"` + InitialValue string `json:"initial_value,omitempty"` + DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"` + FocusOnLoad bool `json:"focus_on_load,omitempty"` +} + +// ElementType returns the type of the Element +func (s URLTextInputBlockElement) ElementType() MessageElementType { + return s.Type +} + +// NewURLTextInputBlockElement returns an instance of a plain-text input +// element +func NewURLTextInputBlockElement(placeholder *TextBlockObject, actionID string) *URLTextInputBlockElement { + return &URLTextInputBlockElement{ + Type: METURLTextInput, + ActionID: actionID, + Placeholder: placeholder, + } +} + // PlainTextInputBlockElement creates a field where a user can enter freeform // data. // Plain-text input elements are currently only available in modals. diff --git a/block_element_test.go b/block_element_test.go index fad1ad2a1..164f8e2f7 100644 --- a/block_element_test.go +++ b/block_element_test.go @@ -142,6 +142,20 @@ func TestNewPlainTextInputBlockElement(t *testing.T) { } +func TestNewEmailTextInputBlockElement(t *testing.T) { + emailTextInputElement := NewEmailTextInputBlockElement(nil, "example@example.com") + + assert.Equal(t, string(emailTextInputElement.Type), "email_text_input") + assert.Equal(t, emailTextInputElement.ActionID, "example@example.com") +} + +func TestNewURLTextInputBlockElement(t *testing.T) { + urlTextInputElement := NewURLTextInputBlockElement(nil, "www.example.com") + + assert.Equal(t, string(urlTextInputElement.Type), "url_text_input") + assert.Equal(t, urlTextInputElement.ActionID, "www.example.com") +} + func TestNewCheckboxGroupsBlockElement(t *testing.T) { // Build Text Objects associated with each option checkBoxOptionTextOne := NewTextBlockObject("plain_text", "Check One", false, false)