diff --git a/block.go b/block.go index 240f55279..18222bd2b 100644 --- a/block.go +++ b/block.go @@ -50,6 +50,7 @@ type BlockAction struct { SelectedConversations []string `json:"selected_conversations"` SelectedDate string `json:"selected_date"` SelectedTime string `json:"selected_time"` + SelectedDateTime int64 `json:"selected_date_time"` InitialOption OptionBlockObject `json:"initial_option"` InitialUser string `json:"initial_user"` InitialChannel string `json:"initial_channel"` diff --git a/block_conv.go b/block_conv.go index 555e48117..4ab58de3f 100644 --- a/block_conv.go +++ b/block_conv.go @@ -110,6 +110,8 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error { e = &DatePickerBlockElement{} case "timepicker": e = &TimePickerBlockElement{} + case "datetimepicker": + e = &DateTimePickerBlockElement{} case "plain_text_input": e = &PlainTextInputBlockElement{} case "email_text_input": @@ -190,6 +192,8 @@ func (b *BlockElements) UnmarshalJSON(data []byte) error { blockElement = &DatePickerBlockElement{} case "timepicker": blockElement = &TimePickerBlockElement{} + case "datetimepicker": + blockElement = &DateTimePickerBlockElement{} case "plain_text_input": blockElement = &PlainTextInputBlockElement{} case "email_text_input": @@ -233,6 +237,7 @@ func (a *Accessory) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the Unmarshaller interface for Accessory, so that any JSON // unmarshalling is delegated and proper type determination can be made before unmarshal +// Note: datetimepicker is not supported in Accessory func (a *Accessory) UnmarshalJSON(data []byte) error { var r json.RawMessage diff --git a/block_element.go b/block_element.go index aba29c6ba..a70d8f2de 100644 --- a/block_element.go +++ b/block_element.go @@ -9,6 +9,7 @@ const ( METOverflow MessageElementType = "overflow" METDatepicker MessageElementType = "datepicker" METTimepicker MessageElementType = "timepicker" + METDatetimepicker MessageElementType = "datetimepicker" METPlainTextInput MessageElementType = "plain_text_input" METRadioButtons MessageElementType = "radio_buttons" METEmailTextInput MessageElementType = "email_text_input" @@ -392,6 +393,29 @@ func NewTimePickerBlockElement(actionID string) *TimePickerBlockElement { } } +// DateTimePickerBlockElement defines an element that allows the selection of both +// a date and a time of day formatted as a UNIX timestamp. +// More Information: https://api.slack.com/reference/messaging/block-elements#datetimepicker +type DateTimePickerBlockElement struct { + Type MessageElementType `json:"type"` + ActionID string `json:"action_id,omitempty"` + InitialDateTime int64 `json:"initial_date_time,omitempty"` + Confirm *ConfirmationBlockObject `json:"confirm,omitempty"` +} + +// ElementType returns the type of the Element +func (s DateTimePickerBlockElement) ElementType() MessageElementType { + return s.Type +} + +// NewDatePickerBlockElement returns an instance of a datetime picker element +func NewDateTimePickerBlockElement(actionID string) *DateTimePickerBlockElement { + return &DateTimePickerBlockElement{ + Type: METDatetimepicker, + ActionID: actionID, + } +} + // EmailTextInputBlockElement creates a field where a user can enter email // data. // email-text-input elements are currently only available in modals. diff --git a/block_element_test.go b/block_element_test.go index 164f8e2f7..0c47affc3 100644 --- a/block_element_test.go +++ b/block_element_test.go @@ -133,6 +133,12 @@ func TestNewTimePickerBlockElement(t *testing.T) { assert.Equal(t, timepickerElement.ActionID, "test") } +func TestNewDateTimePickerBlockElement(t *testing.T) { + datetimepickerElement := NewDateTimePickerBlockElement("test") + assert.Equal(t, string(datetimepickerElement.Type), "datetimepicker") + assert.Equal(t, datetimepickerElement.ActionID, "test") +} + func TestNewPlainTextInputBlockElement(t *testing.T) { plainTextInputElement := NewPlainTextInputBlockElement(nil, "test")