Play

Have you registered a callback URL to receive requests for your virtual number? Please click here.

This element lets you play back an audio file that is located anywhere on the web.

Here is a sample response:
(Say feature in the response below is optional and you may just call play)

<Response>
   <Say>Please listen to our awesome record</Say>
   <Play url="http://www.myvoicemailserver.com/audio/vmail.wav"/>
  </Response>

Attributes

The Play element can take these attributes:
Attribute Description Required Default Value
url A valid URL that contains a link to the file to be played. Note that we will cache the content after the first playback request, and will adhere to header information that indicates the need to re-download the file later on. Yes N/A

Sample PHP Implementation

Assuming that you have configured the callback URL for your Africa's Talking Phone Number to point to voicemail.php. Below is an example of how you would handle an incoming call and play back the content of a file that contains your voice mail (most likely recorded using our Record element...)
<?php
// Save this code in voicemail.php. Configure the callback URL for your phone number
// to point to the location of this script on the web
// e.g http://www.myawesomesite.com/voicemail.php

// First read in a couple of POST variables passed in with the request

// This is a unique ID generated for this call
$sessionId = $_POST['sessionId'];

// Check to see whether this call is active
$isActive  = $_POST['isActive'];

if ($isActive == 1)  {
  
  // Get the location of previously recorded voicemail and play back the file. Make 
  // sure its a valid web address that starts with http
  $response  = '<?xml version="1.0" encoding="UTF-8"?>';
  $response .= '<Response>';
  $response .= '<Say>Please listen to our awesome record</Say>';
  $response .= '<Play url="http://www.myvoicemailserver.com/audio/vmail.wav"/>';
  $response .= '</Response>';
     
  // Print the response onto the page so that our gateway can read it
  header('Content-type: apllication/xml');
  echo $response;

} else {
  
  // Read in call details (duration, cost). This flag is set once the call is completed.
  // Note that the gateway does not expect a response in thie case
  
  $duration     = $_POST['durationInSeconds'];
  $currencyCode = $_POST['currencyCode'];
  $amount       = $_POST['amount'];
  
  // You can then store this information in the database for your records

}