-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\Slack; | ||
|
||
class Client extends \Guanguans\Notify\Foundation\Client | ||
{ | ||
} |
This file contains 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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\Slack; | ||
|
||
use Guanguans\Notify\Foundation\NullCredential; | ||
|
||
class Credential extends NullCredential | ||
{ | ||
} |
This file contains 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,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\Slack\Messages; | ||
|
||
use Guanguans\Notify\Foundation\Concerns\AsJson; | ||
use Guanguans\Notify\Foundation\Concerns\AsPost; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class Message extends \Guanguans\Notify\Foundation\Message | ||
{ | ||
use AsPost; | ||
use AsJson; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $defined = [ | ||
'text', | ||
'channel', | ||
'username', | ||
'icon_emoji', | ||
'icon_url', | ||
'unfurl_links', | ||
'attachments', | ||
]; | ||
|
||
/** | ||
* @var array<string, mixed> | ||
*/ | ||
protected array $options = [ | ||
'unfurl_links' => false, | ||
'attachments' => [], | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $allowedTypes = [ | ||
'unfurl_links' => 'bool', | ||
'attachments' => 'array', | ||
]; | ||
|
||
protected function configureOptionsResolver(OptionsResolver $optionsResolver): OptionsResolver | ||
{ | ||
return tap(parent::configureOptionsResolver($optionsResolver), static function (OptionsResolver $resolver): void { | ||
$resolver->setNormalizer('attachments', static function (OptionsResolver $optionsResolver, array $value): array { | ||
return isset($value[0]) ? $value : [$value]; | ||
}); | ||
}); | ||
} | ||
|
||
public function setAttachments(array $attachments): self | ||
{ | ||
return $this->addAttachments($attachments); | ||
} | ||
|
||
public function addAttachments(array $attachments): self | ||
{ | ||
foreach ($attachments as $attachment) { | ||
$this->addAttachment($attachment); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function setAttachment(array $attachment): self | ||
{ | ||
return $this->addAttachment($attachment); | ||
} | ||
|
||
public function addAttachment(array $attachment): self | ||
{ | ||
$this->options['attachments'][] = configure_options($attachment, static function (OptionsResolver $optionsResolver): void { | ||
$optionsResolver->setDefined([ | ||
'fallback', | ||
'text', | ||
'pretext', | ||
'color', | ||
'fields', | ||
]); | ||
}); | ||
|
||
return $this; | ||
} | ||
|
||
public function httpUri() | ||
{ | ||
return 'webhook_url'; | ||
} | ||
} |