Skip to content

Simple Receive Fax

A simple inbound application that starts a fax session on an inbound call and receives a fax to a tif file.

A progress page is set so that the application can present the negotiated fax settings and a page count after each page has been received. A next page is set so that the application can present the fax termination result and the name of the tif file.
Note, the progress page is expected to respond with a status of 204 No Content.

Uses actions: Receive Fax

{
    "actions" :
    [
        {
            "receive_fax" :
            {
                "next_page"  :
                {
                    "url"    : "ReceiveFaxComplete",
                    "method" : "Post"
                },
                "progress_page":
                {
                    "url"    : "ReceiveFaxProgress",
                    "method" : "Post"
                }
            }
        }
    ],
    "token" : "my instance id",
    "api_version": "2.0"
}
{
    "actions" :
    [
    ],
    "token" : "my 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 Receive Fax:
// A simple application that receives a fax from an answered inbound call.
// It requests progress notifications while the fax is being received and a call 
// to a next page when the fax receiving completes.

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

public partial class SimpleReceiveFax : 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;

        // Setup the actions
        List<TelephonyAction> actions = new List<TelephonyAction>
        {
            new ReceiveFax(new WebPageRequest("ReceiveFaxComplete.aspx"), new WebPageRequest("ReceiveFaxProgress.aspx"))
        };

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
        ourResponse.ToHttpResponse(Response);
    }
}
// CSharp Wrapper sample for the Aculab Telephony REST API.
//
// A page from the Simple Receive Fax sample:
// This receives notifications of the progress of the fax receiving.

using System;
using System.Net;
using Aculab.Cloud.RestAPIWrapper;

public partial class ReceiveFaxProgress : 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;
        Aculab.Cloud.RestAPIWrapper.ReceiveFaxProgress progress = (Aculab.Cloud.RestAPIWrapper.ReceiveFaxProgress)ourRequest.InstanceInfo.ActionProgress;

        // Add your own code here to use the progress information.
        // e.g. update a database, write to a log...
        int pagesReceived = progress.PagesReceived;

        // Respond
        Response.StatusCode = (int)HttpStatusCode.NoContent;
    }
}
// CSharp Wrapper sample for the Aculab Telephony REST API.
//
// A page from the Simple Receive Fax sample:
// This is called when the fax receiving has completed.

using System;
using Aculab.Cloud.RestAPIWrapper;

