Skip to content

Simple Record

A simple application that plays a prompt message to an answered inbound or outbound call, plays a beep, then records a message, before playing a final message and hanging up.

Uses actions: Play, Record

{
    "actions" :
    [
        {
            "play" :
            {
                "play_list" :
                [
                    {
                        "text_to_say" : "Please leave a message after the beep. Press hash to end the recording."
                    }
                ]
            }
        },
        {
            "record" :
            {
                "beep_on_start" : true,
                "barge_in_digits" : "#",
                "milliseconds_max_silence" : 5000,
                "next_page" :
                {
                    "url" : "Acknowledgement"
                }
            }
        }
    ],
    "token" : "my record instance id",
    "api_version": "2.0"
}
{
    "actions" :
    [
        {
            "play" :
            {
                "play_list" :
                [
                    {
                        "text_to_say" : "Thanks for leaving a recording. Goodbye."
                    }
                ]
            }
        }
    ],
    "token" : "my record instance id",
    "api_version": "2.0"
}
{
    "actions" :
    [
        {
            "play" :
            {
                "play_list" :
                [
                    {
                        "text_to_say" : "No message was recorded. Goodbye."
                    }
                ]
            }
        },
        {
            "delete_file":
            {
                "filename": "/rest_api/recordings/2018/10/06/rest_16_39_23_058d242936dcc5f9.4460.wav"
            }
        }
    ],
    "token" : "my record instance id",
    "api_version": "2.0"
}
{
    [
    ],
    "token" : "Error for Action: xxxx  ActionIndex: xxxx  Result: xxxx"
}
{
}

Implementing this sample as an ASP.Net Web application:

// CSharp Wrapper sample for the Aculab Telephony REST API.
//
// Simple Record:
// A simple application that plays a prompt message to an answered inbound call, 
// plays a beep, then records a message from the caller, before playing 
// a final message and hanging up.

using System;
using System.Collections.Generic;
using Aculab.Cloud.RestAPIWrapper;

public partial class SimpleRecord : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(Request);
        String callFrom = ourRequest.InstanceInfo.ThisCall.CallFrom;

        // Setup the actions
        List<TelephonyAction> actions = new List<TelephonyAction>
        {
            Play.SayText("Please leave a message after the beep. Press hash to end the recording.")
        };
        Record recordAction = new Record(new WebPageRequest("Acknowledgement.aspx"))
        {
            BeepOnStart = true,
            BargeInDigits = "#",
            MillisecondsMaxSilence = 5000
        };
        actions.Add(recordAction);

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(actions, "my record instance id");
        ourResponse.ToHttpResponse(Response);
    }
}
// CSharp Wrapper sample for the Aculab Telephony REST API.
//
// A page from the Simple Record sample:
// This acknowledges the completion of the recording.
using System;
using System.Collections.Generic;
using Aculab.Cloud.RestAPIWrapper;

public partial class Acknowledgement : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(Request);
        String token = ourRequest.InstanceInfo.Token;
        RecordResult result = (RecordResult)ourRequest.InstanceInfo.ActionResult;

        // Access the name of the recorded file
        String recordedFilename = result.Filename;

        // Setup the actions
        List<TelephonyAction> actions = new List<TelephonyAction>();
        if (result.ContainsSound)
        {
            actions.Add(Play.SayText("Thanks for leaving a recording. Goodbye."));
        }
        else
        {
            actions.Add(Play.SayText("No message was recorded. Goodbye."));
            actions.Add(new DeleteFile(result.Filename));
        }

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
        ourResponse.ToHttpResponse(Response);
    }
}
using System;
using Aculab.Cloud.RestAPIWrapper;

public partial class ErrorPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(Request);
        ErrorResult result = ourRequest.InstanceInfo.ErrorResult;

        String token = String.Format("Action: {0}\nActionIndex: {1}\nResult: {2}",
            result.Action, result.ActionIndex, result.Result);

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(null, token);
        ourResponse.ToHttpResponse(Response);
    }
}
using System;
using Aculab.Cloud.RestAPIWrapper;

public partial class FinalPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(Request);
    }
}

Implementing this sample as an ASP.Net Core Web application:

// ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.
//
// Simple Record:
// A simple application that plays a prompt message to an answered inbound call, 
// plays a beep, then records a message from the caller, before playing 
// a final message and hanging up.

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Aculab.Cloud.RestAPIWrapper;
using System.Net;
using System.Threading.Tasks;

namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
{
    [Route("SimpleRecord")]
    public class SimpleRecordController : ControllerBase
    {
        // Process the GET or POST request, set up the actions and construct the json response.
        [Route("FirstPage")]
        [HttpGet]
        [HttpPost]
        [ProducesResponseType(200)]
        [ProducesResponseType(400)]
        [ProducesResponseType(500)]
        public async Task<IActionResult> SimpleStartTranscription()
        {
            try
            {
                // Unpack the request
                var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                String callFrom = telephonyRequest.InstanceInfo.ThisCall.CallFrom;

                // Setup the actions required
                List<TelephonyAction> actions = new List<TelephonyAction>();
                actions.Add(Play.SayText("Please leave a message after the beep. Press hash to end the recording."));
                Record recordAction = new Record(new WebPageRequest("SimpleRecord/Acknowledgement"))
                {
                    BeepOnStart = true,
                    BargeInDigits = "#",
                    MillisecondsMaxSilence = 5000
                };
                actions.Add(recordAction);

                // Create response
                TelephonyResponse ourResponse = new TelephonyResponse(actions, "my record instance id");
                return new OkObjectResult(ourResponse.ToJson(this));
            }
            catch (ArgumentException)
            {
                return BadRequest();
            }
            catch (Exception e)
            {
                return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
            }
    }
}
// ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.
//
// Simple Record:
// A simple application that plays a prompt message to an answered inbound call, 
// plays a beep, then records a message from the caller, before playing 
// a final message and hanging up.

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Aculab.Cloud.RestAPIWrapper;
using System.Net;
using System.Threading.Tasks;

namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
{
    [Route("SimpleRecord")]
    public class SimpleRecordController : ControllerBase
    {
        [Route("Acknowledgement")]
        [HttpGet]
        [HttpPost]
        [ProducesResponseType(200)]
        [ProducesResponseType(400)]
        [ProducesResponseType(500)]
        // Process the request, set up the play actions and construct the json response.
        public async Task<IActionResult> Acknowledgement()
        {
            try
            {
                // Unpack the request
                var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                String token = telephonyRequest.InstanceInfo.Token;
                RecordResult result = (RecordResult)telephonyRequest.InstanceInfo.ActionResult;

                // Access the name of the recorded file
                String recordedFilename = result.Filename;

                // Setup the actions required
                List<TelephonyAction> actions = new List<TelephonyAction>();
                if (result.ContainsSound)
                {
                    actions.Add(Play.SayText("Thanks for leaving a recording. Goodbye."));
                }
                else
                {
                    actions.Add(Play.SayText("No message was recorded. Goodbye."));
                    actions.Add(new DeleteFile(result.Filename));
                }

                // Create response
                TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
                return new OkObjectResult(ourResponse.ToJson(this));
            }
            catch (ArgumentException)
            {
                return BadRequest();
            }
            catch (Exception e)
            {
                return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
            }
        }
    }
}
// ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.

using System;
using Microsoft.AspNetCore.Mvc;
using Aculab.Cloud.RestAPIWrapper;
using System.Net;
using System.Threading.Tasks;

namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
{
    public class RESTSampleController : ControllerBase
    {
        // Process the GET or POST request for the Error condition
        [Route("ErrorPage")]
        [HttpGet]
        [HttpPost]
        [ProducesResponseType(200)]
        [ProducesResponseType(400)]
        [ProducesResponseType(500)]
        public async Task<IActionResult> ErrorPage()
        {
            try
            {
                // Unpack the request
                var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                ErrorResult result = telephonyRequest.InstanceInfo.ErrorResult;

                String token = String.Format("Action: {0}\nActionIndex: {1}\nResult: {2}",
                    result.Action, result.ActionIndex, result.Result);

                // Create response
                TelephonyResponse ourResponse = new TelephonyResponse(null, token);
                return new OkObjectResult(ourResponse.ToJson(this));
            }
            catch (ArgumentException)
            {
                return BadRequest();
            }
            catch (Exception e)
            {
                return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
            }
        }
    }
}
// ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.

using System;
using Microsoft.AspNetCore.Mvc;
using Aculab.Cloud.RestAPIWrapper;
using System.Net;
using System.Threading.Tasks;

namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
{
    public class RESTSampleController : ControllerBase
    {
        // Process the GET or POST request for the Final Page
        [Route("FinalPage")]
        [HttpGet]
        [HttpPost]
        [ProducesResponseType(200)]
        [ProducesResponseType(400)]
        [ProducesResponseType(500)]
        public async Task<IActionResult> FinalPage()
        {
            try
            {
                // Unpack the request
                var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                String token = telephonyRequest.InstanceInfo.Token;

                // Create response
                // Only very limited actions can be returned here
                TelephonyResponse ourResponse = new TelephonyResponse(null, token);
                return new OkObjectResult(ourResponse.ToJson(this));
            }
            catch (ArgumentException)
            {
                return BadRequest();
            }
            catch (Exception e)
            {
                return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
            }
        }
    }
}

Implemented as ASP.Net Web App:

' Visual Basic Wrapper sample for the Aculab Telephony REST API.
'
' The first page for the Simple Record sample:
' A simple application that plays a prompt message to an answered inbound call, 
' plays a beep, then records a message from the caller, before playing 
' a final message and hanging up.
Imports System.Collections.Generic
Imports Aculab.Cloud.RestAPIWrapper

Partial Class SimpleRecord
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        ' Unpack the request
        Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)
        Dim callFrom As String = ourRequest.InstanceInfo.ThisCall.CallFrom

        ' Setup the actions
        Dim actions As List(Of TelephonyAction) = New List(Of TelephonyAction)
        actions.Add(Play.SayText("Please leave a message after the beep. Press hash to end the recording."))
        Dim recordAction As Record = New Record(New WebPageRequest("Acknowledgement.aspx"))
        recordAction.BeepOnStart = True
        recordAction.BargeInDigits = "#"
        recordAction.MillisecondsMaxSilence = 5000
        actions.Add(recordAction)

        ' Respond
        Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, "my record instance id")
        ourResponse.ToHttpResponse(Response)
    End Sub
