php-slack / slack

A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax.
BSD 2-Clause "Simplified" License
135 stars 27 forks source link

Checkboxes accessory doesn't work: #60

Closed mongeron closed 3 years ago

mongeron commented 3 years ago

I am trying to use Slack Checkboxes accessory with a text field. This is the block definition from Slack's BlockKit page:

{
    "type": "section",
    "text": {
        "type": "mrkdwn",
        "text": "Testtext"
    },
    "accessory": {
        "type": "checkboxes",
        "options": [
            {
                "value": "ACK",
                "text": {
                    "type": "plain_text",
                    "text": "Acknowledge"
                }
            }
        ]
    }
}

I have formatted it to following PHP array structure:

$text = array(
    'type'      => 'section',
    'text'      => array(
        'type' => 'mrkdwn',
        'text' => $message,
    ),
    'accessory' => array(
        'type'    => 'checkboxes',
        'options' => array(
            array(
                'value' => 'ACK',
                'text'  => array(
                    'type' => 'plain_text',
                    'text' => 'Acknowledge',
                ),
            ),
        ),
    ),
);

I am using:

$client->withBlock($text)->send('Test');

to send the message.

I get the following exception:

PHP Fatal error:  Uncaught InvalidArgumentException: Invalid Block type "checkboxes". Must be one of: button, checkbox, datepicker, image, multi_static_select, overflow, plain_text_input, radio_buttons, static_select, plain_text, mrkdwn. in /home/tero/code/ndc/core/vendor/alek13/slack/src/BlockElement.php:62
Stack trace:
#0 /home/tero/code/ndc/core/vendor/alek13/slack/src/Block/Section.php(127): Maknz\Slack\BlockElement::factory()
#1 /home/tero/code/ndc/core/vendor/alek13/slack/src/Payload.php(33): Maknz\Slack\Block\Section->setAccessory()
#2 /home/tero/code/ndc/core/vendor/alek13/slack/src/Payload.php(20): Maknz\Slack\Payload->fillProperties()
#3 /home/tero/code/ndc/core/vendor/alek13/slack/src/Block.php(87): Maknz\Slack\Payload->__construct()
#4 /home/tero/code/ndc/core/vendor/alek13/slack/src/Message.php(407): Maknz\Slack\Block::factory()
#5 /home/tero/code/ndc/core/vendor/alek13/slack/src/Client.php(185): Maknz\Slack\Message->withBlock()
#6 /home/tero/code/ndc/core/classes/Slack.php(71): Maknz\Slack\Client->__call()
#7 /ho in /home/tero/code/ndc/core/vendor/alek13/slack/src/BlockElement.php on line 62

If I change type to checkbox, the error is:

PHP Fatal error:  Uncaught Error: Class 'Maknz\Slack\BlockElement\Checkbox' not found in /home/tero/code/ndc/core/vendor/alek13/slack/src/BlockElement.php:67

Is this an issue with the library or is it a problem in my block definition?

cmbuckley commented 3 years ago

Hi @mongeron, thanks for this! This is indeed a bug in the new Block Kit. I've created a patch in #61.

alek13 commented 3 years ago

Thanks @cmbuckley

alek13 commented 3 years ago

Released in 2.0.1