Skip to content

Commit 783d812

Browse files
authored
remove outdated docs (#331)
* remove outdated docs * add in premium, add in deprecation for voicename * Fixed tests, use defaults for typed properties
1 parent 4b353c6 commit 783d812

File tree

4 files changed

+80
-38
lines changed

4 files changed

+80
-38
lines changed

src/Voice/NCCO/Action/Talk.php

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,51 @@
1717

1818
class Talk implements ActionInterface
1919
{
20-
/**
21-
* @var bool
22-
*/
23-
protected $bargeIn;
20+
protected bool $bargeIn = false;
2421

25-
/**
26-
* @var string
27-
*/
28-
protected $language;
22+
protected string $language = '';
2923

30-
/**
31-
* @var int
32-
*/
33-
protected $languageStyle = 0;
24+
protected int $languageStyle = 0;
3425

35-
/**
36-
* @var float
37-
*/
38-
protected $level;
26+
protected ?float $level = 0;
3927

40-
/**
41-
* @var int
42-
*/
43-
protected $loop;
28+
protected int $loop = 1;
4429

45-
/**
46-
* @var string
47-
*/
48-
protected $text;
30+
protected ?string $text = '';
31+
32+
protected bool $premium = false;
4933

5034
public function __construct(string $text = null)
5135
{
5236
$this->text = $text;
5337
}
5438

5539
/**
56-
* @param string $text
57-
* @param array{text: string, bargeIn?: bool, level?: float, loop?: int, voiceName?: string} $data
58-
* @return Talk
40+
* @param array{text: string, bargeIn?: bool, level?: float, style? : string, language?: string, premium?: bool, loop?: int} $data
5941
*/
6042
public static function factory(string $text, array $data): Talk
6143
{
6244
$talk = new Talk($text);
6345

46+
if (array_key_exists('voiceName', $data)) {
47+
trigger_error(
48+
'voiceName is deprecated and will not be added to the NCCO',
49+
E_USER_DEPRECATED
50+
);
51+
}
52+
6453
if (array_key_exists('bargeIn', $data)) {
6554
$talk->setBargeIn(
6655
filter_var($data['bargeIn'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE])
6756
);
6857
}
6958

59+
if (array_key_exists('premium', $data)) {
60+
$talk->setPremium(
61+
filter_var($data['premium'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE])
62+
);
63+
}
64+
7065
if (array_key_exists('level', $data)) {
7166
$talk->setLevel(
7267
filter_var($data['level'], FILTER_VALIDATE_FLOAT, ['flags' => FILTER_NULL_ON_FAILURE])
@@ -111,16 +106,13 @@ public function getText(): string
111106
}
112107

113108
/**
114-
* @return array{action: string, bargeIn: bool, level: float, loop: int, text: string, voiceName: string}
109+
* @return array{action: string, bargeIn: bool, level: float, loop: int, text: string}
115110
*/
116111
public function jsonSerialize(): array
117112
{
118113
return $this->toNCCOArray();
119114
}
120115

121-
/**
122-
* @return $this
123-
*/
124116
public function setBargeIn(bool $value): self
125117
{
126118
$this->bargeIn = $value;
@@ -137,18 +129,30 @@ public function setLevel(float $level): self
137129
return $this;
138130
}
139131

132+
public function setLoop(int $times): self
133+
{
134+
$this->loop = $times;
135+
136+
return $this;
137+
}
138+
140139
/**
141140
* @return $this
142141
*/
143-
public function setLoop(int $times): self
142+
public function setPremium(bool $premium): self
144143
{
145-
$this->loop = $times;
144+
$this->premium = $premium;
146145

147146
return $this;
148147
}
149148

149+
public function getPremium(): bool
150+
{
151+
return $this->premium;
152+
}
153+
150154
/**
151-
* @return array{action: string, bargeIn: bool, level: string, loop: string, text: string, voiceName: string, language: string, style: string}
155+
* @return array{action: string, bargeIn: bool, level: string, loop: string, text: string, premium: string, language: string, style: string}
152156
*/
153157
public function toNCCOArray(): array
154158
{
@@ -174,6 +178,10 @@ public function toNCCOArray(): array
174178
$data['style'] = (string) $this->getLanguageStyle();
175179
}
176180

181+
if (!is_null($this->getPremium())) {
182+
$data['premium'] = $this->getPremium() ? 'true' : 'false';
183+
}
184+
177185
return $data;
178186
}
179187

test/Voice/ClientTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ public function testCanCreateOutboundCallWithNCCO(): void
173173
[
174174
'action' => 'talk',
175175
'text' => 'Thank you for trying Vonage',
176+
'bargeIn' => 'false',
177+
'level' => '0',
178+
'loop' => '1',
179+
'premium' => 'false'
176180
]
177181
],
178182
'length_timer' => '7200',
@@ -391,6 +395,10 @@ public function testCanTransferACallLegWithNCCO(): void
391395
[
392396
'action' => 'talk',
393397
'text' => 'Thank you for trying Vonage',
398+
'bargeIn' => 'false',
399+
'level' => '0',
400+
'loop' => '1',
401+
'premium' => 'false'
394402
]
395403
]
396404
],
@@ -489,6 +497,10 @@ public function testCanPlayTTSIntoCall(): void
489497
$id = 'ssf61863-4a51-ef6b-11e1-w6edebcf93bb';
490498
$payload = [
491499
'text' => 'This is sample text',
500+
'bargeIn' => 'false',
501+
'level' => '0',
502+
'loop' => '1',
503+
'premium' => 'false'
492504
];
493505

