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

Blocks #245

Open
legoboyvdlp opened this issue Jul 27, 2020 · 4 comments
Open

Blocks #245

legoboyvdlp opened this issue Jul 27, 2020 · 4 comments

Comments

@legoboyvdlp
Copy link

legoboyvdlp commented Jul 27, 2020

Hi,

I am having trouble sending a block message to slack. I wonder if someone could advise me what I am doing wrong?
I can send ordinary messages just fine, but its these blocks that are giving problems. I was unable to find any example or documentation for this, but this, I understood should have worked...

var length = List.Count;
var blockArr = new SectionBlock[1];
                blockArr[0] = new SectionBlock();
                blockArr[0].fields = new Text[length];
                for (var i = 0; i < length; i++)
                {
                    var text = new Text();
                    text.text = // my string,
                    blockArr[0].fields[i] = text;
                }
                await sendMessageAsync("#channel", text: "Test", block: blockArr);
            });

My sendMessageAsync function is as such:

public static async Task<PostMessageResponse> sendMessageAsync(string channel, string text = "", IBlock[] block = null)
        {
            var response = await slackClient.PostMessageAsync(channel, text: text, blocks: block);
            Console.WriteLine(response.error);
            return response;
        }

In each case I get invalid_blocks as an error.

@legoboyvdlp
Copy link
Author

Does anyone have any ideas on this -- this is somewhat delaying my project until I can solve this :)

@Inumedia
Copy link
Owner

Unfortunately, I'm not well-versed with the newer Blocks APIs.

Afaik, we don't do any validation in the library and the messages just get serialized as-is and sent to Slack. It might be worthwhile to check other libraries or the official API for any hints on what's causing this.

It also might be worthwhile to view the raw responses with Fiddler4 or use the library directly and step through to see the raw response from the API to see if it contains any more descriptive error messages.

@legoboyvdlp
Copy link
Author

Hi, thank you in any case. I will try and inspect the serialized JSON to see what it shows :)

@legoboyvdlp
Copy link
Author

Ok, I got this, using a new script:
Block block = new Block(); Text text = new Text(); text.type = TextTypes.PlainText; block.type = BlockTypes.Section; text.text = "Test"; block.text = text; block.title = text; block.block_id = "test"; blocks[i] = block;

channel=#milcom-bot-test&text=:bubblealert: Test&blocks=[{"type":"section","block_id":"test","text":{"type":"plain_text","text":"Test"},"title":{"type":"plain_text","text":"Test"}},{"type":"section","block_id":"test","text":{"type":"plain_text","text":"Test"},"title":{"type":"plain_text","text":"Test"}},{"type":"section","block_id":"test","text":{"type":"plain_text","text":"Test"},"title":{"type":"plain_text","text":"Test"}},{"type":"section","block_id":"test","text":{"type":"plain_text","text":"Test"},"title":{"type":"plain_text","text":"Test"}}]

This is hard to read, but when imported to the slack Block Builder, I see that:

"title" is invalid for a block of type section: (Invalid additional property "title" error)
Also, block ID must be unique.

I think there is a bug with the title element on your side, and a bug in the block ID on my side :)

So I will continue debugging, now moving on to try and add fields.

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