Skip to content

Commit 53e6887

Browse files
feat: mark message read
1 parent e029644 commit 53e6887

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/WhatsApp.php

+29-18
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,28 @@ public function __construct(array $data = [])
2626

2727
private function request()
2828
{
29-
$this->header[] = 'Content-Type: application/json';
30-
$ch = curl_init();
31-
curl_setopt($ch, CURLOPT_URL, $this->server . $this->parth);
32-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
33-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
34-
if ($this->method === 'POST' || $this->method === 'PUT') {
35-
curl_setopt($ch, CURLOPT_POST, true);
36-
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->body);
37-
}
38-
39-
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
40-
$result = curl_exec($ch);
41-
42-
if (curl_errno($ch)) {
43-
$errorMessage = curl_error($ch);
29+
try {
30+
$this->header[] = 'Content-Type: application/json';
31+
$ch = curl_init();
32+
curl_setopt($ch, CURLOPT_URL, $this->server . $this->parth);
33+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
34+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
35+
if ($this->method === 'POST' || $this->method === 'PUT') {
36+
curl_setopt($ch, CURLOPT_POST, true);
37+
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->body);
38+
}
39+
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
40+
$result = curl_exec($ch);
41+
if (curl_errno($ch)) {
42+
$errorMessage = curl_error($ch);
43+
curl_close($ch);
44+
throw new \RuntimeException("cURL Error: $errorMessage");
45+
}
4446
curl_close($ch);
45-
throw new \RuntimeException("cURL Error: $errorMessage");
47+
return $result;
48+
} catch (\Throwable $th) {
49+
return null;
4650
}
47-
curl_close($ch);
48-
return $result;
4951
}
5052

5153
/**
@@ -63,6 +65,15 @@ public function connect()
6365
return $this->request();
6466
}
6567

68+
public function updateSaveMediaMarkMessageRead(bool $markMessageRead, bool $saveMedia)
69+
{
70+
$markMessageReadValue = json_encode($markMessageRead);
71+
$saveMediaValue = json_encode($saveMedia);
72+
$this->parth = "/{$this->key}/instance/?markMessageRead={$markMessageReadValue}&saveMedia={$saveMediaValue}";
73+
$this->method = "PATCH";
74+
return $this->request();
75+
}
76+
6677
/**
6778
* Obtém informações sobre a instância atual.
6879
*

0 commit comments

Comments
 (0)