494506
$this->vonageClient->send(Argument::that(function (RequestInterface $request) use ($id, $payload) {

test/Voice/NCCO/Action/TalkTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public function testSimpleSetup(): void
2121
$this->assertSame([
2222
'action' => 'talk',
2323
'text' => 'Hello',
24+
'bargeIn' => 'false',
25+
'level' => '0',
26+
'loop' => '1',
27+
'premium' => 'false'
2428
], (new Talk('Hello'))->jsonSerialize());
2529
}
2630

@@ -32,6 +36,7 @@ public function testJsonSerializeLooksCorrect(): void
3236
'bargeIn' => 'false',
3337
'level' => '0',
3438
'loop' => '1',
39+
'premium' => 'false'
3540
];
3641

3742
$action = new Talk('Hello');
@@ -47,8 +52,12 @@ public function testCanSetLanguage(): void
4752
$expected = [
4853
'action' => 'talk',
4954
'text' => 'Hello',
55+
'bargeIn' => 'false',
56+
'level' => '0',
57+
'loop' => '1',
5058
'language' => 'en-US',
51-
'style' => '0'
59+
'style' => '0',
60+
'premium' => 'false'
5261
];
5362

5463
$action = new Talk($expected['text']);
@@ -65,8 +74,12 @@ public function testCanSetLanguageStyle()
6574
$expected = [
6675
'action' => 'talk',
6776
'text' => 'Hello',
77+
'bargeIn' => 'false',
78+
'level' => '0',
79+
'loop' => '1',
6880
'language' => 'en-US',
69-
'style' => '3'
81+
'style' => '3',
82+
'premium' => 'false'
7083
];
7184

7285
$action = new Talk($expected['text']);
@@ -83,8 +96,12 @@ public function testFactorySetsLanguage()
8396
$expected = [
8497
'action' => 'talk',
8598
'text' => 'Hello',
99+
'bargeIn' => 'false',
100+
'level' => '0',
101+
'loop' => '1',
86102
'language' => 'en-US',
87-
'style' => '0'
103+
'style' => '0',
104+
'premium' => 'false'
88105
];
89106

90107
$action = Talk::factory($expected['text'], $expected);
@@ -100,8 +117,12 @@ public function testFactorySetsLanguageAndStyle()
100117
$expected = [
101118
'action' => 'talk',
102119
'text' => 'Hello',
120+
'bargeIn' => 'false',
121+
'level' => '0',
122+
'loop' => '1',
103123
'language' => 'en-US',
104-
'style' => '3'
124+
'style' => '3',
125+
'premium' => 'false'
105126
];
106127

107128
$action = Talk::factory($expected['text'], $expected);

test/Voice/NCCO/NCCOTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testCanCreateNCCOFromArray(): void
3131
'text' => 'Thank you for trying Vonage',
3232
'language' => 'en-US',
3333
'style' => '0',
34+
'premium' => 'false'
3435
],
3536
[
3637
'action' => 'record',

0 commit comments

Comments
 (0)