-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from netflie/multi-product-message
Add Multi Products
- Loading branch information
Showing
9 changed files
with
379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\MultiProduct; | ||
|
||
final class Action | ||
{ | ||
protected array $sections; | ||
|
||
public function __construct(array $sections) | ||
{ | ||
$this->sections = $sections; | ||
} | ||
|
||
public function sections(): array | ||
{ | ||
$result = []; | ||
|
||
foreach ($this->sections as $section) { | ||
$result[] = [ | ||
'title' => $section->title(), | ||
'product_items' => $section->rows(), | ||
]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\MultiProduct; | ||
|
||
final class Row | ||
{ | ||
protected string $product_retailer_id; | ||
|
||
public function __construct(string $product_retailer_id) | ||
{ | ||
$this->product_retailer_id = $product_retailer_id; | ||
} | ||
|
||
public function product_retailer_id(): string | ||
{ | ||
return $this->product_retailer_id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\MultiProduct; | ||
|
||
final class Section | ||
{ | ||
protected string $title; | ||
|
||
protected array $rows; | ||
|
||
public function __construct(string $title, array $rows) | ||
{ | ||
$this->title = $title; | ||
$this->rows = $rows; | ||
} | ||
|
||
public function title(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function rows(): array | ||
{ | ||
$result = []; | ||
|
||
foreach ($this->rows as $row) { | ||
$result[] = [ | ||
'product_retailer_id' => $row->product_retailer_id(), | ||
]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\MultiProduct\Action; | ||
|
||
final class MultiProductMessage extends Message | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected string $type = 'product_list'; | ||
|
||
private string $header; | ||
|
||
private string $body; | ||
|
||
private int $catalog_id; | ||
|
||
private ?string $footer; | ||
|
||
private Action $action; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(string $to, int $catalog_id, Action $action, string $header, string $body, ?string $footer, ?string $reply_to) | ||
{ | ||
$this->header = $header; | ||
$this->body = $body; | ||
$this->catalog_id = $catalog_id; | ||
$this->footer = $footer; | ||
$this->action = $action; | ||
|
||
parent::__construct($to, $reply_to); | ||
} | ||
|
||
public function header(): array | ||
{ | ||
return [ | ||
'type' => 'text', | ||
'text' => $this->header, | ||
]; | ||
} | ||
|
||
public function body(): string | ||
{ | ||
return $this->body; | ||
} | ||
|
||
public function catalog_id(): int | ||
{ | ||
return $this->catalog_id; | ||
} | ||
|
||
public function footer(): ?string | ||
{ | ||
return $this->footer; | ||
} | ||
|
||
public function sections(): array | ||
{ | ||
return $this->action->sections(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
use Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
final class RequestMultiProductMessage extends MessageRequest | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function body(): array | ||
{ | ||
$body = [ | ||
'messaging_product' => $this->message->messagingProduct(), | ||
'recipient_type' => $this->message->recipientType(), | ||
'to' => $this->message->to(), | ||
'type' => 'interactive', | ||
'interactive' => [ | ||
'type' => $this->message->type(), | ||
'header' => $this->message->header(), | ||
'body' => ['text' => $this->message->body()], | ||
'action' => [ | ||
'catalog_id' => $this->message->catalog_id(), | ||
'sections' => $this->message->sections(), | ||
], | ||
], | ||
]; | ||
|
||
if ($this->message->footer()) { | ||
$body['interactive']['footer'] = ['text' => $this->message->footer()]; | ||
} | ||
|
||
if ($this->message->replyTo()) { | ||
$body['context']['message_id'] = $this->message->replyTo(); | ||
} | ||
|
||
return $body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.