Repository: slack-go/slack
Pull request #1341 (2024-10-31 15:08:29)

fix: Don't require `skin_tone` for rich text emoji element
In a rich text `emoji` element, the `skin_tone` value is optional, and when not provided will use the default skin tone. When unmarshalling from JSON, this parameter defaults to an invalid value of 0 (`skin_tone` values range from 2 to 6), resulting in an "invalid_blocks" error when sending a message. This PR allows the `skin_tone` element to be omitted when unmarshalling from JSON.


Patch:
diff --git a/assistant.go b/assistant.go
index ef1425f..8432f89 100644
--- a/assistant.go
+++ b/assistant.go
@@ -60,6 +60,8 @@ func (api *Client) SetAssistantThreadsSuggestedPromptsContext(ctx context.Contex
 		values.Add("thread_ts", params.ThreadTS)
 	}
 
+	values.Add("channel_id", params.ChannelID)
+
 	// Send Prompts as JSON
 	prompts, err := json.Marshal(params.Prompts)
 	if err != nil {
@@ -98,6 +100,8 @@ func (api *Client) SetAssistantThreadsStatusContext(ctx context.Context, params
 		values.Add("thread_ts", params.ThreadTS)
 	}
 
+	values.Add("channel_id", params.ChannelID)
+
 	// Always send the status parameter, if empty, it will clear any existing status
 	values.Add("status", params.Status)
 
diff --git a/block_rich_text.go b/block_rich_text.go
index c6eb0b1..22020be 100644
--- a/block_rich_text.go
+++ b/block_rich_text.go
@@ -340,7 +340,7 @@ func NewRichTextSectionUserElement(userID string, style *RichTextSectionTextStyl
 type RichTextSectionEmojiElement struct {
 	Type     RichTextSectionElementType `json:"type"`
 	Name     string                     `json:"name"`
-	SkinTone int                        `json:"skin_tone"`
+	SkinTone int                        `json:"skin_tone,omitempty"`
 	Unicode  string                     `json:"unicode,omitempty"`
 	Style    *RichTextSectionTextStyle  `json:"style,omitempty"`
 }


Test patch:
diff --git a/block_rich_text_test.go b/block_rich_text_test.go
index dc4a0cf..903f143 100644
--- a/block_rich_text_test.go
+++ b/block_rich_text_test.go
@@ -187,6 +187,16 @@ func TestRichTextSection_UnmarshalJSON(t *testing.T) {
 			},
 			nil,
 		},
+		{
+			[]byte(`{"type": "rich_text_section","elements":[{"type": "emoji","name": "+1"}]}`),
+			RichTextSection{
+				Type: RTESection,
+				Elements: []RichTextSectionElement{
+					&RichTextSectionEmojiElement{Type: RTSEEmoji, Name: "+1"},
+				},
+			},
+			nil,
+		},
 		{
 			[]byte(`{"type": "rich_text_section","elements":[{"type": "emoji","name": "+1","unicode": "1f44d-1f3fb","skin_tone": 2}]}`),
 			RichTextSection{
@@ -299,7 +309,7 @@ func TestRichTextList_UnmarshalJSON(t *testing.T) {
 
 func TestRichTextQuote_Marshal(t *testing.T) {
 	t.Run("rich_text_section", func(t *testing.T) {
-		const rawRSE = "{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Some Text\"}]}"
+		const rawRSE = "{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Some Text\"},{\"type\":\"emoji\",\"name\":\"+1\"},{\"type\":\"emoji\",\"name\":\"+1\",\"skin_tone\":2}]}"
 
 		var got RichTextSection
 		if err := json.Unmarshal([]byte(rawRSE), &got); err != nil {
@@ -309,6 +319,8 @@ func TestRichTextQuote_Marshal(t *testing.T) {
 			Type: RTESection,
 			Elements: []RichTextSectionElement{
 				&RichTextSectionTextElement{Type: RTSEText, Text: "Some Text"},
+				&RichTextSectionEmojiElement{Type: RTSEEmoji, Name: "+1"},
+				&RichTextSectionEmojiElement{Type: RTSEEmoji, Name: "+1", SkinTone: 2},
 			},
 		}