Skip to content

Commit 719c7cf

Browse files
authored
Merge branch 'main' into main
2 parents 157e13c + 0c3acae commit 719c7cf

18 files changed

+701
-6
lines changed

README.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ $whatsapp_cloud_api->sendCtaUrl(
257257

258258
$body = 'Hello! Thanks for your interest. Ordering is easy. Just visit our catalog and add items you\'d like to purchase.';
259259
$footer = 'Best grocery deals on WhatsApp!';
260-
$sku_thumbnail = '<product-sku-id>'; // product sku id to use as header thumbnail
260+
$sku_thumbnail = '<product-sku-id>'; // product sku id to use as header thumbnail
261261

262262
$whatsapp_cloud_api->sendCatalog(
263263
'<destination-phone-number>',
@@ -297,6 +297,67 @@ $whatsapp_cloud_api->sendButton(
297297
);
298298
```
299299

300+
### Send Multi Product Message
301+
```php
302+
<?php
303+
304+
use Netflie\WhatsAppCloudApi\WhatsAppCloudApi;
305+
use Netflie\WhatsAppCloudApi\Message\MultiProduct\Row;
306+
use Netflie\WhatsAppCloudApi\Message\MultiProduct\Section;
307+
use Netflie\WhatsAppCloudApi\Message\MultiProduct\Action;
308+
309+
$rows_section_1 = [
310+
new Row('<product-sku-id>'),
311+
new Row('<product-sku-id>'),
312+
// etc
313+
];
314+
315+
$rows_section_2 = [
316+
new Row('<product-sku-id>'),
317+
new Row('<product-sku-id>'),
318+
new Row('<product-sku-id>'),
319+
// etc
320+
];
321+
322+
$sections = [
323+
new Section('Section 1', $rows_section_1),
324+
new Section('Section 2', $rows_section_2),
325+
];
326+
327+
$action = new Action($sections);
328+
$catalog_id = '<catalog-id>';
329+
$header = 'Grocery Collections';
330+
$body = 'Hello! Thanks for your interest. Here\'s what we can offer you under our grocery collection. Thank you for shopping with us.';
331+
$footer = 'Subject to T&C';
332+
333+
$whatsapp_cloud_api->sendMultiProduct(
334+
'<destination-phone-number>',
335+
$catalog_id,
336+
$action,
337+
$header,
338+
$body,
339+
$footer // optional
340+
);
341+
```
342+
343+
### Send Single Product Message
344+
```php
345+
<?php
346+
347+
$catalog_id = '<catalog-id>';
348+
$sku_id = '<product-sku-id>';
349+
$body = 'Hello! Here\'s your requested product. Thanks for shopping with us.';
350+
$footer = 'Subject to T&C';
351+
352+
$whatsapp_cloud_api->sendSingleProduct(
353+
'<destination-phone-number>',
354+
$catalog_id,
355+
$sku_id,
356+
$body, // body: optional
357+
$footer // footer: optional
358+
);
359+
```
360+
300361
### Replying messages
301362

302363
You can reply a previous sent message:
@@ -458,6 +519,8 @@ Fields list: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/b
458519
- Send Contacts
459520
- Send Lists
460521
- Send Buttons
522+
- Send Multi Product Message
523+
- Send Single Product
461524
- Upload media resources to WhatsApp servers
462525
- Download media resources from WhatsApp servers
463526
- Mark messages as read

src/Message/CtaUrl/TitleHeader.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Netflie\WhatsAppCloudApi\Message\CtaUrl;
44

5-
use Netflie\WhatsAppCloudApi\Message\CtaUrl\Header;
6-
75
final class TitleHeader extends Header
86
{
97
protected string $title;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Netflie\WhatsAppCloudApi\Message\MultiProduct;
4+
5+
final class Action
6+
{
7+
protected array $sections;
8+
9+
public function __construct(array $sections)
10+
{
11+
$this->sections = $sections;
12+
}
13+
14+
public function sections(): array
15+
{
16+
$result = [];
17+
18+
foreach ($this->sections as $section) {
19+
$result[] = [
20+
'title' => $section->title(),
21+
'product_items' => $section->rows(),
22+
];
23+
}
24+
25+
return $result;
26+
}
27+
}

src/Message/MultiProduct/Row.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Netflie\WhatsAppCloudApi\Message\MultiProduct;
4+
5+
final class Row
6+
{
7+
protected string $product_retailer_id;
8+
9+
public function __construct(string $product_retailer_id)
10+
{
11+
$this->product_retailer_id = $product_retailer_id;
12+
}
13+
14+
public function product_retailer_id(): string
15+
{
16+
return $this->product_retailer_id;
17+
}
18+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Netflie\WhatsAppCloudApi\Message\MultiProduct;
4+
5+
final class Section
6+
{
7+
protected string $title;
8+
9+
protected array $rows;
10+
11+
public function __construct(string $title, array $rows)
12+
{
13+
$this->title = $title;
14+
$this->rows = $rows;
15+
}
16+
17+
public function title(): string
18+
{
19+
return $this->title;
20+
}
21+
22+
public function rows(): array
23+
{
24+
$result = [];
25+
26+
foreach ($this->rows as $row) {
27+
$result[] = [
28+
'product_retailer_id' => $row->product_retailer_id(),
29+
];
30+
}
31+
32+
return $result;
33+
}
34+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Netflie\WhatsAppCloudApi\Message;
4+
5+
use Netflie\WhatsAppCloudApi\Message\MultiProduct\Action;
6+
7+
final class MultiProductMessage extends Message
8+
{
9+
/**
10+
* {@inheritdoc}
11+
*/
12+
protected string $type = 'product_list';
13+
14+
private string $header;
15+
16+
private string $body;
17+
18+
private int $catalog_id;
19+
20+
private ?string $footer;
21+
22+
private Action $action;
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function __construct(string $to, int $catalog_id, Action $action, string $header, string $body, ?string $footer, ?string $reply_to)
28+
{
29+
$this->header = $header;
30+
$this->body = $body;
31+
$this->catalog_id = $catalog_id;
32+
$this->footer = $footer;
33+
$this->action = $action;
34+
35+
parent::__construct($to, $reply_to);
36+
}
37+
38+
public function header(): array
39+
{
40+
return [
41+
'type' => 'text',
42+
'text' => $this->header,
43+
];
44+
}
45+
46+
public function body(): string
47+
{
48+
return $this->body;
49+
}
50+
51+
public function catalog_id(): int
52+
{
53+
return $this->catalog_id;
54+
}
55+
56+
public function footer(): ?string
57+
{
58+
return $this->footer;
59+
}
60+
61+
public function sections(): array
62+
{
63+
return $this->action->sections();
64+
}
65+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Netflie\WhatsAppCloudApi\Message;
4+
5+
final class SingleProductMessage extends Message
6+
{
7+
/**
8+
* {@inheritdoc}
9+
*/
10+
protected string $type = 'product';
11+
12+
private int $catalog_id;
13+
14+
private string $product_retailer_id;
15+
16+
private ?string $body;
17+
18+
private ?string $footer;
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public function __construct(string $to, int $catalog_id, string $product_retailer_id, ?string $body, ?string $footer, ?string $reply_to)
24+
{
25+
$this->catalog_id = $catalog_id;
26+
$this->product_retailer_id = $product_retailer_id;
27+
$this->body = $body;
28+
$this->footer = $footer;
29+
30+
parent::__construct($to, $reply_to);
31+
}
32+
33+
public function catalog_id(): int
34+
{
35+
return $this->catalog_id;
36+
}
37+
38+
public function product_retailer_id(): string
39+
{
40+
return $this->product_retailer_id;
41+
}
42+
43+
public function body(): ?string
44+
{
45+
return $this->body;
46+
}
47+
48+
public function footer(): ?string
49+
{
50+
return $this->footer;
51+
}
52+
}

src/Request/BusinessProfileRequest/UpdateBusinessProfileRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function body(): array
3333
{
3434
return array_merge(
3535
[
36-
'messaging_product' => 'whatsapp'
36+
'messaging_product' => 'whatsapp',
3737
],
3838
$this->information
3939
);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Netflie\WhatsAppCloudApi\Request\MessageRequest;
4+
5+
use Netflie\WhatsAppCloudApi\Request\MessageRequest;
6+
7+
final class RequestMultiProductMessage extends MessageRequest
8+
{
9+
/**
10+
* {@inheritdoc}
11+
*/
12+
public function body(): array
13+
{
14+
$body = [
15+
'messaging_product' => $this->message->messagingProduct(),
16+
'recipient_type' => $this->message->recipientType(),
17+
'to' => $this->message->to(),
18+
'type' => 'interactive',
19+
'interactive' => [
20+
'type' => $this->message->type(),
21+
'header' => $this->message->header(),
22+
'body' => ['text' => $this->message->body()],
23+
'action' => [
24+
'catalog_id' => $this->message->catalog_id(),
25+
'sections' => $this->message->sections(),
26+
],
27+
],
28+
];
29+
30+
if ($this->message->footer()) {
31+
$body['interactive']['footer'] = ['text' => $this->message->footer()];
32+
}
33+
34+
if ($this->message->replyTo()) {
35+
$body['context']['message_id'] = $this->message->replyTo();
36+
}
37+
38+
return $body;
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Netflie\WhatsAppCloudApi\Request\MessageRequest;
4+
5+
use Netflie\WhatsAppCloudApi\Request\MessageRequest;
6+
7+
final class RequestSingleProductMessage extends MessageRequest
8+
{
9+
/**
10+
* {@inheritdoc}
11+
*/
12+
public function body(): array
13+
{
14+
$body = [
15+
'messaging_product' => $this->message->messagingProduct(),
16+
'recipient_type' => $this->message->recipientType(),
17+
'to' => $this->message->to(),
18+
'type' => 'interactive',
19+
'interactive' => [
20+
'type' => $this->message->type(),
21+
'action' => [
22+
'catalog_id' => $this->message->catalog_id(),
23+
'product_retailer_id' => $this->message->product_retailer_id(),
24+
],
25+
],
26+
];
27+
28+
if ($this->message->body()) {
29+
$body['interactive']['body'] = ['text' => $this->message->body()];
30+
}
31+
32+
if ($this->message->footer()) {
33+
$body['interactive']['footer'] = ['text' => $this->message->footer()];
34+
}
35+
36+
if ($this->message->replyTo()) {
37+
$body['context']['message_id'] = $this->message->replyTo();
38+
}
39+
40+
return $body;
41+
}
42+
}

0 commit comments

Comments
 (0)