* #126 - vacation request reminders * #126 - fix workdays * #126 - changes * #126 - cs fix * #5 - bump codestyle * #126 - fix * #126 - fix * #126 - fix * #126 - fix * #126 - tests * #126 - fix * #126 - fix * #126 - fix seeders * #126 - fix * #126 - tests Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
53
app/Infrastructure/Slack/Elements/SlackMessage.php
Normal file
53
app/Infrastructure/Slack/Elements/SlackMessage.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Slack\Elements;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class SlackMessage
|
||||
{
|
||||
protected string $text = "";
|
||||
protected Collection $attachments;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->attachments = new Collection();
|
||||
}
|
||||
|
||||
public function text(string $text): static
|
||||
{
|
||||
$this->text = $text;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withAttachment(Attachment $attachment): static
|
||||
{
|
||||
$this->attachments->push($attachment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withAttachments(Collection $attachments): static
|
||||
{
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->withAttachment($attachment);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPayload(): array
|
||||
{
|
||||
return [
|
||||
"text" => $this->text,
|
||||
"link_names" => true,
|
||||
"unfurl_links" => true,
|
||||
"unfurl_media" => true,
|
||||
"mrkdwn" => true,
|
||||
"attachments" => $this->attachments->toArray(),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user