jolicode / slack-php-api

:hash: PHP Slack Client based on the official OpenAPI specification
https://jolicode.github.io/slack-php-api/
MIT License
221 stars 54 forks source link

Method chatPostMessage() with "blocks" return "invalid_blocks_format" #114

Closed ghost closed 3 years ago

ghost commented 3 years ago

Lib version: v4.1.1 PHP: 7.4.16

Hi, your lib is great! But i have problem with sending Blocks with chatPostMessage() method. I am trying everything and it does not work. I get response invalid_blocks_format from Slack.

My code looks like this:

$client->chatPostMessage([
            'channel' => '#channel',
            'username' => 'BOT',
            'blocks' => <<<EOT
{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "plain_text",
                "text": "This is a plain text section block.",
                "emoji": true
            }
        }
    ]
}
EOT]);

Could you check if everything is working properly?

damienalexandre commented 3 years ago

Hi!

Thanks for reaching out, I think this is a JSON escaping issue. You pass a JSON that has two times the "blocks" name :thinking:

You can find a nice working example here:

https://github.com/jolicode/slack-php-api/blob/6e4b7c83ab172884ad29cf7517841b7ba7ba4c82/tests/WritingTest.php#L54-L87

ghost commented 3 years ago

Thank you very much, it works! :)

Could you add this example into doc/examples? It would be great!

Thank you for very fast response!!!

damienalexandre commented 3 years ago

Just done that :+1: :heavy_check_mark:

Have a good day.