Skip to content

Commit 0e2cd6c

Browse files
feat: send media
1 parent 15d3708 commit 0e2cd6c

File tree

2 files changed

+80
-23
lines changed

2 files changed

+80
-23
lines changed

README.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,7 @@ $url =''; // url image
120120
echo $whatsapp->updateProfilePicture($url);
121121
```
122122

123-
### Download Media
124-
```php
125-
$body = [
126-
"mediaKey" => "",
127-
"directPath" => "",
128-
"url" => "",
129-
] ;
130-
$type = "image";// video | audio| image | sticker | document|
131-
echo $whatsapp->downloadMediaMessage($type, $body);
132-
```
133-
123+
134124
## Send Message
135125

136126
### send Presence
@@ -154,9 +144,34 @@ echo $whatsapp->sendText($to, $text);
154144
echo $whatsapp->sendAudio($to, $url);
155145
```
156146

157-
### send Media
147+
### send Image
148+
```php
149+
$to = '556696852025'; // if it's a group, use full id ex: [email protected]
150+
$url = '';
151+
$caption = '';
152+
echo $whatsapp->sendImage($to, $url);
153+
```
158154

155+
### send Video
156+
```php
157+
$to = '556696852025'; // if it's a group, use full id ex: [email protected]
158+
$url = '';
159+
$caption = '';
160+
echo $whatsapp->sendVideo($to, $url);
161+
```
162+
163+
159164

165+
### send Document
166+
```php
167+
$to = '556696852025'; // if it's a group, use full id ex: [email protected]
168+
$url = '';
169+
$caption = '';
170+
$mimetype = 'application/pdf'; // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
171+
$fileName='';
172+
echo $whatsapp->sendDocument($to, $url, $mimetype, $fileName);
173+
```
174+
160175

161176
### Send Button
162177
```php

src/WhatsApp.php

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Api\Wame;
34

45
use stdClass;
@@ -420,23 +421,65 @@ public function sendTextWithMentions(string $groupId, string $text, array $menti
420421
public function sendMedia(string $to, string $url, string $type, string $caption, string $mimeType = '', bool $ptt = false)
421422
{
422423
// Define o corpo da requisição para enviar uma mensagem de mídia.
423-
$this->parth = "/message/media?key={$this->key}";
424+
// $this->parth = "/message/media?key={$this->key}";
425+
// $this->method = "POST";
426+
// $this->body = json_encode([
427+
// "data" => [
428+
// "to" => $to,
429+
// "url" => $url,
430+
// "type" => $type,
431+
// "caption" => $caption,
432+
// "mimeType" => $mimeType,
433+
// "ptt" => $ptt
434+
// ]
435+
// ]);
436+
// Executa a requisição e retorna o resultado.
437+
//return $this->request();
438+
}
439+
440+
441+
public function sendImage(string $to, string $url, string $caption)
442+
{
443+
// Define o corpo da requisição para enviar uma mensagem de mídia.
444+
$this->parth = "/{$this->key}/message/image";
424445
$this->method = "POST";
425446
$this->body = json_encode([
426-
"data" => [
427-
"to" => $to,
428-
"url" => $url,
429-
"type" => $type,
430-
"caption" => $caption,
431-
"mimeType" => $mimeType,
432-
"ptt" => $ptt
433-
]
447+
"to" => $to,
448+
"url" => $url,
449+
"caption" => $caption,
450+
]);
451+
return $this->request();
452+
}
453+
454+
public function sendVideo(string $to, string $url, string $caption)
455+
{
456+
// Define o corpo da requisição para enviar uma mensagem de mídia.
457+
$this->parth = "/{$this->key}/message/video";
458+
$this->method = "POST";
459+
$this->body = json_encode([
460+
"to" => $to,
461+
"url" => $url,
462+
"caption" => $caption,
434463
]);
464+
return $this->request();
465+
}
435466

436-
// Executa a requisição e retorna o resultado.
467+
public function sendDocument(string $to, string $url, string $caption, string $mimetype, $fileName)
468+
{
469+
// Define o corpo da requisição para enviar uma mensagem de mídia.
470+
$this->parth = "/{$this->key}/message/document";
471+
$this->method = "POST";
472+
$this->body = json_encode([
473+
"to" => $to,
474+
"url" => $url,
475+
"caption" => $caption,
476+
"mimetype" => $mimetype,
477+
"fileName" => $fileName,
478+
]);
437479
return $this->request();
438480
}
439481

482+
440483
/**
441484
* Envia uma mensagem com botões para um destinatário.
442485
*
@@ -926,5 +969,4 @@ public function constructWebhook()
926969
}
927970
}
928971
}
929-
930972
}

0 commit comments

Comments
 (0)