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

Sending RichText messages invalid_blocks error #90

Closed
AlesDo opened this issue Jan 18, 2024 · 6 comments
Closed

Sending RichText messages invalid_blocks error #90

AlesDo opened this issue Jan 18, 2024 · 6 comments

Comments

@AlesDo
Copy link

AlesDo commented Jan 18, 2024

I am facing a problem sending a message containing a rich text block. I get the error invalid_blocks. This happens using the following basic sample..

var slackWebApiClient = new SlackWebApiClient(Environment.GetEnvironmentVariable("SLACK_BOT_TOKEN"));

var richText = new RichText(
    new RichTextSection()
    {
        Elements = new List<RichTextElement>()
        {
            new TextElement()
            {
                Text = "Hello Rich Text"
            } 
        }
    });
var blocks = [richText];
var postMessageRequest = new PostMessageRequest()
{
    Channel = "<ValidChannelID>", 
    Text = "Hello From API",
    Blocks = blocks
};
var response =await slackWebApiClient.Chat.Post(postMessageRequest);

Am I doing something wrong or this is not supported?

@stoiveyp
Copy link
Owner

Morning @AlesDo - I'm at work right now so I can't replicate the issue for a little while.

when you look at the response object - is there a pointer returned with the error messager (like /blocks[0]...) that could help us narrow down the problem? The example you sent works in the Block Kit Builder so just seeing if there's more help coming from Slack until I can try and recreate it

@AlesDo
Copy link
Author

AlesDo commented Jan 18, 2024

Hi @stoiveyp !

Thanks for your quick reply.
The pointer returned is: must provide a string [json-pointer:/blocks/0/elements/0/elements/0/type].
It looks like it is a serialization issue that the type is not set for elements. it is set to null if I serialize the PostMessageReaquest using JsonConvert.SerializeObject.
Here is the output from serializing the request:

{
  "mrkdwn": false,
  "channel": "U06EE5LP7Q9",
  "blocks": [
    {
      "type": "rich_text",
      "block_id": "d2ff47786b264d7389c67a5695a587a0",
      "elements": [
        {
          "type": "rich_text_section",
          "elements": [
            {
              "text": "Hello World",
              "type": null
            }
          ]
        }
      ]
    }
  ],
  "text": "Hello from slack app!!!!!",
  "parse": "none"
}

@stoiveyp
Copy link
Owner

Oh! Yeah that's clearly wrong. I'll get a new test written and fix it once my working day is done. Apologies and thanks for raising it 👍

@stoiveyp
Copy link
Owner

This should now be fixed in v8.2.1 - please let me know 👍

@AlesDo
Copy link
Author

AlesDo commented Jan 22, 2024

Yes now it works. Thanks for the quick fix.
There is just one detail more. If you don't provide the BlockId on the rich text block it serializes to null which again cause an error. must provide a string [json-pointer:/blocks/0/block_id]. It should be omitted if it is not specified since it is an optional field https://api.slack.com/reference/block-kit/blocks#rich_fields

@stoiveyp
Copy link
Owner

v9.0.0 onward has Rich Text block_id set to optional

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

No branches or pull requests

2 participants