Closed MechJosh0 closed 3 years ago
Support has not yet been added for the new users
, conversations
, channels
select blocks. I'll look at creating a PR for this.
@cmbuckley Thanks for the work you've done. I'm having issues implementing it my end and I'm hoping you can take a look.
Using the example from Slacks documentation on multi_users_select I've done the following:
->withBlock([
"type" => "section",
"block_id" => "section678",
"text" => [
"type" => "mrkdwn",
"text" => "Pick users from the list",
],
"accessory" => [
"action_id" => "text1234",
"type" => "multi_users_select",
"initial_users" => [],
"placeholder" => [
"type" => "plain_text",
"text" => "Select users",
],
]
])
Slack states that initial_users
should not be required (per the documentation) but the package will throw a count
error if it's not defined because a default value is not being set, so setting the default value to be []
resolves this error.
Aside from this, I still cannot get the notification to send and I get the following error from the Slack API request:
Client error: `POST https://hooks.slack.com/services/****** resulted in a `400 Bad Request` response:\ninvalid_blocks\n
I get the same error when I try to use an input
block type as well.
Would you like me to open a new issue for the above?
Hi,
Please try to provide a self-contained example of your error, because the block you have posted above works fine for me. You can also see this at the block kit builder.
You can debug the message as follows:
try {
$client->send();
} catch (GuzzleHttp\Exception\ClientException $ex) {
var_dump(json_encode($client->preparePayload($client->getMessage())));
}
Also, please can you explain more your point about initial_users
, because again this example appears to work fine without adding the field:
$client = new Maknz\Slack\Client($token);
$client->withBlock([
"type" => "section",
"block_id" => "section678",
"text" => [
"type" => "mrkdwn",
"text" => "Pick users from the list",
],
"accessory" => [
"action_id" => "text1234",
"type" => "multi_users_select",
"placeholder" => [
"type" => "plain_text",
"text" => "Select users",
],
]
])->send('Fallback message');
Sorry, the thrown client error was because I was providing a blank image URL.
However, I'm still unable to not provide a blank initial_users
array. The below code:
$client = new Client('https://hooks.slack.com/services/xxxxxxx');
$client->to('#foo')
->withBlock([
"type" => "section",
"block_id" => "section678",
"text" => [
"type" => "mrkdwn",
"text" => "Pick users from the list",
],
"accessory" => [
"action_id" => "text1234",
"type" => "multi_users_select",
// "initial_users" => [],
"placeholder" => [
"type" => "plain_text",
"text" => "Select users",
],
]
])
->send('Fallback message');
Will throw the following error:
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null givenPHPUnit
MultiUsersSelect.php(112, 9): TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
Section.php(167, 13): TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
Message.php(436, 13): TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
Client.php(535, 13): TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
Client.php(467, 9): TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
Client.php(503, 9): TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
If I uncomment // "initial_users" => [],
then the Slack message will send perfectly fine without errors. It's being required by the client, but my understanding is that it's not meant to be.
If you set a default array value for initial_users
, this resolves the problem.
// MultiUsersSelect::20
protected $initial_users = [];
Aha, your error message has helped me track this one down - in PHP 8.0, count
defines compulsory types that are not enforced in 7.x (there is a warning, which should have been noticed too, but was not).
I'll reopen this issue and make sure that:
@cmbuckley thank you!
I'm attempting to use input type
multi_users_select
but I am being thrown an error that I'm not allowed to use it. I'm assuming the package isn't aware it's a valid input type. It does exist and can be seen in Slacks Block Kit Buider and block elements documentation.