public partial class ReceiveFaxComplete : 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;
        ReceiveFaxResult result = (ReceiveFaxResult)ourRequest.InstanceInfo.ActionResult;

        // Add your own code here to use the result information.
        // e.g. update a database, write to a log...
        int pagesReceived = result.PagesReceived;
        String faxFilename = result.FaxFilename;

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(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:

// CSharp Wrapper sample for the Aculab Telephony REST API.
//
// Simple Receive Fax:
// A simple application that receives a fax from an answered inbound call.
// It requests progress notifications while the fax is being received and a call 
// to a next page when the fax receiving completes.

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("SimpleReceiveFax")]
    public class SimpleReceiveFaxController : 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> SimpleReceiveFax()
        {
            try
            {
                // Unpack the request
                var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                String token = telephonyRequest.InstanceInfo.Token;

                // Setup the actions required
                List<TelephonyAction> actions = new List<TelephonyAction>();
                actions.Add(new ReceiveFax(new WebPageRequest("SimpleReceiveFax/ReceiveFaxComplete"), 
                                           new WebPageRequest("SimpleReceiveFax/ReceiveFaxProgress")));

                // 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);
            }
        }
    }
}
// CSharp Wrapper sample for the Aculab Telephony REST API.
//
// Simple Receive Fax:
// A simple application that receives a fax from an answered inbound call.
// It requests progress notifications while the fax is being received and a call 
// to a next page when the fax receiving completes.

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("SimpleReceiveFax")]
    public class SimpleReceiveFaxController : ControllerBase
    {
        // Process the GET or POST progress request.
        [Route("ReceiveFaxProgress")]
        [HttpGet]
        [HttpPost]
        [ProducesResponseType(200)]
        [ProducesResponseType(400)]
        [ProducesResponseType(500)]
        public async Task<IActionResult> ReceiveFaxProgress()
        {
            try
            {
                // Unpack the request
                var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                String token = telephonyRequest.InstanceInfo.Token;
                RestAPIWrapper.ReceiveFaxProgress progress = (RestAPIWrapper.ReceiveFaxProgress)telephonyRequest.InstanceInfo.ActionProgress;

                // Add your own code here to use the progress information.
                // e.g. update a database, write to a log...
                int pagesReceived = progress.PagesReceived;

                // Respond with no content
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            catch (ArgumentException)
            {
                return BadRequest();
            }
            catch (Exception e)
            {
                return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
            }
        }
    }
}
// CSharp Wrapper sample for the Aculab Telephony REST API.
//
// Simple Receive Fax:
// A simple application that receives a fax from an answered inbound call.
// It requests progress notifications while the fax is being received and a call 
// to a next page when the fax receiving completes.

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("SimpleReceiveFax")]
    public class SimpleReceiveFaxController : ControllerBase
    {
        // Process the GET or POST request, set up the actions and construct the json response.
        [Route("ReceiveFaxComplete")]
        [HttpGet]
        [HttpPost]
        [ProducesResponseType(200)]
        [ProducesResponseType(400)]
        [ProducesResponseType(500)]
        public async Task<IActionResult> ReceiveFaxComplete()
        {
            try
            {
                // Unpack the request
                var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                String token = telephonyRequest.InstanceInfo.Token;
                ReceiveFaxResult result = (ReceiveFaxResult)telephonyRequest.InstanceInfo.ActionResult;

                // Add your own code here to use the result information.
                // e.g. update a database, write to a log...
                int pagesReceived = result.PagesReceived;
                String faxFilename = result.FaxFilename;

                // Create response
                TelephonyResponse ourResponse = new TelephonyResponse(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 Receive Fax sample:
' A simple application that receives a fax from an answered inbound call.
' It requests progress notifications while the fax is being received and a call 
' to a next page when the fax receiving completes.
Imports System.Collections.Generic
Imports Aculab.Cloud.RestAPIWrapper

Partial Class SimpleReceiveFax
    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)

        ' Setup the actions
        Dim actions As List(Of TelephonyAction) = New List(Of TelephonyAction)
        actions.Add(New ReceiveFax(New WebPageRequest("ReceiveFaxComplete.aspx"), New WebPageRequest("ReceiveFaxProgress.aspx")))

        ' Respond
        Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, "my instance id")
        ourResponse.ToHttpResponse(Response)
    End Sub
End Class
' Visual Basic Wrapper sample for the Aculab Telephony REST API.
'
' A page from the Simple Receive Fax sample:
' This receives notifications of the progress of the fax receiving.
Imports System.Net
Imports Aculab.Cloud.RestAPIWrapper

Partial Class ReceiveFaxProgress
    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 token As String = ourRequest.InstanceInfo.Token
        Dim progress As Aculab.Cloud.RestAPIWrapper.ReceiveFaxProgress = ourRequest.InstanceInfo.ActionProgress

        ' Add your own code here to use the progress information.
        ' e.g. update a database, write to a log...
        Dim pagesReceived As Integer = progress.PagesReceived

        ' Respond
        Response.StatusCode = HttpStatusCode.NoContent
    End Sub
End Class
' Visual Basic Wrapper sample for the Aculab Telephony REST API.
'
' A page from the Simple Receive Fax sample:
' This is called when the fax receiving has completed.
Imports Aculab.Cloud.RestAPIWrapper

Partial Class ReceiveFaxComplete
    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 token As String = ourRequest.InstanceInfo.Token
        Dim result As ReceiveFaxResult = ourRequest.InstanceInfo.ActionResult

        ' Add your own code here to use the result information.
        ' e.g. update a database, write to a log...
        Dim pagesReceived As Integer = result.PagesReceived
        Dim faxFilename As String = result.FaxFilename

        ' 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 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 Receive Fax:
// A simple application that receives a fax from an answered inbound call.
// It requests progress notifications while the fax is being received and a call 
// to a next page when the fax receiving completes.

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 SimpleReceiveFax extends HttpServlet
{
    private static final long serialVersionUID = 7808170260824303032L;

    @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();

        // Set up the actions
        List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
        ReceiveFax rxFaxAction = new ReceiveFax(
                new WebPageRequest("ReceiveFaxComplete"), 
                new WebPageRequest("ReceiveFaxProgress"));
        actions.add(rxFaxAction);

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
        ourResponse.setHttpServletResponse(response);
    }
}
// Java Servlet sample for the Aculab Telephony REST API.
//
// A page from the Simple Receive Fax sample:
// This receives notifications of the progress of the fax receiving.

package com.aculab.telephonyrestapi.samples;

import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;

import com.aculab.telephonyrestapi.*;

public class ReceiveFaxProgress extends HttpServlet
{
    private static final long serialVersionUID = -5873850255346099488L;

    @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();
        com.aculab.telephonyrestapi.ReceiveFaxProgress progress = (com.aculab.telephonyrestapi.ReceiveFaxProgress)ourRequest.getInstanceInfo().getActionProgress();

        // Add your own code here to use the progress information.
        // e.g. update a database, write to a log...
        int pagesReceived = progress.getPagesReceived();

        // Respond
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }
}
// Java Servlet sample for the Aculab Telephony REST API.
//
// A page from the Simple Receive Fax sample:
// This is called when the fax receiving has completed.

