Skip to content

Commit c6d9f85

Browse files
committed
added whatsapp messaging and media management
1 parent a8f2ae3 commit c6d9f85

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

src/Plugins/WhatsApp/Traits/SendsMessages.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ public function sendMessage($type, AbstractMessage $message, $recipient) {
2525
return $this->send(['type' => $type, 'to' => $recipient, $type => $message->toArray()]);
2626
}
2727

28+
/**
29+
* Mark message as read
30+
*
31+
* @param $message_id
32+
* @return mixed
33+
*/
34+
public function markRead($message_id) {
35+
$this->checkForPhoneNumberId();
36+
37+
$this->checkForAccessToken();
38+
39+
return $this->httpClient->post($this->messagingFullUrl(), [
40+
'json' => [
41+
"messaging_product" => "whatsapp",
42+
"status" => "read",
43+
"message_id" => $message_id
44+
]
45+
]);
46+
}
47+
2848
/**
2949
* send message
3050
*

src/Plugins/WhatsApp/WhatsAppPlugin.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,31 +160,31 @@ private function iterateOverObjectsAndEmitEvents()
160160
$this->bionic->emit('message', [$this, $contacts, $message]);
161161

162162
if ($text = $message->getText())
163-
$this->bionic->emit('message.text', [$this, $contacts, $text]);
163+
$this->bionic->emit('message.text', [$this, $contacts, $message, $text]);
164164

165165
if ($location = $message->getLocation())
166-
$this->bionic->emit('message.location', [$this, $contacts, $location]);
166+
$this->bionic->emit('message.location', [$this, $contacts, $message, $location]);
167167

168168
if ($sent_contacts = $message->getContacts())
169-
$this->bionic->emit('message.contacts', [$this, $contacts, $sent_contacts]);
169+
$this->bionic->emit('message.contacts', [$this, $contacts, $message, $sent_contacts]);
170170

171171
if ($errors = $message->getErrors())
172-
$this->bionic->emit('message.errors', [$this, $contacts, $errors]);
172+
$this->bionic->emit('message.errors', [$this, $contacts, $message, $errors]);
173173

174174
if ($image = $message->getImage())
175-
$this->bionic->emit('message.image', [$this, $contacts, $image]);
175+
$this->bionic->emit('message.image', [$this, $contacts, $message, $image]);
176176

177177
if ($document = $message->getDocument())
178-
$this->bionic->emit('message.document', [$this, $contacts, $document]);
178+
$this->bionic->emit('message.document', [$this, $contacts, $message, $document]);
179179

180180
if ($voice = $message->getVoice())
181-
$this->bionic->emit('message.voice', [$this, $contacts, $voice]);
181+
$this->bionic->emit('message.voice', [$this, $contacts, $message, $voice]);
182182

183183
if ($sticker = $message->getSticker())
184-
$this->bionic->emit('message.sticker', [$this, $contacts, $sticker]);
184+
$this->bionic->emit('message.sticker', [$this, $contacts, $message, $sticker]);
185185

186186
if ($system = $message->getSystem())
187-
$this->bionic->emit('message.system', [$this, $contacts, $system]);
187+
$this->bionic->emit('message.system', [$this, $contacts, $message, $system]);
188188
}
189189
}
190190

0 commit comments

Comments
 (0)