End Class
' Visual Basic Wrapper sample for the Aculab Telephony REST API.
'
' A page from the Simple Record sample:
' This acknowledges the completion of the recording.
Imports System.Collections.Generic
Imports Aculab.Cloud.RestAPIWrapper

Partial Class Acknowledgement
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        ' Unpack the request
        Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)

        ' Get interrupt details from the action result.
        Dim previousAction As String = ourRequest.InstanceInfo.ActionResult.Action
        Dim interrupted As Boolean = ourRequest.InstanceInfo.ActionResult.Interrupted

        Dim token As String = ourRequest.InstanceInfo.Token
        Dim result As RecordResult = ourRequest.InstanceInfo.ActionResult

        ' Access the name of the recorded file
        Dim recordedFilename As String = result.Filename

        ' Setup the actions
        Dim actions As List(Of TelephonyAction) = New List(Of TelephonyAction)
        If (result.ContainsSound) Then
            actions.Add(Play.SayText("Thanks for leaving a recording. Goodbye."))
        Else
            actions.Add(Play.SayText("No message was recorded. Goodbye."))
            actions.Add(New DeleteFile(result.Filename))
        End If

        ' Respond
        Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, token)
        ourResponse.ToHttpResponse(Response)
    End Sub
End Class
' Visual Basic Wrapper sample for the Aculab Telephony REST API.
'
' A generic error page for all the samples.
Imports Aculab.Cloud.RestAPIWrapper

Partial Class ErrorPage
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        ' Unpack the request
        Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)
        Dim result As ErrorResult = ourRequest.InstanceInfo.ErrorResult

        Dim token As String = String.Format("Action: {0}\nActionIndex: {1}\nResult: {2}", _
            result.Action, result.ActionIndex, result.Result)

        ' Respond
        Dim ourResponse As TelephonyResponse = New TelephonyResponse(token)
        ourResponse.ToHttpResponse(Response)
    End Sub
End Class
' Visual Basic Wrapper sample for the Aculab Telephony REST API.
'
' A generic final page for all the samples:
Imports Aculab.Cloud.RestAPIWrapper

Partial Class FinalPage
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        ' Unpack the request
        Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)

        ' Do application tidying up
        ' ...
    End Sub
End Class

Implemented as Java Servlets:

// Java Servlet sample for the Aculab Telephony REST API.
//
// Simple Record:
// A simple application that plays a prompt message to an answered inbound call, 
// plays a beep, then records a message from the caller, before playing 
// a final message and hanging up.

package com.aculab.telephonyrestapi.samples;

import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.aculab.telephonyrestapi.*;

public class SimpleRecord extends HttpServlet
{
    private static final long serialVersionUID = -5454932181483087489L;

