@@ -260,20 +260,149 @@ $outboundCall
260260$response = $client->voice()->createOutboundCall($outboundCall);
261261```
262262
263- Or you can provide an NCCO directly in the POST request
263+ ### Building a call with NCCO Actions
264264
265+ Full parameter lists for NCCO Actions can be found in the [ Voice API Docs] ( https://developer.nexmo.com/voice/voice-api/ncco-reference ) .
266+
267+ Each of these examples uses the following structure to add actions to a call:
268+
269+ ``` php
270+ $outboundCall = new \Vonage\Voice\OutboundCall(
271+ new \Vonage\Voice\Endpoint\Phone('14843331234'),
272+ new \Vonage\Voice\Endpoint\Phone('14843335555')
273+ );
274+ $ncco = new NCCO();
275+
276+ //ADD ACTIONS TO THE NCCO OBJECT HERE
277+
278+ $outboundCall->setNCCO($ncco);
279+
280+ $response = $client->voice()->createOutboundCall($outboundCall);
281+ ```
282+
283+ ### Record a call
284+
285+ ``` php
286+ $outboundCall = new \Vonage\Voice\OutboundCall(
287+ new \Vonage\Voice\Endpoint\Phone('14843331234'),
288+ new \Vonage\Voice\Endpoint\Phone('14843335555')
289+ );
290+
291+ $ncco = new NCCO();
292+ $record = new \Vonage\Voice\NCCO\Action\Record;
293+ $ncco->addAction($record->factory([
294+ 'eventUrl' => 'https://webhook.url'
295+ ]);
296+ $outboundCall->setNCCO($ncco);
297+
298+ $response = $client->voice()->createOutboundCall($outboundCall);
299+ ```
300+
301+ Your webhook url will receive a payload like this:
302+
303+ ```
304+ {
305+ "start_time": "2020-10-29T14:30:24Z",
306+ "recording_url": "https://api.nexmo.com/v1/files/<recording-id>",
307+ "size": 27918,
308+ "recording_uuid": "<recording-id>",
309+ "end_time": "2020-10-29T14:30:31Z",
310+ "conversation_uuid": "<conversation-id>",
311+ "timestamp": "2020-10-29T14:30:31.619Z"
312+ }
313+ ```
314+
315+ You can then fetch and store the recording like this:
316+
317+ ```
318+ $recordingId = '<recording-id>';
319+ $recordingUrl = 'https://api.nexmo.com/v1/files/' . $recordingId;
320+ $data = $client->get($recordingUrl);
321+ file_put_contents($recordingId.'.mp3', $data->getBody());
322+ ```
323+
324+ ### Send a text to voice call
265325``` php
266326$outboundCall = new \Vonage\Voice\OutboundCall(
267327 new \Vonage\Voice\Endpoint\Phone('14843331234'),
268328 new \Vonage\Voice\Endpoint\Phone('14843335555')
269329);
330+
270331$ncco = new NCCO();
271332$ncco->addAction(new \Vonage\Voice\NCCO\Action\Talk('This is a text to speech call from Vonage'));
272333$outboundCall->setNCCO($ncco);
273334
274335$response = $client->voice()->createOutboundCall($outboundCall);
275336```
276337
338+ ### Stream an audio file on a call
339+ ``` php
340+ $outboundCall = new \Vonage\Voice\OutboundCall(
341+ new \Vonage\Voice\Endpoint\Phone('14843331234'),
342+ new \Vonage\Voice\Endpoint\Phone('14843335555')
343+ );
344+
345+ $ncco = new NCCO();
346+ $ncco->addAction(new \Vonage\Voice\NCCO\Action\Stream('https://my-mp3.url'));
347+ $outboundCall->setNCCO($ncco);
348+
349+ $response = $client->voice()->createOutboundCall($outboundCall);
350+ ```
351+
352+ ### Collect user input from a call
353+
354+ Supports keypad entry as well as voice. NB. the input action must follow an action with ` bargeIn ` set to ` true `
355+
356+ ``` php
357+ $outboundCall = new \Vonage\Voice\OutboundCall(
358+ new \Vonage\Voice\Endpoint\Phone('14843331234'),
359+ new \Vonage\Voice\Endpoint\Phone('14843335555')
360+ );
361+
362+ $ncco = new NCCO();
363+
364+ $talk = new \Vonage\Voice\NCCO\Action\Talk;
365+ $ncco->addAction($talk->factory('Please record your name.',[
366+ 'bargeIn' => true,
367+ ]));
368+
369+ $input = new \Vonage\Voice\NCCO\Action\Input;
370+ $ncco->addAction($input->factory([
371+ 'eventUrl' => 'https://webhook.url',
372+ 'type' => [
373+ 'speech',
374+ ],
375+ 'speech' => [
376+ 'endOnSilence' => true,
377+ ],
378+ ]));
379+
380+ $outboundCall->setNCCO($ncco);
381+
382+ $response = $client->voice()->createOutboundCall($outboundCall);
383+ ```
384+
385+ The webhook URL will receive a payload containing the input from the user with relative confidence ratings for speech input.
386+
387+ ### Send a notification to a webhook url
388+
389+ ``` php
390+ $outboundCall = new \Vonage\Voice\OutboundCall(
391+ new \Vonage\Voice\Endpoint\Phone('14843331234'),
392+ new \Vonage\Voice\Endpoint\Phone('14843335555')
393+ );
394+
395+ $ncco = new NCCO();
396+ $ncco->addAction(new \Vonage\Voice\NCCO\Action\Talk('We are just testing the notify function, you do not need to do anything.'));
397+ $ncco->addAction(new \Vonage\Voice\NCCO\Action\Notify([
398+ 'foo' => 'bar',
399+ ], new Vonage\Voice\Webhook('https://webhook.url')));
400+ $outboundCall->setNCCO($ncco);
401+
402+ $response = $client->voice()->createOutboundCall($outboundCall);
403+ ```
404+ The webhook URL will receive a payload as specified in the request.
405+
277406### Fetching a Call
278407
279408You can fetch a call using a ` Vonage\Call\Call ` object, or the call's UUID as a string:
0 commit comments