-
-
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.
- Loading branch information
Showing
18 changed files
with
701 additions
and
6 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
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,52 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message; | ||
|
||
final class SingleProductMessage extends Message | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected string $type = 'product'; | ||
|
||
private int $catalog_id; | ||
|
||
private string $product_retailer_id; | ||
|
||
private ?string $body; | ||
|
||
private ?string $footer; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(string $to, int $catalog_id, string $product_retailer_id, ?string $body, ?string $footer, ?string $reply_to) | ||
{ | ||
$this->catalog_id = $catalog_id; | ||
$this->product_retailer_id = $product_retailer_id; | ||
$this->body = $body; | ||
$this->footer = $footer; | ||
|
||
parent::__construct($to, $reply_to); | ||
} | ||
|
||
public function catalog_id(): int | ||
{ | ||
return $this->catalog_id; | ||
} | ||
|
||
public function product_retailer_id(): string | ||
{ | ||
return $this->product_retailer_id; | ||
} | ||
|
||
public function body(): ?string | ||
{ | ||
return $this->body; | ||
} | ||
|
||
public function footer(): ?string | ||
{ | ||
return $this->footer; | ||
} | ||
} |
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,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; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Request/MessageRequest/RequestSingleProductMessage.php
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,42 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
use Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
final class RequestSingleProductMessage 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(), | ||
'action' => [ | ||
'catalog_id' => $this->message->catalog_id(), | ||
'product_retailer_id' => $this->message->product_retailer_id(), | ||
], | ||
], | ||
]; | ||
|
||
if ($this->message->body()) { | ||
$body['interactive']['body'] = ['text' => $this->message->body()]; | ||
} | ||
|
||
if ($this->message->footer()) { | ||
$body['interactive']['footer'] = ['text' => $this->message->footer()]; | ||
} | ||
|
||
if ($this->message->replyTo()) { | ||
$body['context']['message_id'] = $this->message->replyTo(); | ||
} | ||
|
||
return $body; | ||
} | ||
} |
Oops, something went wrong.