    @Override
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request,
            HttpServletResponse response)
                    throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    private void handleRequest(HttpServletRequest request,
                               HttpServletResponse response) throws IOException
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(request);

        // Setup the actions
        List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
        actions.add(Play.sayText("Please leave a message after the beep. Press hash to end the recording."));
        Record recordAction = new Record(new WebPageRequest("Acknowledgement"));
        recordAction.setBeepOnStart(true);
        recordAction.setBargeInDigits("#");
        recordAction.setMillisecondsMaxSilence(5000);
        actions.add(recordAction);

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(actions, "my record instance id");
        ourResponse.setHttpServletResponse(response);
    }
}
// Java Servlet sample for the Aculab Telephony REST API.
//
// Simple Record:
// A simple application that plays a prompt message to an answered inbound call, 
// plays a beep, then records a message from the caller, before playing 
// a final message and hanging up.

package com.aculab.telephonyrestapi.samples;

import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.aculab.telephonyrestapi.*;

public class Acknowledgement extends HttpServlet
{
    private static final long serialVersionUID = -3340890064388962307L;

    @Override
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request,
            HttpServletResponse response)
                    throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    private void handleRequest(HttpServletRequest request,
                               HttpServletResponse response) throws IOException
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(request);

        String token = ourRequest.getInstanceInfo().getToken();
        RecordResult result = (RecordResult)ourRequest.getInstanceInfo().getActionResult();

        // Setup the actions
        List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
        if (result.containsSound())
        {
            actions.add(Play.sayText("Thanks for leaving a recording. Goodbye."));
        }
        else
        {
            actions.add(Play.sayText("No message was recorded. Goodbye."));
            actions.add(new DeleteFile(result.getFilename()));
        }

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
        ourResponse.setHttpServletResponse(response);
    }
}
// Java Servlet sample for the Aculab Telephony REST API.
//

package com.aculab.telephonyrestapi.samples;

import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.aculab.telephonyrestapi.*;

public class ErrorPage extends HttpServlet
{
    private static final long serialVersionUID = -4842873371047361437L;

    @Override
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request,
            HttpServletResponse response)
                    throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    private void handleRequest(HttpServletRequest request,
                               HttpServletResponse response) throws IOException
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(request);

        ErrorResult result = ourRequest.getInstanceInfo().getErrorResult();

        String token = String.format("Action: %s\nActionIndex: %d\nResult: %s", result.getAction(), result.getActionIndex(), result.getResult());

        // Respond
        List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
        TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
        ourResponse.setHttpServletResponse(response);
    }
}
// Java Servlet sample for the Aculab Telephony REST API.
//

package com.aculab.telephonyrestapi.samples;

import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import com.aculab.telephonyrestapi.*;

public class FinalPage extends HttpServlet
{
    private static final long serialVersionUID = 5940620014313056844L;

    @Override
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request,
            HttpServletResponse response)
                    throws IOException, ServletException
    {
        handleRequest(request, response);
    }

    private void handleRequest(HttpServletRequest request,
                               HttpServletResponse response) throws IOException
    {
        // Unpack the request
        TelephonyRequest ourRequest = new TelephonyRequest(request);
    }
}

Implemented as a Flask web application:

@app.route('/SimpleRecord', methods=['GET','POST'])
def handle_SimpleRecord():

    my_request = TelephonyRequest(request)
    app_inst_id = my_request.get_application_instance_id()
    print("SimpleRecord: app_inst_id='{}'".format(app_inst_id))

    record_action = Record(next_page=WebPage(url='Acknowledgement'),
                            beep_on_start=True,
                            barge_in_digits="#", 
                            milliseconds_max_silence=5000)

    list_of_actions = []
    # play a prompt and then record
    list_of_actions.append(Play(text_to_say='Please leave a message after the beep. Press hash to end the recording.'))
    list_of_actions.append(record_action)

    my_response = TelephonyResponse(list_of_actions, token='my record instance id')
    return Response(response=my_response.get_json(), content_type='application/json;charset=utf-8')
@app.route('/Acknowledgement', methods=['GET','POST'])
def handle_Acknowledgement():

    my_request = TelephonyRequest(request)
    my_token = my_request.get_token()
    action_result = my_request.get_action_result()

    record_result =  action_result.get("result")

    list_of_actions = []
    if record_result.get("contains_sound") == True:
        list_of_actions.append(Play(text_to_say='Thanks for leaving a recording. Goodbye.'))
        print ("Recorded file is {0}".format(record_result.get('filename')))
    else:
        list_of_actions.append(Play(text_to_say='No message was recorded. Goodbye.'))
        list_of_actions.append(DeleteFile(record_result.get("filename")))

    my_response = TelephonyResponse(list_of_actions, my_token)
    return Response(response=my_response.get_json(), content_type='application/json;charset=utf-8')
