Repository: slack-go/slack
Pull request #780 (2020-08-18 00:48:03)

Revert "Fix block_object typo and refactor to use static type"
Reverts slack-go/slack#762


Patch:
diff --git a/block_conv.go b/block_conv.go
index 4f11228..656a9ab 100644
--- a/block_conv.go
+++ b/block_conv.go
@@ -381,7 +381,7 @@ func (e *ContextElements) UnmarshalJSON(data []byte) error {
 		}
 
 		switch contextElementType {
-		case string(MBTPlainText), string(MBTMarkdown):
+		case PlainTextType, MarkdownType:
 			elem, err := unmarshalBlockObject(r, &TextBlockObject{})
 			if err != nil {
 				return err
diff --git a/block_object.go b/block_object.go
index a885722..c7df800 100644
--- a/block_object.go
+++ b/block_object.go
@@ -14,8 +14,8 @@ import (
 
 // blockObject object types
 const (
-	MBTMarkdown  MessageBlockType = "mrkdwn"
-	MBTPlainText MessageBlockType = "plain_text"
+	MarkdownType  = "mrkdwn"
+	PlainTextType = "plain_text"
 	// The following objects don't actually have types and their corresponding
 	// const values are just for internal use
 	motConfirmation = "confirm"
@@ -55,7 +55,7 @@ func (b *BlockObjects) UnmarshalJSON(data []byte) error {
 		blockObjectType := getBlockObjectType(obj)
 
 		switch blockObjectType {
-		case string(MBTPlainText), string(MBTMarkdown):
+		case PlainTextType, MarkdownType:
 			object, err := unmarshalBlockObject(r, &TextBlockObject{})
 			if err != nil {
 				return err
@@ -119,10 +119,10 @@ func unmarshalBlockObject(r json.RawMessage, object blockObject) (blockObject, e
 //
 // More Information: https://api.slack.com/reference/messaging/composition-objects#text
 type TextBlockObject struct {
-	Type     MessageBlockType `json:"type"`
-	Text     string           `json:"text"`
-	Emoji    bool             `json:"emoji,omitempty"`
-	Verbatim bool             `json:"verbatim,omitempty"`
+	Type     string `json:"type"`
+	Text     string `json:"text"`
+	Emoji    bool   `json:"emoji,omitempty"`
+	Verbatim bool   `json:"verbatim,omitempty"`
 }
 
 // validateType enforces block objects for element and block parameters
@@ -136,7 +136,7 @@ func (s TextBlockObject) MixedElementType() MixedElementType {
 }
 
 // NewTextBlockObject returns an instance of a new Text Block Object
-func NewTextBlockObject(elementType MessageBlockType, text string, emoji, verbatim bool) *TextBlockObject {
+func NewTextBlockObject(elementType, text string, emoji, verbatim bool) *TextBlockObject {
 	return &TextBlockObject{
 		Type:     elementType,
 		Text:     text,
@@ -147,7 +147,10 @@ func NewTextBlockObject(elementType MessageBlockType, text string, emoji, verbat
 
 // BlockType returns the type of the block
 func (t TextBlockObject) BlockType() MessageBlockType {
-	return t.Type
+	if t.Type == "mrkdown" {
+		return MarkdownType
+	}
+	return PlainTextType
 }
 
 // ConfirmationBlockObject defines a dialog that provides a confirmation step to


Test patch:
diff --git a/block_image_test.go b/block_image_test.go
index a52ec16..3cdd203 100644
--- a/block_image_test.go
+++ b/block_image_test.go
@@ -12,7 +12,7 @@ func TestNewImageBlock(t *testing.T) {
 	imageBlock := NewImageBlock("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Marker", "test", imageText)
 
 	assert.Equal(t, string(imageBlock.Type), "image")
-	assert.Equal(t, string(imageBlock.Title.Type), "plain_text")
+	assert.Equal(t, imageBlock.Title.Type, "plain_text")
 	assert.Equal(t, imageBlock.BlockID, "test")
 	assert.Contains(t, imageBlock.Title.Text, "Location")
 	assert.Contains(t, imageBlock.ImageURL, "tripAgentLocationMarker.png")
diff --git a/block_object_test.go b/block_object_test.go
index 0f08ce1..8a86904 100644
--- a/block_object_test.go
+++ b/block_object_test.go
@@ -20,7 +20,7 @@ func TestNewTextBlockObject(t *testing.T) {
 
 	textObject := NewTextBlockObject("plain_text", "test", true, false)
 
-	assert.Equal(t, string(textObject.Type), "plain_text")
+	assert.Equal(t, textObject.Type, "plain_text")
 	assert.Equal(t, textObject.Text, "test")
 	assert.True(t, textObject.Emoji, "Emoji property should be true")
 	assert.False(t, textObject.Verbatim, "Verbatim should be false")
diff --git a/block_section_test.go b/block_section_test.go
index 5539687..3f9f452 100644
--- a/block_section_test.go
+++ b/block_section_test.go
@@ -15,7 +15,7 @@ func TestNewSectionBlock(t *testing.T) {
 	assert.Equal(t, string(sectionBlock.BlockID), "test_block")
 	assert.Equal(t, len(sectionBlock.Fields), 0)
 	assert.Nil(t, sectionBlock.Accessory)
-	assert.Equal(t, string(sectionBlock.Text.Type), "mrkdwn")
+	assert.Equal(t, sectionBlock.Text.Type, "mrkdwn")
 	assert.Contains(t, sectionBlock.Text.Text, "New Orleans")
 
 }
diff --git a/chat_test.go b/chat_test.go
index 3c34795..a038728 100644
--- a/chat_test.go
+++ b/chat_test.go
@@ -77,7 +77,7 @@ func TestPostMessage(t *testing.T) {
 		expected url.Values
 	}
 
-	blocks := []Block{NewContextBlock("context", NewTextBlockObject(MBTPlainText, "hello", false, false))}
+	blocks := []Block{NewContextBlock("context", NewTextBlockObject(PlainTextType, "hello", false, false))}
 	blockStr := `[{"type":"context","block_id":"context","elements":[{"type":"plain_text","text":"hello"}]}]`
 
 	tests := map[string]messageTest{
@@ -137,7 +137,7 @@ func TestPostMessage(t *testing.T) {
 }
 
 func TestPostMessageWithBlocksWhenMsgOptionResponseURLApplied(t *testing.T) {
-	expectedBlocks := []Block{NewContextBlock("context", NewTextBlockObject(MBTPlainText, "hello", false, false))}
+	expectedBlocks := []Block{NewContextBlock("context", NewTextBlockObject(PlainTextType, "hello", false, false))}
 
 	http.DefaultServeMux = new(http.ServeMux)
 	http.HandleFunc("/response-url", func(rw http.ResponseWriter, r *http.Request) {