Skip to content

Commit

Permalink
docs(slack): Update Slack Message class methods and properties
Browse files Browse the repository at this point in the history
- Updated methods and properties in the Slack Message class:
  - Added 'blocks' method
  - Added 'asUser' method
  - Added 'linkNames' method
  - Added 'metadata' method
  - Added 'mrkdwn' method
  - Added 'parse' method
  - Added 'replyBroadcast' method
  - Added 'threadTs' method
  - Added 'unfurlMedia' method
  - Removed 'attachments' method from the 'defined' property
  - Removed 'unfurlLinks' method from the 'options' property
  - Removed 'unfurl_links' and 'attachments' from the 'allowedTypes' property
  - Updated the README.md file with additional Slack API links
  • Loading branch information
guanguans committed Mar 1, 2024
1 parent b03d3b4 commit 3dcb658
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
48 changes: 33 additions & 15 deletions src/Slack/Messages/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @method self text($text)
* @method self channel($channel)
* @method self username($username)
* @method self attachments(array $attachments)
* @method self blocks(array $blocks)
* @method self text($text)
* @method self asUser(bool $asUser)
* @method self iconEmoji($iconEmoji)
* @method self iconUrl($iconUrl)
* @method self linkNames(bool $linkNames)
* @method self metadata($metadata)
* @method self mrkdwn(bool $mrkdwn)
* @method self parse($parse)
* @method self replyBroadcast(bool $replyBroadcast)
* @method self threadTs($threadTs)
* @method self unfurlLinks(bool $unfurlLinks)
* @method self attachments(array $attachments)
* @method self unfurlMedia(bool $unfurlMedia)
* @method self username($username)
*/
class Message extends \Guanguans\Notify\Foundation\Message
{
Expand All @@ -33,23 +42,38 @@ class Message extends \Guanguans\Notify\Foundation\Message
use AsPost;

protected array $defined = [
'text',
'channel',
'username',
'attachments',
'blocks',
'text',
'as_user',
'icon_emoji',
'icon_url',
'link_names',
'metadata',
'mrkdwn',
'parse',
'reply_broadcast',
'thread_ts',
'unfurl_links',
'attachments',
'unfurl_media',
'username',
];

protected array $options = [
'unfurl_links' => false,
'attachments' => [],
'blocks' => [],
];

protected array $allowedTypes = [
'unfurl_links' => 'bool',
'attachments' => 'array',
'blocks' => 'array',
'as_user' => 'bool',
'link_names' => 'bool',
'mrkdwn' => 'bool',
'reply_broadcast' => 'bool',
'unfurl_links' => 'bool',
'unfurl_media' => 'bool',
];

public function addAttachment(array $attachment): self
Expand All @@ -70,11 +94,5 @@ static function (OptionsResolver $optionsResolver): void {
return $this;
}

protected function configureOptionsResolver(OptionsResolver $optionsResolver): void
{
$optionsResolver->setNormalizer('attachments', static fn (
OptionsResolver $optionsResolver,
array $value
): array => isset($value[0]) ? $value : [$value]);
}
protected function configureOptionsResolver(OptionsResolver $optionsResolver): void {}
}
2 changes: 2 additions & 0 deletions src/Slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
## Related links

* [https://api.slack.com/messaging/webhooks](https://api.slack.com/messaging/webhooks)
* [https://api.slack.com/methods/chat.postMessage](https://api.slack.com/methods/chat.postMessage)
* [https://app.slack.com/client](https://app.slack.com/client)

0 comments on commit 3dcb658

Please sign in to comment.