-
-
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 #186 from jfradj/dev-cta
Implement CTA URL message (With text & Image support)
- Loading branch information
Showing
9 changed files
with
315 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,15 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\CtaUrl; | ||
|
||
abstract class Header | ||
{ | ||
protected string $type; | ||
|
||
protected function __construct(string $type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
abstract public function getBody(): array; | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\CtaUrl; | ||
|
||
final class ImageHeader extends Header | ||
{ | ||
protected string $link; | ||
|
||
public function __construct(string $link) | ||
{ | ||
parent::__construct('image'); | ||
|
||
$this->link = $link; | ||
} | ||
|
||
public function getBody(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'image' => [ | ||
'link' => $this->link, | ||
], | ||
]; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message\CtaUrl; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\CtaUrl\Header; | ||
|
||
final class TitleHeader extends Header | ||
{ | ||
protected string $title; | ||
|
||
public function __construct(string $title) | ||
{ | ||
parent::__construct('text'); | ||
|
||
$this->title = $title; | ||
} | ||
|
||
public function getBody(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'text' => $this->title, | ||
]; | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Message; | ||
|
||
use Netflie\WhatsAppCloudApi\Message\CtaUrl\Header; | ||
|
||
final class CtaUrlMessage extends Message | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected string $type = 'cta_url'; | ||
|
||
private string $displayText; | ||
|
||
private string $url; | ||
|
||
private ?Header $header = null; | ||
|
||
private ?string $body = null; | ||
|
||
private ?string $footer = null; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct( | ||
string $to, | ||
string $displayText, | ||
string $url, | ||
?Header $header, | ||
?string $body, | ||
?string $footer, | ||
?string $reply_to | ||
) { | ||
$this->displayText = $displayText; | ||
$this->url = $url; | ||
$this->header = $header; | ||
$this->body = $body; | ||
$this->footer = $footer; | ||
|
||
parent::__construct($to, $reply_to); | ||
} | ||
|
||
public function getDisplayText(): string | ||
{ | ||
return $this->displayText; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function header(): ?array | ||
{ | ||
return is_null($this->header) ? null : $this->header->getBody(); | ||
} | ||
|
||
public function body(): ?string | ||
{ | ||
return $this->body; | ||
} | ||
|
||
public function footer(): ?string | ||
{ | ||
return $this->footer; | ||
} | ||
|
||
public function action(): array | ||
{ | ||
return [ | ||
'name' => $this->type, | ||
'parameters' => [ | ||
'display_text' => $this->displayText, | ||
'url' => $this->url, | ||
], | ||
]; | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
use Netflie\WhatsAppCloudApi\Request\MessageRequest; | ||
|
||
final class RequestCtaUrlMessage 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' => $this->message->action(), | ||
], | ||
]; | ||
|
||
if ($this->message->header()) { | ||
$body['interactive']['header'] = $this->message->header(); | ||
} | ||
|
||
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; | ||
} | ||
} |
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