diff --git a/src/Message/Media/MediaType.php b/src/Message/Media/MediaType.php new file mode 100644 index 0000000..2b83cd7 --- /dev/null +++ b/src/Message/Media/MediaType.php @@ -0,0 +1,30 @@ +sha256 = $sha256; $this->filename = $filename; $this->caption = $caption; + $this->type = $type; } public function imageId(): string @@ -57,4 +63,9 @@ public function caption(): string { return $this->caption; } + + public function type(): MediaType + { + return $this->type; + } } diff --git a/src/WebHook/Notification/MessageNotificationFactory.php b/src/WebHook/Notification/MessageNotificationFactory.php index 8db65cf..fe302f2 100644 --- a/src/WebHook/Notification/MessageNotificationFactory.php +++ b/src/WebHook/Notification/MessageNotificationFactory.php @@ -2,6 +2,8 @@ namespace Netflie\WhatsAppCloudApi\WebHook\Notification; +use Netflie\WhatsAppCloudApi\Message\Media\MediaType; + class MessageNotificationFactory { public function buildFromPayload(array $metadata, array $message, array $contact): MessageNotification @@ -43,7 +45,8 @@ private function buildMessageNotification(array $metadata, array $message): Mess $message[$message['type']]['sha256'], $message[$message['type']]['filename'] ?? '', $message[$message['type']]['caption'] ?? '', - $message['timestamp'] + $message['timestamp'], + new MediaType($message['type']) ); case 'location': return new Location( diff --git a/tests/Unit/WebHook/NotificationFactoryTest.php b/tests/Unit/WebHook/NotificationFactoryTest.php index b21e935..2fec1d2 100644 --- a/tests/Unit/WebHook/NotificationFactoryTest.php +++ b/tests/Unit/WebHook/NotificationFactoryTest.php @@ -2,6 +2,7 @@ namespace Netflie\WhatsAppCloudApi\Tests\Unit\WebHook; +use Netflie\WhatsAppCloudApi\Message\Media\MediaType; use Netflie\WhatsAppCloudApi\WebHook\Notification; use Netflie\WhatsAppCloudApi\WebHook\NotificationFactory; use PHPUnit\Framework\TestCase; @@ -331,6 +332,7 @@ public function test_build_from_payload_can_build_an_image_notification() $this->assertEquals('IMAGE_HASH', $notification->sha256()); $this->assertEquals('image/jpeg', $notification->mimeType()); $this->assertEquals('CAPTION_TEXT', $notification->caption()); + $this->assertEquals(MediaType::IMAGE(), $notification->type()); } public function test_build_from_payload_can_build_an_document_notification() @@ -379,6 +381,7 @@ public function test_build_from_payload_can_build_an_document_notification() $this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $notification->mimeType()); $this->assertEquals('CAPTION_TEXT', $notification->caption()); $this->assertEquals('FILENAME', $notification->filename()); + $this->assertEquals(MediaType::DOCUMENT(), $notification->type()); } public function test_build_from_payload_can_build_a_sticker_notification() @@ -431,6 +434,7 @@ public function test_build_from_payload_can_build_a_sticker_notification() $this->assertEquals('STICKER_ID', $notification->imageId()); $this->assertEquals('STICKER_HASH', $notification->sha256()); $this->assertEquals('image/webp', $notification->mimeType()); + $this->assertEquals(MediaType::STICKER(), $notification->type()); } public function test_build_from_payload_can_build_an_unknown_notification()