#126 - fix
This commit is contained in:
		@@ -17,11 +17,12 @@ class SlackApiChannel
 | 
			
		||||
        $url = "{$baseUrl}/chat.postMessage";
 | 
			
		||||
        $channel = $notifiable->routeNotificationFor("slack", $notification);
 | 
			
		||||
 | 
			
		||||
        $message = $notification->toSlack($notifiable);
 | 
			
		||||
 | 
			
		||||
        return Http::withToken($this->getClientToken())
 | 
			
		||||
            ->post($url, [
 | 
			
		||||
            ->post($url, array_merge($message->getPayload(), [
 | 
			
		||||
                "channel" => $channel,
 | 
			
		||||
                "text" => $notification->toSlack($notifiable),
 | 
			
		||||
            ]);
 | 
			
		||||
            ]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function getClientToken(): string
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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(),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Toby\Infrastructure\Slack\Elements;
 | 
			
		||||
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
use Toby\Eloquent\Models\VacationRequest;
 | 
			
		||||
 | 
			
		||||
class VacationRequestsAttachment extends ListAttachment
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(Collection $vacationRequests)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct();
 | 
			
		||||
 | 
			
		||||
        $this
 | 
			
		||||
            ->setColor("#527aba")
 | 
			
		||||
            ->setItems($this->mapVacationRequests($vacationRequests));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function mapVacationRequests(Collection $vacationRequests): Collection
 | 
			
		||||
    {
 | 
			
		||||
        return $vacationRequests->map(function (VacationRequest $request): string {
 | 
			
		||||
            $url = route("vacation.requests.show", ["vacationRequest" => $request->id]);
 | 
			
		||||
 | 
			
		||||
            $date = $request->from->equalTo($request->to)
 | 
			
		||||
                ? "{$request->from->toDisplayString()}"
 | 
			
		||||
                : "{$request->from->toDisplayString()} - {$request->to->toDisplayString()}";
 | 
			
		||||
 | 
			
		||||
            return "<{$url}|Wniosek nr {$request->name}> użytkownika {$request->user->profile->full_name} ({$date})";
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user