-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/q3 messages additions (#497)
* RCS objects and tests added * RCS update message added
- Loading branch information
Showing
10 changed files
with
647 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\RCS; | ||
|
||
use Vonage\Messages\MessageObjects\FileObject; | ||
use Vonage\Messages\Channel\BaseMessage; | ||
use Vonage\Messages\MessageTraits\TtlTrait; | ||
|
||
class RcsCustom extends BaseMessage | ||
{ | ||
use TtlTrait; | ||
|
||
protected const RCS_TEXT_MIN_TTL = 300; | ||
protected const RCS_TEXT_MAX_TTL = 259200; | ||
|
||
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; | ||
protected string $channel = 'rcs'; | ||
protected array $custom; | ||
|
||
public function __construct( | ||
string $to, | ||
string $from, | ||
array $custom | ||
) { | ||
$this->to = $to; | ||
$this->from = $from; | ||
$this->custom = $custom; | ||
} | ||
|
||
public function getCustom(): array | ||
{ | ||
return $this->custom; | ||
} | ||
|
||
public function setCustom(array $custom): RcsCustom | ||
{ | ||
$this->custom = $custom; | ||
return $this; | ||
} | ||
|
||
public function setTtl(?int $ttl): void | ||
{ | ||
$range = [ | ||
'options' => [ | ||
'min_range' => self::RCS_TEXT_MIN_TTL, | ||
'max_range' => self::RCS_TEXT_MAX_TTL | ||
] | ||
]; | ||
|
||
if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) { | ||
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid'); | ||
} | ||
|
||
$this->ttl = $ttl; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnArray = $this->getBaseMessageUniversalOutputArray(); | ||
|
||
$returnArray['custom'] = $this->getCustom(); | ||
|
||
if ($this->getClientRef()) { | ||
$returnArray['client_ref'] = $this->getClientRef(); | ||
} | ||
|
||
if ($this->getWebhookUrl()) { | ||
$returnArray['webhook_url'] = $this->getWebhookUrl(); | ||
} | ||
|
||
if ($this->getTtl()) { | ||
$returnArray['ttl'] = $this->getTtl(); | ||
} | ||
|
||
return $returnArray; | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\RCS; | ||
|
||
use Vonage\Messages\MessageObjects\FileObject; | ||
use Vonage\Messages\Channel\BaseMessage; | ||
use Vonage\Messages\MessageTraits\TtlTrait; | ||
|
||
class RcsFile extends BaseMessage | ||
{ | ||
use TtlTrait; | ||
|
||
protected const RCS_TEXT_MIN_TTL = 300; | ||
protected const RCS_TEXT_MAX_TTL = 259200; | ||
|
||
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; | ||
protected string $channel = 'rcs'; | ||
protected FileObject $file; | ||
|
||
public function __construct( | ||
string $to, | ||
string $from, | ||
FileObject $file | ||
) { | ||
$this->to = $to; | ||
$this->from = $from; | ||
$this->file = $file; | ||
} | ||
|
||
public function setTtl(?int $ttl): void | ||
{ | ||
$range = [ | ||
'options' => [ | ||
'min_range' => self::RCS_TEXT_MIN_TTL, | ||
'max_range' => self::RCS_TEXT_MAX_TTL | ||
] | ||
]; | ||
|
||
if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) { | ||
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid'); | ||
} | ||
|
||
$this->ttl = $ttl; | ||
} | ||
|
||
public function getFile(): FileObject | ||
{ | ||
return $this->file; | ||
} | ||
|
||
public function setFile(FileObject $fileObject): RcsFile | ||
{ | ||
$this->file = $fileObject; | ||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnArray = $this->getBaseMessageUniversalOutputArray(); | ||
|
||
$returnArray['file'] = $this->getFile()->toArray(); | ||
|
||
if ($this->getClientRef()) { | ||
$returnArray['client_ref'] = $this->getClientRef(); | ||
} | ||
|
||
if ($this->getWebhookUrl()) { | ||
$returnArray['webhook_url'] = $this->getWebhookUrl(); | ||
} | ||
|
||
if ($this->getTtl()) { | ||
$returnArray['ttl'] = $this->getTtl(); | ||
} | ||
|
||
return $returnArray; | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\RCS; | ||
|
||
use Vonage\Messages\MessageObjects\ImageObject; | ||
use Vonage\Messages\Channel\BaseMessage; | ||
use Vonage\Messages\MessageTraits\TtlTrait; | ||
|
||
class RcsImage extends BaseMessage | ||
{ | ||
use TtlTrait; | ||
|
||
protected const RCS_TEXT_MIN_TTL = 300; | ||
protected const RCS_TEXT_MAX_TTL = 259200; | ||
|
||
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_IMAGE; | ||
protected string $channel = 'rcs'; | ||
protected ImageObject $image; | ||
|
||
public function __construct( | ||
string $to, | ||
string $from, | ||
ImageObject $image | ||
) { | ||
$this->to = $to; | ||
$this->from = $from; | ||
$this->image = $image; | ||
} | ||
|
||
public function setTtl(?int $ttl): void | ||
{ | ||
$range = [ | ||
'options' => [ | ||
'min_range' => self::RCS_TEXT_MIN_TTL, | ||
'max_range' => self::RCS_TEXT_MAX_TTL | ||
] | ||
]; | ||
|
||
if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) { | ||
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid'); | ||
} | ||
|
||
$this->ttl = $ttl; | ||
} | ||
|
||
public function getImage(): ImageObject | ||
{ | ||
return $this->image; | ||
} | ||
|
||
public function setImage(ImageObject $image): RcsImage | ||
{ | ||
$this->image = $image; | ||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnArray = $this->getBaseMessageUniversalOutputArray(); | ||
|
||
$returnArray['image'] = $this->getImage()->toArray(); | ||
|
||
if ($this->getClientRef()) { | ||
$returnArray['client_ref'] = $this->getClientRef(); | ||
} | ||
|
||
if ($this->getWebhookUrl()) { | ||
$returnArray['webhook_url'] = $this->getWebhookUrl(); | ||
} | ||
|
||
if ($this->getTtl()) { | ||
$returnArray['ttl'] = $this->getTtl(); | ||
} | ||
|
||
return $returnArray; | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\RCS; | ||
|
||
class RcsInvalidTtlException extends \Exception | ||
{ | ||
} |
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 Vonage\Messages\Channel\RCS; | ||
|
||
use Vonage\Messages\MessageTraits\TextTrait; | ||
use Vonage\Messages\Channel\BaseMessage; | ||
use Vonage\Messages\MessageTraits\TtlTrait; | ||
|
||
class RcsText extends BaseMessage | ||
{ | ||
use TextTrait; | ||
use TtlTrait; | ||
|
||
protected const RCS_TEXT_MIN_TTL = 300; | ||
protected const RCS_TEXT_MAX_TTL = 259200; | ||
|
||
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEXT; | ||
protected string $channel = 'rcs'; | ||
|
||
public function __construct( | ||
string $to, | ||
string $from, | ||
string $message | ||
) { | ||
$this->to = $to; | ||
$this->from = $from; | ||
$this->text = $message; | ||
} | ||
|
||
public function setTtl(?int $ttl): void | ||
{ | ||
$range = [ | ||
'options' => [ | ||
'min_range' => self::RCS_TEXT_MIN_TTL, | ||
'max_range' => self::RCS_TEXT_MAX_TTL | ||
] | ||
]; | ||
|
||
if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) { | ||
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid'); | ||
} | ||
|
||
$this->ttl = $ttl; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnArray = $this->getBaseMessageUniversalOutputArray(); | ||
$returnArray['text'] = $this->getText(); | ||
|
||
if ($this->getClientRef()) { | ||
$returnArray['client_ref'] = $this->getClientRef(); | ||
} | ||
|
||
if ($this->getWebhookUrl()) { | ||
$returnArray['webhook_url'] = $this->getWebhookUrl(); | ||
} | ||
|
||
if ($this->getTtl()) { | ||
$returnArray['ttl'] = $this->getTtl(); | ||
} | ||
|
||
return $returnArray; | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\RCS; | ||
|
||
use Vonage\Messages\MessageObjects\VideoObject; | ||
use Vonage\Messages\Channel\BaseMessage; | ||
use Vonage\Messages\MessageTraits\TtlTrait; | ||
|
||
class RcsVideo extends BaseMessage | ||
{ | ||
use TtlTrait; | ||
|
||
protected const RCS_TEXT_MIN_TTL = 300; | ||
protected const RCS_TEXT_MAX_TTL = 259200; | ||
|
||
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; | ||
protected string $channel = 'rcs'; | ||
protected VideoObject $video; | ||
|
||
public function __construct( | ||
string $to, | ||
string $from, | ||
VideoObject $videoObject | ||
) { | ||
$this->to = $to; | ||
$this->from = $from; | ||
$this->video = $videoObject; | ||
} | ||
|
||
public function setTtl(?int $ttl): void | ||
{ | ||
$range = [ | ||
'options' => [ | ||
'min_range' => self::RCS_TEXT_MIN_TTL, | ||
'max_range' => self::RCS_TEXT_MAX_TTL | ||
] | ||
]; | ||
|
||
if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) { | ||
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid'); | ||
} | ||
|
||
$this->ttl = $ttl; | ||
} | ||
|
||
public function getVideo(): VideoObject | ||
{ | ||
return $this->video; | ||
} | ||
|
||
public function setVideo(VideoObject $videoObject): RcsVideo | ||
{ | ||
$this->video = $videoObject; | ||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnArray = $this->getBaseMessageUniversalOutputArray(); | ||
|
||
$returnArray['video'] = $this->getVideo()->toArray(); | ||
|
||
if ($this->getClientRef()) { | ||
$returnArray['client_ref'] = $this->getClientRef(); | ||
} | ||
|
||
if ($this->getWebhookUrl()) { | ||
$returnArray['webhook_url'] = $this->getWebhookUrl(); | ||
} | ||
|
||
if ($this->getTtl()) { | ||
$returnArray['ttl'] = $this->getTtl(); | ||
} | ||
|
||
return $returnArray; | ||
} | ||
} |
Oops, something went wrong.