@app.route('/ErrorPage', methods=['GET','POST'])
def handle_ErrorPage():

    my_request = TelephonyRequest(request)
    token = my_request.get_token()
    app_inst_id = my_request.get_application_instance_id()
    error_result_dict = my_request.get_error_result()
    action_string = error_result_dict.get('action', "?")
    result_string = error_result_dict.get('result', "?")
    print("ErrorPage: app_inst_id='{}' token='{}' action='{}' result='{}'".format(app_inst_id, token, action_string, result_string))

    my_response = TelephonyResponse([Play(text_to_say='An error has occurred')])
    return Response(response=my_response.get_json(), content_type='application/json;charset=utf-8')
@app.route('/FinalPage', methods=['GET','POST'])
def handle_FinalPage():
    # The FinalPage handler follows the guidelines on:
    # https://www.aculab.com/cloud/voice-and-fax-apis/rest-api/rest-api-version-2/writing-a-rest-application
    # The guidelines are:
    #   "Your final page should return an empty response, a 204 is preferable, but empty JSON is acceptable."
    my_request = TelephonyRequest(request)
    token = my_request.get_token()
    app_inst_id = my_request.get_application_instance_id()
    print("FinalPage: app_inst_id='{}' token='{}'".format(app_inst_id, token))
    empty_json = '{}'.encode('utf-8')
    return Response(response=empty_json, status=204, content_type='application/json;charset=utf-8')
<?php
header("Content-Type: application/json; charset=UTF-8");

require __DIR__ . "/../../autoload.php";

use \Aculab\TelephonyRestAPI\Play;
use \Aculab\TelephonyRestAPI\Record;
use \Aculab\TelephonyRestAPI\Response;
use \Aculab\TelephonyRestAPI\WebPageRequest;

$response = new Response();
$response->setToken('my record instance id');

$play = new Play();
$play->addText('Please leave a message after the beep. Press hash to end the recording.');
$response->addAction($play);

$record = new Record(new WebPageRequest('Acknowledgement.php'));
$record->setBeepOnStart(true)
    ->setBargeInDigits('#')
    ->setMillisecondsMaxSilence(5000);

$response->addAction($record);

print $response;
?>
<?php
header("Content-Type: application/json; charset=UTF-8");

require __DIR__ . "/../../autoload.php";

use \Aculab\TelephonyRestAPI\Play;
use \Aculab\TelephonyRestAPI\DeleteFile;
use \Aculab\TelephonyRestAPI\Response;
use \Aculab\TelephonyRestAPI\InstanceInfo;

$info = InstanceInfo::getInstanceInfo();
$result = $info->getActionResult();

// get the recording filename
$filename = $result->getFilename();

$response = new Response();
$response->setToken($info->getToken());

if ($result->getContainsSound()) {
    $play = new Play();
    $play->addText('Thanks for leaving a recording. Goodbye.');
    $response->addAction($play);
    // add code to save the filename, e.g. in a database
} else {
    $play = new Play();
    $play->addText('No message was recorded. Goodbye.');
    $response->addAction($play);
    $response->addAction(new DeleteFile($filename));
}

print $response;
<?php
header("Content-Type: application/json; charset=UTF-8");

require __DIR__ . "/../../autoload.php";

use Aculab\TelephonyRestAPI\Play;
use Aculab\TelephonyRestAPI\Response;
use Aculab\TelephonyRestAPI\InstanceInfo;

$info = InstanceInfo::getInstanceInfo();

$error = $info->getErrorResult();
$action = $error->getAction();
$desc = $error->getResult();
if (!is_null($action)) {
    error_log("Error from action \"$action\" with result:" . PHP_EOL . "$desc" . PHP_EOL);
} else {
    error_log("Error result:" . PHP_EOL . "$desc" . PHP_EOL);
}

$response = new Response();
$response->setToken('Error');

$play = new Play();
$play->addText('An error has occurred.');
$response->addAction($play);

print $response;
<?php
require __DIR__ . "/../../autoload.php";

http_response_code(204);
header("Content-Type: application/json; charset=UTF-8");

use Aculab\TelephonyRestAPI\InstanceInfo;

$info = InstanceInfo::getInstanceInfo();
$call = $info->getThisCallInfo();
$callid = $call->getCallId();
$duration = $call->getSecondsCallDuration();
error_log("This call id: $callid" . PHP_EOL . "This call duration: $duration" . PHP_EOL);