package com.aculab.telephonyrestapi.samples;

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

public class ReceiveFaxComplete extends HttpServlet
{
    private static final long serialVersionUID = -8602547053444851906L;

    @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();
        ReceiveFaxResult result = (ReceiveFaxResult)ourRequest.getInstanceInfo().getActionResult();

        // Add your own code here to use the result information.
        // e.g. update a database, write to a log...
        int pagesReceived = result.getPagesReceived();

        // Respond
        TelephonyResponse ourResponse = new TelephonyResponse(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('/SimpleReceiveFax', methods=['GET','POST'])
def handle_SimpleReceiveFax():

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

    fax_action = ReceiveFax(next_page=WebPage(url='ReceiveFaxComplete', method='POST'),
                    progress_page=WebPage(url='ReceiveFaxProgress', method='POST'))

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

    my_request = TelephonyRequest(request)
    my_token = my_request.get_token()
    action_progress = my_request.get_action_progress()
    negotiated_settings = action_progress.get('progress').get('negotiated_settings')
    if negotiated_settings:
        modem = negotiated_settings['modem']
        datarate = negotiated_settings['data_rate']
        print("Modem {0} rate {1}".format(modem, datarate))
    pages = action_progress.get('progress').get('pages_received', '0')
    print("Page count {0}".format(pages))

    # Return 'No content' Http Response code
    empty_json = '{}'.encode('utf-8')
    return Response(response=empty_json, status=204, content_type='application/json;charset=utf-8')
@app.route('/ReceiveFaxComplete', methods=['GET','POST'])
def handle_ReceiveFaxComplete():

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

    fax_result = action_result.get('result').get('description')
    fax_filename = action_result.get('result').get('fax_filename')
    print("The fax result is {0}".format(fax_result))
    print("The fax filename is {0}".format(fax_filename))

    my_response = TelephonyResponse([], 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\ReceiveFax;
use Aculab\TelephonyRestAPI\WebPageRequest;
use Aculab\TelephonyRestAPI\Response;

$fax = new ReceiveFax(new WebPageRequest('ReceiveFaxComplete.php', 'POST'));
$fax->setProgressPage('ReceiveFaxProgress.php', 'POST');


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

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

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

use Aculab\TelephonyRestAPI\InstanceInfo;

$info = InstanceInfo::getInstanceInfo();
$p = $info->getActionProgress();

// Add your own code here to use the progress information.
// e.g. update a database, write to a log...
$pages = $p->getPagesReceived();
<?php
header("Content-Type: application/json; charset=UTF-8");

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

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

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

// Add your own code here to use the result information.
// e.g. update a database, write to a log...
$filename = $result->getFaxFilename();
$description = $result->getDescription();
$pages = $result->getPagesReceived();
$duration = $result->getSecondsDuration();


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

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);