IVR : Transfer a telephone call with PHP and VoiceXML
While developing IVR application with VoiceXML we need sometimes to offer a service of call transfer. And certainly you know how to transfer a call with VoiceXML using the tag "transfer".
So I have written this PHP Voice module to make call transfer more easy using PHP VoiceXML class. A small sample usage could be :
$v = new gonx_vxml();
$v->start_vxml("", "", "", "", "", "2.0");
$v->load("transfer",array("123456789","please wait, transferring your call to 1 2 3 4 5 6 7 8 9 "));
$v->end_vxml();
$v->generate();
The example just allow to play a message to the user and then transfer the call to a specific number. I have setup a default message "Please wait while we transfer your call" so we keep the message optional. I have added another parameter which is the formid, which could be used if you want to link the transfer form to another application ... etc.
The module code is listed below transfer.class.php
/**
* VoiceXML Telephone call transfer Module
*
* @author Ben Yacoub Hatem
* @version $Id: transer.class.php,v 1.0
*/
class transfer
{
/**
* @access private
* @var object
*/
var $obj;
/*
*
* Transfer a message
*
* @param number transfer number
* @param message message (optional)
* @param formid formid (optional)
*
*/
function transfer(&$obj,$params)
{
$this->obj = &$obj;
$number = $params[0];
$message = (trim($params[1])!='')?$params[1]:'Please wait while we transfer your call';
$formid = (trim($params[2])!='')?$params[2]:'transfer';
$this->obj->start_form($formid);
$this->obj->start_block();
$page->start_prompt();
$page->write($message);
$page->end_prompt();
$this->obj->end_block();
$page->transfer($number,'',false);
$this->obj->end_form();
return;
}
}


