Skip to content

Commit f8582d2

Browse files
authored
Merge pull request #166 from Nexmo/ncco-param-create-call
Add NCCO parameter support for PHP
2 parents 29f6856 + 1b41572 commit f8582d2

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,27 @@ $client->calls()->create([
321321
]);
322322
```
323323

324+
Or you can provide an NCCO directly in the POST request
325+
326+
```
327+
$call = $client->calls()->create([
328+
'to' => [[
329+
'type' => 'phone',
330+
'number' => '14843331234'
331+
]],
332+
'from' => [
333+
'type' => 'phone',
334+
'number' => '14843335555'
335+
],
336+
'ncco' => [
337+
[
338+
'action' => 'talk',
339+
'text' => 'This is a text to speech call from Nexmo'
340+
]
341+
]
342+
]);
343+
```
344+
324345
Or you can create a `Nexmo\Call\Call` object, and use that:
325346

326347
```php
@@ -334,6 +355,23 @@ $call->setTo('14843331234')
334355
$client->calls()->create($call);
335356
```
336357

358+
The same example, providing an NCCO directly:
359+
360+
```php
361+
use Nexmo\Call\Call;
362+
$call = new Call();
363+
$call->setTo('14843331234')
364+
->setFrom('14843335555')
365+
->setNcco([
366+
[
367+
'action' => 'talk',
368+
'text' => 'This is a text to speech call from Nexmo'
369+
]
370+
]);
371+
372+
$client->calls()->create($call);
373+
```
374+
337375
### Fetching a Call
338376

339377
You can fetch a call using a `Nexmo\Call\Call` object, or the call's UUID as a string:
@@ -594,6 +632,7 @@ API Coverage
594632
* [X] Campaign Subscription Management
595633
* Voice
596634
* [X] Outbound Call
635+
* [X] Outbound Call with an NCCO
597636
* [X] Inbound Call
598637
* [X] Text-To-Speech Call
599638
* [X] Text-To-Speech Prompt

src/Call/Call.php

+5
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public function setTimeout($type, $length)
195195
$this->data[$type . '_timeout'] = $length;
196196
}
197197

198+
public function setNcco($ncco) {
199+
$this->data['ncco'] = $ncco;
200+
return $this;
201+
}
202+
198203
public function getStatus()
199204
{
200205
if($this->lazyLoad()){

test/Call/CollectionTest.php

+59
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ public function testCreatePostCall($payload, $method)
135135
$this->assertInstanceOf('Nexmo\Call\Call', $call);
136136
$this->assertEquals('e46fd8bd-504d-4044-9600-26dd18b41111', $call->getId());
137137
}
138+
139+
/**
140+
* @dataProvider postCallNcco
141+
*/
142+
public function testCreatePostCallNcco($payload)
143+
{
144+
$this->nexmoClient->send(Argument::that(function(RequestInterface $request) use ($payload){
145+
$ncco = [['action' => 'talk', 'text' => 'Hello World']];
146+
147+
$this->assertRequestUrl('api.nexmo.com', '/v1/calls', 'POST', $request);
148+
$this->assertRequestBodyIsJson(json_encode($payload), $request);
149+
$this->assertRequestJsonBodyContains('ncco', $ncco, $request);
150+
return true;
151+
}))->willReturn($this->getResponse('created', '201'));
152+
153+
$call = $this->collection->post($payload);
154+
155+
$this->assertInstanceOf('Nexmo\Call\Call', $call);
156+
$this->assertEquals('e46fd8bd-504d-4044-9600-26dd18b41111', $call->getId());
157+
}
138158

139159
/**
140160
* @dataProvider postCall
@@ -228,6 +248,45 @@ public function getCall()
228248
];
229249
}
230250

251+
/**
252+
* Creating a call with an NCCO can take a Call object or a simple array.
253+
* @return array
254+
*/
255+
public function postCallNcco()
256+
{
257+
$raw = [
258+
'to' => [[
259+
'type' => 'phone',
260+
'number' => '14843331234'
261+
]],
262+
'from' => [
263+
'type' => 'phone',
264+
'number' => '14843335555'
265+
],
266+
'ncco' => [
267+
[
268+
'action' => 'talk',
269+
'text' => 'Hello World'
270+
]
271+
]
272+
];
273+
274+
275+
$call = new Call();
276+
$call->setTo('14843331234')
277+
->setFrom('14843335555')
278+
->setNcco([
279+
[
280+
'action' => 'talk',
281+
'text' => 'Hello World'
282+
]
283+
]);
284+
285+
return [
286+
'object' => [clone $call],
287+
'array' => [$raw]
288+
];
289+
}
231290
/**
232291
* Creating a call can take a Call object or a simple array.
233292
* @return array

0 commit comments

Comments
 (0)