diff --git a/src/Messages/Client.php b/src/Messages/Client.php index 1446f4cb..804b65f6 100644 --- a/src/Messages/Client.php +++ b/src/Messages/Client.php @@ -11,6 +11,7 @@ class Client implements APIClient { public const RCS_STATUS_REVOKED = 'revoked'; + public const WHATSAPP_STATUS_READ = 'read'; public function __construct(protected APIResource $api) { @@ -45,7 +46,15 @@ public function updateRcsStatus(string $messageUuid, string $status): bool } catch (\Exception $e) { return false; } - return false; + } + + /** + * This method is just a wrapper for updateRcsStatus to make it semantically + * correct for other uses such as WhatsApp messages + */ + public function markAsStatus(string $messageUuid, string $status): bool + { + return $this->updateRcsStatus($messageUuid, $status); } protected function stripLeadingPlus(string $phoneNumber): string diff --git a/test/Messages/ClientTest.php b/test/Messages/ClientTest.php index 390d4214..5b4889bc 100644 --- a/test/Messages/ClientTest.php +++ b/test/Messages/ClientTest.php @@ -1235,6 +1235,30 @@ public function testCanUpdateRcsMessage(): void $this->messageClient->updateRcsStatus('6ce72c29-e454-442a-94f2-47a1cadba45f', MessagesClient::RCS_STATUS_REVOKED); } + public function testCanUpdateWhatsAppStatus(): void + { + $geoSpecificClient = clone $this->messageClient; + $geoSpecificClient->getAPIResource()->setBaseUrl('https://api-us.nexmo.com/v1'); + + $this->vonageClient->send(Argument::that(function (Request $request) { + $this->assertEquals( + 'Bearer ', + mb_substr($request->getHeaders()['Authorization'][0], 0, 7) + ); + $uri = $request->getUri(); + $uriString = $uri->__toString(); + $this->assertEquals('https://api-us.nexmo.com/v1/messages/6ce72c29-e454-442a-94f2-47a1cadba45f', + $uriString); + + $this->assertRequestJsonBodyContains('status', 'read', $request); + $this->assertEquals('PATCH', $request->getMethod()); + + return true; + }))->willReturn($this->getResponse('rcs-update-success')); + + $geoSpecificClient->markAsStatus('6ce72c29-e454-442a-94f2-47a1cadba45f', MessagesClient::WHATSAPP_STATUS_READ); + } + public function stickerTypeProvider(): array { return [