From 08d01cddfebf1693b5f564e21cd95b876d9f3ae3 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Fri, 12 Apr 2019 15:55:54 +0100 Subject: [PATCH 1/2] Add NCCO parameter support for PHP --- src/Call/Call.php | 5 +++ test/Call/CollectionTest.php | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/Call/Call.php b/src/Call/Call.php index 49b24bd1..abcf45ae 100644 --- a/src/Call/Call.php +++ b/src/Call/Call.php @@ -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()){ diff --git a/test/Call/CollectionTest.php b/test/Call/CollectionTest.php index 61cec0f3..c6e43b04 100644 --- a/test/Call/CollectionTest.php +++ b/test/Call/CollectionTest.php @@ -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 @@ -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 From 1b41572491185c3080d6dbd992f33725474957fa Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Sat, 13 Apr 2019 11:03:39 +0100 Subject: [PATCH 2/2] Add Create NCCO example to README --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index c743cb56..b5f16fe0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: @@ -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