|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Vonage\Messages\Channel\RCS; |
| 4 | + |
| 5 | +use Vonage\Messages\MessageObjects\VideoObject; |
| 6 | +use Vonage\Messages\Channel\BaseMessage; |
| 7 | +use Vonage\Messages\MessageTraits\TtlTrait; |
| 8 | + |
| 9 | +class RcsVideo extends BaseMessage |
| 10 | +{ |
| 11 | + use TtlTrait; |
| 12 | + |
| 13 | + protected const RCS_TEXT_MIN_TTL = 300; |
| 14 | + protected const RCS_TEXT_MAX_TTL = 259200; |
| 15 | + |
| 16 | + protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; |
| 17 | + protected string $channel = 'rcs'; |
| 18 | + protected VideoObject $video; |
| 19 | + |
| 20 | + public function __construct( |
| 21 | + string $to, |
| 22 | + string $from, |
| 23 | + VideoObject $videoObject |
| 24 | + ) { |
| 25 | + $this->to = $to; |
| 26 | + $this->from = $from; |
| 27 | + $this->video = $videoObject; |
| 28 | + } |
| 29 | + |
| 30 | + public function setTtl(?int $ttl): void |
| 31 | + { |
| 32 | + $range = [ |
| 33 | + 'options' => [ |
| 34 | + 'min_range' => self::RCS_TEXT_MIN_TTL, |
| 35 | + 'max_range' => self::RCS_TEXT_MAX_TTL |
| 36 | + ] |
| 37 | + ]; |
| 38 | + |
| 39 | + if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) { |
| 40 | + throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid'); |
| 41 | + } |
| 42 | + |
| 43 | + $this->ttl = $ttl; |
| 44 | + } |
| 45 | + |
| 46 | + public function getVideo(): VideoObject |
| 47 | + { |
| 48 | + return $this->video; |
| 49 | + } |
| 50 | + |
| 51 | + public function setVideo(VideoObject $videoObject): RcsVideo |
| 52 | + { |
| 53 | + $this->video = $videoObject; |
| 54 | + return $this; |
| 55 | + } |
| 56 | + |
| 57 | + public function toArray(): array |
| 58 | + { |
| 59 | + $returnArray = $this->getBaseMessageUniversalOutputArray(); |
| 60 | + |
| 61 | + $returnArray['video'] = $this->getVideo()->toArray(); |
| 62 | + |
| 63 | + if ($this->getClientRef()) { |
| 64 | + $returnArray['client_ref'] = $this->getClientRef(); |
| 65 | + } |
| 66 | + |
| 67 | + if ($this->getWebhookUrl()) { |
| 68 | + $returnArray['webhook_url'] = $this->getWebhookUrl(); |
| 69 | + } |
| 70 | + |
| 71 | + if ($this->getTtl()) { |
| 72 | + $returnArray['ttl'] = $this->getTtl(); |
| 73 | + } |
| 74 | + |
| 75 | + return $returnArray; |
| 76 | + } |
| 77 | +} |
0 commit comments