Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ConversationsVisitOutboundMessenger | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| send | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Visits\Infrastructure\Messaging; |
| 6 | |
| 7 | use ImovelZapAi\Conversations\Application\Actions\SendOutboundMessageAction; |
| 8 | use ImovelZapAi\Conversations\Domain\Enums\MessageDeliveryStatus; |
| 9 | use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\ContactModel; |
| 10 | use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\ConversationModel; |
| 11 | use ImovelZapAi\Visits\Application\Ports\VisitOutboundMessengerInterface; |
| 12 | use RuntimeException; |
| 13 | |
| 14 | final 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 | } |