Closed akuzia closed 2 years ago
I can't reproduce. Could you give me some more details?
I've updated the lib, enabled debugging and still getting the same error with code below:
package main
import (
"encoding/json"
"fmt"
"github.com/slack-go/slack"
)
func main() {
api := slack.New(
"xoxb-...",
slack.OptionDebug(true),
)
block := slack.NewRichTextBlock("",
slack.NewRichTextSection(
slack.NewRichTextSectionTextElement("test message", nil),
),
)
if blocksJson, err := json.Marshal(block); err == nil {
fmt.Println(string(blocksJson))
} else {
fmt.Println(err)
}
if _, _, err := api.PostMessage(
"test",
slack.MsgOptionBlocks(block),
); err != nil {
err := err.(slack.SlackErrorResponse)
fmt.Printf("slack: %s: %v\n", err.Error(), err.ResponseMetadata)
}
}
go mod for reference:
module github.com/akuzia/first
go 1.18
require github.com/slack-go/slack v0.11.3
require github.com/gorilla/websocket v1.4.2 // indirect
Output:
# go run ./main.go
{"type":"rich_text","elements":[{"type":"rich_text_section","elements":[{"type":"text","text":"test message"}]}]}
slack-go/slack2022/09/12 09:41:17 chat.go:227: Sending request: blocks=%5B%7B%22type%22%3A%22rich_text%22%2C%22elements%22%3A%5B%7B%22type%22%3A%22rich_text_section%22%2C%22elements%22%3A%5B%7B%22type%22%3A%22text%22%2C%22text%22%3A%22test+message%22%7D%5D%7D%5D%7D%5D&channel=test&token=xoxb-...
slack: invalid_blocks: { [] []}
Thanks. I was able to reproduce it. By the way, it does not seem to be a library's bug because I get an error when I use Tester. I'll do some more research and report back here if I find anything.
@akuzia
I inquired Slack support about this and got an answer.
These are data structures that can only be used when received as a response from Slack, so we cannot use rich_text
or rich_text_section
for user posting messages...
p.s.
You can use webhook if you want rich_text
block.
I'm going to close this issue but I'd like to think of some way not to have problems with this confusing specification. Thank you for reporting.
What happened
Simple RichTextBlock is valid in block kit, but not valid in api. Returned error has no useful metadata.
Expected behavior
RichText is successfuly sent, nil error returned
Steps to reproduce
reproducible code
manifest.yaml
Versions
go1.18.3 linux/amd64
v0.11.0