Skip to content

Commit 700cd53

Browse files
authored
Feature/q3 messages additions (#497)
* RCS objects and tests added * RCS update message added
1 parent 8efe7cc commit 700cd53

File tree

10 files changed

+647
-0
lines changed

10 files changed

+647
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Vonage\Messages\Channel\RCS;
4+
5+
use Vonage\Messages\MessageObjects\FileObject;
6+
use Vonage\Messages\Channel\BaseMessage;
7+
use Vonage\Messages\MessageTraits\TtlTrait;
8+
9+
class RcsCustom 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_FILE;
17+
protected string $channel = 'rcs';
18+
protected array $custom;
19+
20+
public function __construct(
21+
string $to,
22+
string $from,
23+
array $custom
24+
) {
25+
$this->to = $to;
26+
$this->from = $from;
27+
$this->custom = $custom;
28+
}
29+
30+
public function getCustom(): array
31+
{
32+
return $this->custom;
33+
}
34+
35+
public function setCustom(array $custom): RcsCustom
36+
{
37+
$this->custom = $custom;
38+
return $this;
39+
}
40+
41+
public function setTtl(?int $ttl): void
42+
{
43+
$range = [
44+
'options' => [
45+
'min_range' => self::RCS_TEXT_MIN_TTL,
46+
'max_range' => self::RCS_TEXT_MAX_TTL
47+
]
48+
];
49+
50+
if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) {
51+
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid');
52+
}
53+
54+
$this->ttl = $ttl;
55+
}
56+
57+
public function toArray(): array
58+
{
59+
$returnArray = $this->getBaseMessageUniversalOutputArray();
60+
61+
$returnArray['custom'] = $this->getCustom();
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+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Vonage\Messages\Channel\RCS;
4+
5+
use Vonage\Messages\MessageObjects\FileObject;
6+
use Vonage\Messages\Channel\BaseMessage;
7+
use Vonage\Messages\MessageTraits\TtlTrait;
8+
9+
class RcsFile 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_FILE;
17+
protected string $channel = 'rcs';
18+
protected FileObject $file;
19+
20+
public function __construct(
21+
string $to,
22+
string $from,
23+
FileObject $file
24+
) {
25+
$this->to = $to;
26+
$this->from = $from;
27+
$this->file = $file;
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 getFile(): FileObject
47+
{
48+
return $this->file;
49+
}
50+
51+
public function setFile(FileObject $fileObject): RcsFile
52+
{
53+
$this->file = $fileObject;
54+
return $this;
55+
}
56+
57+
public function toArray(): array
58+
{
59+
$returnArray = $this->getBaseMessageUniversalOutputArray();
60+
61+
$returnArray['file'] = $this->getFile()->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+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Vonage\Messages\Channel\RCS;
4+
5+
use Vonage\Messages\MessageObjects\ImageObject;
6+
use Vonage\Messages\Channel\BaseMessage;
7+
use Vonage\Messages\MessageTraits\TtlTrait;
8+
9+
class RcsImage 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_IMAGE;
17+
protected string $channel = 'rcs';
18+
protected ImageObject $image;
19+
20+
public function __construct(
21+
string $to,
22+
string $from,
23+
ImageObject $image
24+
) {
25+
$this->to = $to;
26+
$this->from = $from;
27+
$this->image = $image;
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 getImage(): ImageObject
47+
{
48+
return $this->image;
49+
}
50+
51+
public function setImage(ImageObject $image): RcsImage
52+
{
53+
$this->image = $image;
54+
return $this;
55+
}
56+
57+
public function toArray(): array
58+
{
59+
$returnArray = $this->getBaseMessageUniversalOutputArray();
60+
61+
$returnArray['image'] = $this->getImage()->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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Vonage\Messages\Channel\RCS;
4+
5+
class RcsInvalidTtlException extends \Exception
6+
{
7+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Vonage\Messages\Channel\RCS;
4+
5+
use Vonage\Messages\MessageTraits\TextTrait;
6+
use Vonage\Messages\Channel\BaseMessage;
7+
use Vonage\Messages\MessageTraits\TtlTrait;
8+
9+
class RcsText extends BaseMessage
10+
{
11+
use TextTrait;
12+
use TtlTrait;
13+
14+
protected const RCS_TEXT_MIN_TTL = 300;
15+
protected const RCS_TEXT_MAX_TTL = 259200;
16+
17+
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEXT;
18+
protected string $channel = 'rcs';
19+
20+
public function __construct(
21+
string $to,
22+
string $from,
23+
string $message
24+
) {
25+
$this->to = $to;
26+
$this->from = $from;
27+
$this->text = $message;
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 toArray(): array
47+
{
48+
$returnArray = $this->getBaseMessageUniversalOutputArray();
49+
$returnArray['text'] = $this->getText();
50+
51+
if ($this->getClientRef()) {
52+
$returnArray['client_ref'] = $this->getClientRef();
53+
}
54+
55+
if ($this->getWebhookUrl()) {
56+
$returnArray['webhook_url'] = $this->getWebhookUrl();
57+
}
58+
59+
if ($this->getTtl()) {
60+
$returnArray['ttl'] = $this->getTtl();
61+
}
62+
63+
return $returnArray;
64+
}
65+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)