Skip to content

Commit b296283

Browse files
authored
add method for whatsapp updating (#524)
1 parent e3d6114 commit b296283

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/Messages/Client.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class Client implements APIClient
1212
{
1313
public const RCS_STATUS_REVOKED = 'revoked';
14+
public const WHATSAPP_STATUS_READ = 'read';
1415

1516
public function __construct(protected APIResource $api)
1617
{
@@ -45,7 +46,15 @@ public function updateRcsStatus(string $messageUuid, string $status): bool
4546
} catch (\Exception $e) {
4647
return false;
4748
}
48-
return false;
49+
}
50+
51+
/**
52+
* This method is just a wrapper for updateRcsStatus to make it semantically
53+
* correct for other uses such as WhatsApp messages
54+
*/
55+
public function markAsStatus(string $messageUuid, string $status): bool
56+
{
57+
return $this->updateRcsStatus($messageUuid, $status);
4958
}
5059

5160
protected function stripLeadingPlus(string $phoneNumber): string

test/Messages/ClientTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,30 @@ public function testCanUpdateRcsMessage(): void
12351235
$this->messageClient->updateRcsStatus('6ce72c29-e454-442a-94f2-47a1cadba45f', MessagesClient::RCS_STATUS_REVOKED);
12361236
}
12371237

1238+
public function testCanUpdateWhatsAppStatus(): void
1239+
{
1240+
$geoSpecificClient = clone $this->messageClient;
1241+
$geoSpecificClient->getAPIResource()->setBaseUrl('https://api-us.nexmo.com/v1');
1242+
1243+
$this->vonageClient->send(Argument::that(function (Request $request) {
1244+
$this->assertEquals(
1245+
'Bearer ',
1246+
mb_substr($request->getHeaders()['Authorization'][0], 0, 7)
1247+
);
1248+
$uri = $request->getUri();
1249+
$uriString = $uri->__toString();
1250+
$this->assertEquals('https://api-us.nexmo.com/v1/messages/6ce72c29-e454-442a-94f2-47a1cadba45f',
1251+
$uriString);
1252+
1253+
$this->assertRequestJsonBodyContains('status', 'read', $request);
1254+
$this->assertEquals('PATCH', $request->getMethod());
1255+
1256+
return true;
1257+
}))->willReturn($this->getResponse('rcs-update-success'));
1258+
1259+
$geoSpecificClient->markAsStatus('6ce72c29-e454-442a-94f2-47a1cadba45f', MessagesClient::WHATSAPP_STATUS_READ);
1260+
}
1261+
12381262
public function stickerTypeProvider(): array
12391263
{
12401264
return [

0 commit comments

Comments
 (0)