Skip to content

Commit f270166

Browse files
committed
Updated all the non-framework related Voice snippets to v2.2.0
1 parent b019ae4 commit f270166

File tree

14 files changed

+89
-95
lines changed

14 files changed

+89
-95
lines changed

voice/conference-call.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
// Instruct Nexmo to add this call to a conference
66
// Start with an optional announcement using the `talk` action
7-
$ncco = [
8-
[
9-
'action' => 'talk',
10-
'text' => 'Welcome to the amazing Nexmo conference call'
11-
],
12-
[
13-
'action' => 'conversation',
14-
'name' => 'amazing-conference-call'
15-
]
16-
];
7+
8+
$ncco = new \Nexmo\Voice\NCCO\NCCO();
9+
$ncco
10+
->addAction(
11+
new \Nexmo\Voice\NCCO\Action\Talk('Welcome to the amazing Nexmo conference call')
12+
)
13+
->addAction(
14+
new \Nexmo\Voice\NCCO\Action\Conversation('amazing-conference-call')
15+
)
16+
;
1717

1818
header('Content-Type: application/json');
1919
$json = json_encode($ncco);

voice/connect-a-call.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
<?php
1+
<?php
2+
23
require_once __DIR__ . '/../config.php';
34
require_once __DIR__ . '/../vendor/autoload.php';
45

56
// Retrive the inbound call details
67
$from = $_GET['from'];
78
$to = $_GET['to'];
89

9-
// Create the `connect` NCCO
10-
$ncco = [
11-
[
12-
'action' => 'connect',
13-
'from' => $from,
14-
'endpoint' => [
15-
[
16-
'type' => 'phone',
17-
'number' => NEXMO_TO_NUMBER
18-
]
19-
]
20-
]
21-
];
10+
$ncco = new \Nexmo\Voice\NCCO\NCCO();
11+
$ncco->addAction(
12+
new \Nexmo\Voice\NCCO\Action\Connect(
13+
new \Nexmo\Voice\Endpoint\Phone(NEXMO_TO_NUMBER)
14+
)
15+
);
2216

2317
header('Content-Type: application/json');
2418
$json = json_encode($ncco);

voice/earmuff-a-call/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
66
$client = new \Nexmo\Client($keypair);
77

8-
$client->calls[UUID]->put(new \Nexmo\Call\Earmuff());
8+
$client->voice()->earmuffCall(UUID);
99
sleep(3);
10-
$client->calls[UUID]->put(new \Nexmo\Call\Unearmuff());
10+
$client->voice()->unearmuffCall(UUID);
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
use Nexmo\Voice\NCCO\NCCO;
4+
25
require_once __DIR__ . '/../../config.php';
36
require_once __DIR__ . '/../../vendor/autoload.php';
47

@@ -8,21 +11,14 @@
811
);
912
$client = new \Nexmo\Client($keypair);
1013

11-
$call = $client->calls()->create([
12-
'to' => [[
13-
'type' => 'phone',
14-
'number' => TO_NUMBER
15-
]],
16-
'from' => [
17-
'type' => 'phone',
18-
'number' => NEXMO_NUMBER
19-
],
20-
'ncco' => [
21-
[
22-
'action' => 'talk',
23-
'text' => 'This is a text to speech call from Nexmo'
24-
]
25-
]
26-
]);
14+
$outboundCall = new \Nexmo\Voice\OutboundCall(
15+
new \Nexmo\Voice\Endpoint\Phone(TO_NUMBER),
16+
new \Nexmo\Voice\Endpoint\Phone(NEXMO_NUMBER)
17+
);
18+
$ncco = new NCCO();
19+
$ncco->addAction(new \Nexmo\Voice\NCCO\Action\Talk('This is a text to speech call from Nexmo'));
20+
$outboundCall->setNCCO($ncco);
21+
22+
$response = $client->voice()->createOutboundCall($outboundCall);
2723

28-
print_r($call);
24+
var_dump($response);

voice/mute-a-call/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
66
$client = new \Nexmo\Client($keypair);
77

8-
$client->calls[UUID]->put(new \Nexmo\Call\Mute());
8+
$client->voice()->muteCall(UUID);
99
sleep(3);
10-
$client->calls[UUID]->put(new \Nexmo\Call\Unmute());
10+
$client->voice()->unmuteCall(UUID);

voice/play-audio-stream-in-to-call/index.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
66
$client = new \Nexmo\Client($keypair);
77

8-
$stream = $client->calls[UUID]->stream();
9-
$stream->setUrl('https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3');
10-
$stream->put();
8+
$client->voice()->streamAudio(UUID, 'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3');

voice/play-dtmf-in-to-call/index.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
66
$client = new \Nexmo\Client($keypair);
77

8-
$dtmf = $client->calls[UUID]->dtmf();
9-
$dtmf->setDigits('2468#');
10-
$dtmf->put();
8+
$client->voice()->playDTMF(UUID, '2468#');

voice/play-tts-in-to-call/index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
66
$client = new \Nexmo\Client($keypair);
77

8-
$talk = $client->calls[UUID]->talk();
9-
$talk->setText(TEXT);
10-
$talk->setVoiceName('Kimberly');
11-
$talk->put();
8+
$client->voice()->playTTS(
9+
UUID,
10+
new \Nexmo\Voice\NCCO\Action\Talk(TEXT)
11+
);

voice/retrieve-call-info/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
66
$client = new \Nexmo\Client($keypair);
77

8-
$call = $client->calls()->get(NEXMO_CALL_UUID);
9-
echo json_encode($call).PHP_EOL;
8+
$call = $client->voice()->get(NEXMO_CALL_UUID);
9+
echo json_encode($call->toArray());
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
<?php
1+
<?php
22
require_once __DIR__ . '/../../config.php';
33
require_once __DIR__ . '/../../vendor/autoload.php';
44

55
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
66
$client = new \Nexmo\Client($keypair);
77

8-
$filter = new \Nexmo\Call\Filter();
9-
$filter->setStart(new DateTime('- 1 day'));
10-
$filter->setEnd(new DateTime);
8+
$filter = new \Nexmo\Voice\Filter\VoiceFilter();
9+
$filter->setDateStart(new DateTime('-1 Day'));
10+
$filter->setDateEnd(new DateTime());
1111

12-
foreach ($client->calls($filter) as $call){
13-
echo json_encode($call).PHP_EOL;
12+
/** @var \Nexmo\Voice\Call $call */
13+
foreach ($client->voice()->search($filter) as $call) {
14+
echo json_encode($call->toArray()) . PHP_EOL;
1415
}

0 commit comments

Comments
 (0)