Skip to content

Commit 3184be0

Browse files
feat: add send button action and reply functionality
1 parent 53e6887 commit 3184be0

File tree

2 files changed

+77
-21
lines changed

2 files changed

+77
-21
lines changed

README.md

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,36 +173,69 @@ echo $whatsapp->sendDocument($to, $url, $mimetype, $fileName);
173173
```
174174

175175

176-
### Send Button
176+
### Send Button Action
177177
```php
178178
$body = [
179-
"to" => "556696852025",
180-
"title" => "Are you enjoying ?",
181-
"footer" => "choose an option",
182-
"buttons" => [
183-
[
184-
"type"=> "quick_reply",
185-
"id" => "click_1",
186-
"text" => "Yes"
187-
],
179+
'to' => '14375223417',
180+
'header' => [
181+
'title' => 'Example Title',
182+
'hasMediaAttachment' => true,
183+
'imageMessage' => [
184+
'url' => 'https://raphaelvserafim.com/og-image.png'
185+
]
186+
],
187+
'text' => 'This is a test',
188+
'footer' => 'choose an option',
189+
'buttons' => [
188190
[
189-
"type"=> "cta_copy",
190-
"copy_code" => "000000000000",
191-
"text" => "Copy barcode"
191+
'type' => 'cta_copy',
192+
'copy_code' => '1234567890',
193+
'text' => 'Copy barcode'
192194
],
193195
[
194-
"type"=> "cta_url",
195-
"url" => "https://api-wa.me",
196-
"text" => "Access the website"
196+
'type' => 'cta_url',
197+
'url' => 'https://api-wa.me',
198+
'text' => 'Access the website'
197199
],
198200
[
199-
"type"=> "send_location"
201+
'type' => 'cta_call',
202+
'phone_number' => '+14375223417',
203+
'text' => 'Call us'
200204
]
201-
]
202-
];
205+
]
206+
];
203207
echo $whatsapp->sendButton($body);
204208
```
205209

210+
### Send Button Reply
211+
```php
212+
{
213+
"to": "14375223417",
214+
"header": {
215+
"title": "Example Header",
216+
"hasMediaAttachment": true,
217+
"imageMessage": {
218+
"url": "https://raphaelvserafim.com/og-image.png"
219+
}
220+
},
221+
"text": "This is a test",
222+
"footer": "choose an option",
223+
"buttons": [
224+
{
225+
"type": "quick_reply",
226+
"id": "uniqId1",
227+
"text": "Yes"
228+
},
229+
{
230+
"type": "quick_reply",
231+
"id": "uniqId2",
232+
"text": "No"
233+
}
234+
]
235+
}
236+
echo $whatsapp->sendButtonReply($body);
237+
```
238+
206239

207240
### Send List
208241
```php

src/WhatsApp.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ public function sendVideo(string $to, string $url, string $caption)
475475
return $this->request();
476476
}
477477

478-
public function sendDocument(string $to, string $url, string $caption, string $mimetype, $fileName)
478+
public function sendDocument(string $to, string $url, string $caption, string $mimetype, $fileName)
479479
{
480480
// Define o corpo da requisição para enviar uma mensagem de mídia.
481481
$this->parth = "/{$this->key}/message/document";
@@ -501,14 +501,37 @@ public function sendDocument(string $to, string $url, string $caption, string $m
501501
*/
502502
public function sendButton($body)
503503
{
504+
505+
// Define o corpo da requisição para enviar uma mensagem com botões.
506+
$this->parth = "/{$this->key}/message/button_action";
507+
$this->method = "POST";
508+
$this->body = json_encode($body);
509+
// Executa a requisição e retorna o resultado.
510+
return $this->request();
511+
}
512+
513+
514+
/**
515+
* Envia uma resposta a um botão pressionado por um destinatário.
516+
*
517+
* @param mixed $body Os dados a serem enviados no corpo da requisição.
518+
*
519+
* @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha.
520+
* @throws \RuntimeException Se ocorrer um erro durante a requisição cURL.
521+
*/
522+
public function sendButtonReply($body)
523+
{
524+
504525
// Define o corpo da requisição para enviar uma mensagem com botões.
505-
$this->parth = "/{$this->key}/message/button";
526+
$this->parth = "/{$this->key}/message/button_reply";
506527
$this->method = "POST";
507528
$this->body = json_encode($body);
508529
// Executa a requisição e retorna o resultado.
509530
return $this->request();
510531
}
511532

533+
534+
512535
/**
513536
* Envia uma mensagem com botões de modelo para um destinatário.
514537
*

0 commit comments

Comments
 (0)