Skip to content

Commit d22a7c9

Browse files
author
Lorna Jane Mitchell
authored
Merge pull request Vonage#38 from Nexmo/transfer-call-with-ncco
Added example to update existing call with an NCCO
2 parents 7a4b89d + 7fc4e60 commit d22a7c9

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

.env-example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NEXMO_API_KEY=
22
NEXMO_API_SECRET=
3-
APPLICATION_ID=
4-
PRIVATE_KEY=
3+
NEXMO_APPLICATION_ID=
4+
NEXMO_APPLICATION_PRIVATE_KEY_PATH=
55
FROM=
66
NEXMO_TO_NUMBER=
77
RECIPIENT_NUMBER=
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../../config.php';
4+
require_once __DIR__ . '/../../vendor/autoload.php';
5+
6+
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH), NEXMO_APPLICATION_ID);
7+
$client = new \Nexmo\Client($keypair);
8+
9+
if (count($argv) != 2) {
10+
error_log("You must supply a UUID of currently connected call to update");
11+
exit(1);
12+
}
13+
14+
$uuid = $argv[1];
15+
16+
try {
17+
$client->calls[$uuid]->put([
18+
'action' => 'transfer',
19+
'destination' => [
20+
'type' => 'ncco',
21+
'ncco' => [[
22+
'action' => 'talk',
23+
'text' => 'This call was transferred'
24+
]],
25+
]
26+
]);
27+
} catch (\Nexmo\Client\Exception\Request $e) {
28+
error_log("Client error: " . $e->getMessage());
29+
exit(1);
30+
} catch (\Nexmo\Client\Exception\Server $e) {
31+
error_log("Server error: " . $e->getMessage());
32+
exit(1);
33+
}
34+

0 commit comments

Comments
 (0)