Skip to content

Commit

Permalink
add method for whatsapp updating (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK authored Nov 11, 2024
1 parent e3d6114 commit b296283
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Messages/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/Messages/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit b296283

Please sign in to comment.