Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ConversationsVisitOutboundMessenger
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 send
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Visits\Infrastructure\Messaging;
6
7use ImovelZapAi\Conversations\Application\Actions\SendOutboundMessageAction;
8use ImovelZapAi\Conversations\Domain\Enums\MessageDeliveryStatus;
9use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\ContactModel;
10use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\ConversationModel;
11use ImovelZapAi\Visits\Application\Ports\VisitOutboundMessengerInterface;
12use RuntimeException;
13
14final class ConversationsVisitOutboundMessenger implements VisitOutboundMessengerInterface
15{
16    public function __construct(
17        private readonly SendOutboundMessageAction $sendOutbound,
18    ) {}
19
20    public function send(
21        string $tenantId,
22        ContactModel $contact,
23        string $body,
24        ?ConversationModel $conversation = null,
25    ): void {
26        $message = $this->sendOutbound->execute($tenantId, $contact, $body, $conversation);
27
28        if ($message->delivery_status === MessageDeliveryStatus::Failed) {
29            throw new RuntimeException($message->error_message ?? 'Falha ao enviar WhatsApp.');
30        }
31    }
32}