-
Notifications
You must be signed in to change notification settings - Fork 27
Add support for Slack's "Blocks" and OAuth instead of webhooks #53
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
mikeymclellan
wants to merge
9
commits into
nexylan:master
Choose a base branch
from
ideahq:block
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be09b3a
Add support for Slack Blocks in messages
mikeymclellan d63d167
Add support for Slack Blocks in messages
mikeymclellan c63b127
Add ability to set slack's `replace_original` field
mikeymclellan 2bbc0e2
Add OAuth support for sending messages
mikeymclellan 167fcfb
Add some docs for using OAuth and simplify the interface without brea…
mikeymclellan 48ff124
Fix doc indentation
mikeymclellan 1e1d4c7
Update Slack Oauth documentation link
mikeymclellan 505570c
Update documentation intro to include oauth info
mikeymclellan a0d0339
Remove company logo etc
mikeymclellan 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,26 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the Nexylan packages. | ||
| * | ||
| * (c) Nexylan SAS <contact@nexylan.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Nexy\Slack; | ||
|
|
||
| /** | ||
| * @author Sullivan Senechal <soullivaneuh@gmail.com> | ||
| * @author Mikey McLellan <mikey@mclellan.org.nz> | ||
| */ | ||
| final class ActionsBlock extends ElementsBlock | ||
| { | ||
| public function __construct() | ||
| { | ||
| parent::__construct('actions'); | ||
| } | ||
| } |
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,99 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the Nexylan packages. | ||
| * | ||
| * (c) Nexylan SAS <contact@nexylan.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Nexy\Slack; | ||
|
|
||
| /** | ||
| * @author Sullivan Senechal <soullivaneuh@gmail.com> | ||
| * @author Mikey McLellan <mikey@mclellan.org.nz> | ||
| */ | ||
| class Block | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| protected $type; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| private $blockId; | ||
|
|
||
| public function __construct(?string $type) | ||
| { | ||
| $this->setType($type); | ||
| } | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getType(): string | ||
| { | ||
| return $this->type; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $type | ||
| * | ||
| * @return $this | ||
| */ | ||
| public function setType(string $type): self | ||
| { | ||
| $this->type = $type; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * Convert this block to its array representation. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| $data = [ | ||
| 'type' => $this->type, | ||
| 'block_id' => $this->blockId | ||
| ]; | ||
|
|
||
| return $this->removeNulls($data); | ||
| } | ||
|
|
||
| /** | ||
| * @param string $blockId | ||
| */ | ||
| public function setBlockId(string $blockId): self | ||
| { | ||
| $this->blockId = $blockId; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getBlockId(): string | ||
| { | ||
| return $this->blockId; | ||
| } | ||
|
|
||
| protected function removeNulls(array $data): array | ||
| { | ||
| foreach($data as $k => $v) { | ||
| if ($v === null || (is_array($v) && count($v) === 0)) { | ||
| unset($data[$k]); | ||
| } | ||
| } | ||
| return $data; | ||
| } | ||
| } | ||
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,135 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the Nexylan packages. | ||
| * | ||
| * (c) Nexylan SAS <contact@nexylan.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Nexy\Slack; | ||
|
|
||
| /** | ||
| * @author Sullivan Senechal <soullivaneuh@gmail.com> | ||
| * @author Mikey McLellan <mikey@mclellan.org.nz> | ||
| */ | ||
| final class ButtonBlock extends SectionBlock | ||
| { | ||
| const STYLE_PRIMARY = 'primary'; | ||
| const STYLE_DANGER = 'danger'; | ||
|
|
||
| /** @var string */ | ||
| private $url; | ||
|
|
||
| /** @var string */ | ||
| private $value; | ||
|
|
||
| /** @var string */ | ||
| private $actionId; | ||
|
|
||
| /** @var string */ | ||
| private $style; | ||
|
|
||
| public function __construct() | ||
| { | ||
| parent::__construct('button'); | ||
| } | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getUrl(): string | ||
| { | ||
| return $this->url; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $url | ||
| */ | ||
| public function setUrl(string $url): self | ||
| { | ||
| $this->url = $url; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getValue(): string | ||
| { | ||
| return $this->value; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $value | ||
| */ | ||
| public function setValue(string $value): self | ||
| { | ||
| $this->value = $value; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $actionId | ||
| */ | ||
| public function setActionId(string $actionId): self | ||
| { | ||
| $this->actionId = $actionId; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getActionId(): string | ||
| { | ||
| return $this->actionId; | ||
| } | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getStyle(): string | ||
| { | ||
| return $this->style; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $style | ||
| */ | ||
| public function setStyle(string $style): self | ||
| { | ||
| $this->style = $style; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function setMarkdown(string $string): SectionBlock | ||
| { | ||
| throw new \InvalidArgumentException('ButtonBlock must use plain_text'); | ||
| } | ||
|
|
||
| /** | ||
| * Convert this block to its array representation. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| $data = [ | ||
| 'url' => $this->url, | ||
| 'value' => $this->value, | ||
| 'action_id' => $this->actionId, | ||
| 'style' => $this->style | ||
| ]; | ||
|
|
||
| return array_merge(parent::toArray(), $this->removeNulls($data)); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Missing PHPDoc
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.
Not necessary, the strict typing is enough.
Except if you want to add detail about
$typedescription.