Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Notifier] Allow to set block_id/value for SlackActionsBlock and SlackButtonBlockElement #60209

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,26 @@ public function __construct()
/**
* @return $this
*/
public function button(string $text, string $url, ?string $style = null): static
public function button(string $text, ?string $url = null, ?string $style = null, ?string $value = null): static
{
if (25 === \count($this->options['elements'] ?? [])) {
throw new \LogicException('Maximum number of buttons should not exceed 25.');
}

$element = new SlackButtonBlockElement($text, $url, $style);
$element = new SlackButtonBlockElement($text, $url, $style, $value);

$this->options['elements'][] = $element->toArray();

return $this;
}

/**
* @return $this
*/
public function id(string $id): static
{
$this->options['block_id'] = $id;

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,27 @@
*/
final class SlackButtonBlockElement extends AbstractSlackBlockElement
{
public function __construct(string $text, string $url, ?string $style = null)
public function __construct(string $text, ?string $url = null, ?string $style = null, ?string $value = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this change makes sense. Buttons defined this way are legacy anyway?
What would the value be used for, for buttons?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to slack API docs:

The value to send along with the interaction payload. Maximum length is 2000 characters.

If you want to react for a callback upon button is pressed, you can get a value of the button that was pressed, what can be hard without the value set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple example would be buttons like Approve & Decline that are included in one message - without the value, you can not determine which one was pressed by the user by just looking at the callback payload.

{
$this->options = [
'type' => 'button',
'text' => [
'type' => 'plain_text',
'text' => $text,
],
'url' => $url,
];

if ($url) {
$this->options['url'] = $url;
}

if ($style) {
// primary or danger
$this->options['style'] = $style;
}

if ($value) {
$this->options['value'] = $value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ final class SlackActionsBlockTest extends TestCase
public function testCanBeInstantiated()
{
$actions = new SlackActionsBlock();
$actions->button('first button text', 'https://example.org')
$actions->button('first button text', 'https://example.org', null, 'test-value')
->button('second button text', 'https://example.org/slack', 'danger')
->button('third button text', null, null, 'test-value-3')
;

$this->assertSame([
Expand All @@ -33,6 +34,7 @@ public function testCanBeInstantiated()
'text' => 'first button text',
],
'url' => 'https://example.org',
'value' => 'test-value'
],
[
'type' => 'button',
Expand All @@ -43,6 +45,14 @@ public function testCanBeInstantiated()
'url' => 'https://example.org/slack',
'style' => 'danger',
],
[
'type' => 'button',
'text' => [
'type' => 'plain_text',
'text' => 'third button text',
],
'value' => 'test-value-3',
]
],
], $actions->toArray());
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.