diff --git a/block_object.go b/block_object.go index b39ff228..a3e78d4e 100644 --- a/block_object.go +++ b/block_object.go @@ -147,6 +147,16 @@ func (s TextBlockObject) Validate() error { return errors.New("emoji cannot be true in mrkdown") } + // https://api.slack.com/reference/block-kit/composition-objects#text__fields + if len(s.Text) == 0 { + return errors.New("text must have a minimum length of 1") + } + + // https://api.slack.com/reference/block-kit/composition-objects#text__fields + if len(s.Text) > 3000 { + return errors.New("text cannot be longer than 3000 characters") + } + return nil } diff --git a/block_object_test.go b/block_object_test.go index 9889fae4..1f4874a0 100644 --- a/block_object_test.go +++ b/block_object_test.go @@ -2,6 +2,7 @@ package slack import ( "errors" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -126,6 +127,24 @@ func TestValidateTextBlockObject(t *testing.T) { }, expected: errors.New("emoji cannot be true in mrkdown"), }, + { + input: TextBlockObject{ + Type: "mrkdwn", + Text: "", + Emoji: false, + Verbatim: false, + }, + expected: errors.New("text must have a minimum length of 1"), + }, + { + input: TextBlockObject{ + Type: "mrkdwn", + Text: strings.Repeat("a", 3001), + Emoji: false, + Verbatim: false, + }, + expected: errors.New("text cannot be longer than 3000 characters"), + }, } for _, test := range tests {