This repository was archived by the owner on Jun 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Added ability to add actions (buttons) within the attachment #32
Open
craigwillis85
wants to merge
3
commits into
sagebind:master
Choose a base branch
from
craigwillis85:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
| namespace Slack\Message; | ||
|
|
||
| use Slack\DataObject; | ||
|
|
||
| /** | ||
| * An action inside a message attachment. | ||
| * | ||
| * @see https://api.slack.com/docs/attachments | ||
| */ | ||
| class AttachmentAction extends DataObject | ||
| { | ||
| /** | ||
| * Creates a new attachment action. | ||
| * | ||
| * @param string $name A text heading for the field. | ||
| * @param string $text The text value of the field. | ||
| * @param string $type The type value of the field. | ||
| * @param string $value The value of the field. | ||
| * @param array $confirm Array for button confirmation | ||
| */ | ||
| public function __construct($name, $text, $type, $value, array $confirm = null) | ||
| { | ||
| $this->data['name'] = $name; | ||
| $this->data['text'] = $text; | ||
| $this->data['type'] = $type; | ||
| $this->data['value'] = $value; | ||
|
|
||
| if (isset($confirm)) { | ||
| $this->data['confirm'] = $confirm; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the text heading for the field. | ||
| * | ||
| * @return string The text heading for the field. | ||
| */ | ||
| public function getName() | ||
| { | ||
| return $this->data['name']; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the text value of the field. | ||
| * | ||
| * @return string The text value of the field. | ||
| */ | ||
| public function getText() | ||
| { | ||
| return $this->data['text']; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the text type of the field. | ||
| * | ||
| * @return string The type value of the field. | ||
| */ | ||
| public function getType() | ||
| { | ||
| return $this->data['type']; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the text value of the field. | ||
| * | ||
| * @return string The text value of the field. | ||
| */ | ||
| public function getValue() | ||
| { | ||
| return $this->data['value']; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the confirmation details for the action. | ||
| * | ||
| * @return array Array containing the confirmation. | ||
| */ | ||
| public function getConfirm() | ||
| { | ||
| return isset($this->data['confirm']) ? $this->data['confirm'] : ''; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?php | ||
| namespace Slack\Tests\Message; | ||
|
|
||
| use Slack\Message\AttachmentAction; | ||
| use Slack\Tests\TestCase; | ||
|
|
||
| class AttachmentActionTest extends TestCase | ||
| { | ||
| public function testConstructor() | ||
| { | ||
| $name = $this->faker->title; | ||
| $text = $this->faker->title; | ||
| $type = 'button'; | ||
| $confirm = null; | ||
|
|
||
| $field = new AttachmentAction($name, $text, $type, $confirm); | ||
|
|
||
| $this->assertEquals($name, $field->getName()); | ||
| $this->assertEquals($text, $field->getText()); | ||
| $this->assertEquals($type, $field->getType()); | ||
| $this->assertEquals($confirm, $field->getConfirm()); | ||
| } | ||
|
|
||
| public function testGetName() | ||
| { | ||
| $field = AttachmentAction::fromData([ | ||
| 'name' => $this->faker->title, | ||
| ]); | ||
|
|
||
| $this->assertEquals($field->data['name'], $field->getName()); | ||
| } | ||
|
|
||
| public function testGetText() | ||
| { | ||
| $field = AttachmentAction::fromData([ | ||
| 'text' => $this->faker->title, | ||
| ]); | ||
|
|
||
| $this->assertEquals($field->data['text'], $field->getText()); | ||
| } | ||
|
|
||
| public function testGetType() | ||
| { | ||
| $field = AttachmentAction::fromData([ | ||
| 'type' => $this->faker->title, | ||
| ]); | ||
|
|
||
| $this->assertEquals($field->data['type'], $field->getType()); | ||
| } | ||
|
|
||
| public function testConfirm() | ||
| { | ||
| $field = AttachmentAction::fromData([ | ||
| 'confirm' => null, | ||
| ]); | ||
|
|
||
| $this->assertEquals($field->data['confirm'], $field->getConfirm()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thought here, you probably want to use
$callback_id = nullin the constructor here, otherwise it breaks the existing API contract for the Attachment object and will break code on upgrade.If you really meant to require the field, you probably should move it before
$fallbackas this order would require all constructor calls to also specify a value, or null, for$fallbackas well.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is changed to
$callback_id = nullthen it should also be moved to the end of the constructor, after all the existing parameters, otherwise it will still be a breaking change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was having a small brain-fart on that positioning... 😨