Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to disable emojis in plain text blocks #1332

Open
christeredvartsen opened this issue Oct 10, 2024 · 2 comments
Open

Unable to disable emojis in plain text blocks #1332

christeredvartsen opened this issue Oct 10, 2024 · 2 comments
Labels

Comments

@christeredvartsen
Copy link

What happened

Creating a TextBlockObject with the Emoji field set to false does not disable rendering of emojis in that text block.

The reason this happens is because of the omitempty JSON-tag:

type TextBlockObject struct {
	Type     string `json:"type"`
	Text     string `json:"text"`
	Emoji    bool   `json:"emoji,omitempty"` // <-- this one
	Verbatim bool   `json:"verbatim,omitempty"`
}

This causes the field to be removed from the payload when encoded to JSON (if the field is false) as seen in this snippet: https://go.dev/play/p/63tqgJJ6Nnt.

The required JSON payload for creating a plain text object without support for emojis is:

{
	"type": "section",
	"text": {
		"type": "plain_text",
		"text": ":+1:",
		"emoji": false
	}
}

This is likely an issue for some other fields with the omitempty tag as well, where you explicitly need to set a value to false in the JSON payload for the Slack API.

Expected behavior

Creating a TextBlockObject with the Emoji field set to false should disable rendering of emojis in that text block.

Steps to reproduce

emoji, verbatim := false, false
slack.New("some token").PostMessage(
	"channel ID",
	slack.MsgOptionBlocks(
		slack.NewSectionBlock(
			slack.NewTextBlockObject("plain_text", ":+1:", emoji, verbatim), 
			nil, 
			nil,
		),
	),
)

Versions

  • Go: go version go1.23.1 linux/amd64
  • slack-go/slack: v0.14.0
@Manjish
Copy link
Contributor

Manjish commented Nov 1, 2024

How about we change the type of emoji to bool pointer ? This will remove the field if a nil value is passed and will retain the false value as well 🤔

@calebmckay
Copy link
Contributor

I can probably look at fixing this, since it's the same sort of change as #1341. Might also do a deep dive to see if there's any other omitempty fields that could be turned to pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants