Skip to content

Commit

Permalink
Merge pull request #166 from Nexmo/ncco-param-create-call
Browse files Browse the repository at this point in the history
Add NCCO parameter support for PHP
  • Loading branch information
lornajane authored Apr 13, 2019
2 parents 29f6856 + 1b41572 commit f8582d2
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,27 @@ $client->calls()->create([
]);
```

Or you can provide an NCCO directly in the POST request

```
$call = $client->calls()->create([
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'ncco' => [
[
'action' => 'talk',
'text' => 'This is a text to speech call from Nexmo'
]
]
]);
```

Or you can create a `Nexmo\Call\Call` object, and use that:

```php
Expand All @@ -334,6 +355,23 @@ $call->setTo('14843331234')
$client->calls()->create($call);
```

The same example, providing an NCCO directly:

```php
use Nexmo\Call\Call;
$call = new Call();
$call->setTo('14843331234')
->setFrom('14843335555')
->setNcco([
[
'action' => 'talk',
'text' => 'This is a text to speech call from Nexmo'
]
]);

$client->calls()->create($call);
```

### Fetching a Call

You can fetch a call using a `Nexmo\Call\Call` object, or the call's UUID as a string:
Expand Down Expand Up @@ -594,6 +632,7 @@ API Coverage
* [X] Campaign Subscription Management
* Voice
* [X] Outbound Call
* [X] Outbound Call with an NCCO
* [X] Inbound Call
* [X] Text-To-Speech Call
* [X] Text-To-Speech Prompt
Expand Down
5 changes: 5 additions & 0 deletions src/Call/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public function setTimeout($type, $length)
$this->data[$type . '_timeout'] = $length;
}

public function setNcco($ncco) {
$this->data['ncco'] = $ncco;
return $this;
}

public function getStatus()
{
if($this->lazyLoad()){
Expand Down
59 changes: 59 additions & 0 deletions test/Call/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ public function testCreatePostCall($payload, $method)
$this->assertInstanceOf('Nexmo\Call\Call', $call);
$this->assertEquals('e46fd8bd-504d-4044-9600-26dd18b41111', $call->getId());
}

/**
* @dataProvider postCallNcco
*/
public function testCreatePostCallNcco($payload)
{
$this->nexmoClient->send(Argument::that(function(RequestInterface $request) use ($payload){
$ncco = [['action' => 'talk', 'text' => 'Hello World']];

$this->assertRequestUrl('api.nexmo.com', '/v1/calls', 'POST', $request);
$this->assertRequestBodyIsJson(json_encode($payload), $request);
$this->assertRequestJsonBodyContains('ncco', $ncco, $request);
return true;
}))->willReturn($this->getResponse('created', '201'));

$call = $this->collection->post($payload);

$this->assertInstanceOf('Nexmo\Call\Call', $call);
$this->assertEquals('e46fd8bd-504d-4044-9600-26dd18b41111', $call->getId());
}

/**
* @dataProvider postCall
Expand Down Expand Up @@ -228,6 +248,45 @@ public function getCall()
];
}

/**
* Creating a call with an NCCO can take a Call object or a simple array.
* @return array
*/
public function postCallNcco()
{
$raw = [
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'ncco' => [
[
'action' => 'talk',
'text' => 'Hello World'
]
]
];


$call = new Call();
$call->setTo('14843331234')
->setFrom('14843335555')
->setNcco([
[
'action' => 'talk',
'text' => 'Hello World'
]
]);

return [
'object' => [clone $call],
'array' => [$raw]
];
}
/**
* Creating a call can take a Call object or a simple array.
* @return array
Expand Down

0 comments on commit f8582d2

Please sign in to comment.