Building KooKoo applications in php is as easy as it gets.
response.php is a KooKoo php library that has been designed to help you create KooKoo markup faster. It is not mandatory for you to use the KooKoo PHP library to create the markup. Plain XML is sufficient.
In order to use the KooKoo php library, just download
KooKoo PHP library and include it in your source code.
KooKoo php library has two main classes:
- Response: This is the root tag
- collectdtmf: Collect user input from your callers
Response is the main class. To talk to KooKoo you have to first create a response object.
If you want to maintain session through the response object you instantiate it with a state variable
1 | $r = new Response( "start" ); |
Once a response object is created, you can inform KooKoo to do several tasks on your behalf.For each task there is corresponding method in the Response object. The supported tasks and their corresponding methods are given below:
- playtext: Play some text to your callers
- playaudio: Play some audio to your callers
- Send Sms: Tells KooKoo to send an SMS to a specified number.(Available only to paid users)
- record: Record caller conversation
- Hangup: Tells KooKoo to hangup the call.
- dial: Make an outbound call (Available only to paid users)
Description:Tells KooKoo to play some text using the default text to speech engine.The characters usage of playtext tag is limited to 100 characters.
1 | Method:addPlayText($text) |
2 | Arguments:The text to play |
3 | Example:$r->addPlayText( "I love KooKoo" ); |
Description: Tells KooKoo to play an audio file.
1 | Method:addPlayAudio($url) |
2 | Arguments:The URL of the audio to play |
Description:Tells KooKoo to send an SMS to a specified number.
1 | Method: sendSms($text,$number) |
2 | Arguments:The text of the sms message (should be less that 160 characters) |
3 | and the mobile number to send the sms to. |
4 | Example:$r->sendSms( "This is an sms message" ,919000455345); |
Description: Tells KooKoo to play a beep to the caller and record his message.
01 | The URL of the recorded message will be sent back to your application. |
02 | Method: addRecord($filename,$format,$silence,$maxduration,$option) |
04 | filename:The name to be given to the recorded audio. |
05 | format:The format of the recorded audio. Right now only wav is supported. |
06 | silence:Number of seconds of silence before we assume the caller has finished recording. |
07 | Default value is 2 secs. |
08 | maxduration:Maximum number of seconds to allow recording. Default value is 30 secs. |
09 | option:Any additonal options to be provided to the record function . |
10 | Right now this parameter is not used.So you can leave it. |
11 | Example:$r->addRecord( "test.wav" ); |
Description: Tells KooKoo to hangup the call.
2 | Example:$r->addHangup(); |
Description: In KooKoo collecting user input is handled by the collectdtmf tag. Since the collectdtmf tag is a complex tag with other tags nested inside it, we have a CollectDtmf object to handle the collectdtmf tag. If your program needs to collect user input, first instantiate the CollectDtmf object
You can set the following attributes on the CollectDtmf object
1.max digits: The maximum number of digits to collect from the user before stopping
1 | $cd->setMaxDigits( "4" ); |
2.terminating character: Specify the terminating character which when pressed will tell KooKoo to stop accepting user input and return.
2 | kookoo stops accpeting user input and return the digits pressed so far. |
3.time out: The number of milliseconds to wait for an user to input a digit.If the user does not enter any digit for the specified amount of time, KooKoo assumes that the user has finished entering the digits and returns the digits entered so far to your application.
1 | $cd->setTimeOut( "2000" ); |
You can also add playtext and playaudio tags to the collectdtmf. These will be played as prompts to the user prompting him to enter input. The format of the addPlayText and addPlayAudio methods are same as that of the Response object.
1 | $cd->addPlayText( "Please enter your pin number" ); |
Once all the attributes are set to the CollectDtmf object we add the object to the Response.
1 | $r->addCollectDtmf($cd); |
So once the response object has been prepared with all the necessary actions, we send the response object to KooKoo
KooKoo will receive the Response object, perform the actions specified and return results if there are any. Your application receives the results, processes them and creates another Response object if necessary. This flow continues until you are finished with your application. To put this all together, an example application, Adder, is explained below.
3 | require_once( "response.php" ); |
Now you are ready to receive requests from the IVR. A general user scenario is given below.
Step 1: A customer calls your phone number. Step 2: KooKoo receives the call and informs us of the new call at the URL we have specified in our KooKoo dashboard.Let us say our URL is http://www.yoursite.com/adder.php Step 3: The PHP at the URL receives the request. We need to handle the message from KooKoo about the new call.KooKoo communicates with our application by posting GET requests to our web server and passing request parameters. Add the following to adder.php to handle the KooKoo new call message.We recieve the call and ask KooKoo to interact with the caller to get the first number to calculate.
01 | if ($_REQUEST[ 'event' ]== "NewCall" ) |
03 | $cd = new CollectDtmf(); |
05 | $cd->setTermChar( "#" ); |
07 | $cd->setTimeOut( "4000" );( KooKoo will wait for '4000' milliseconds for the |
09 | $cd->addPlayText( "welcome to adder.Please enter your first number.Terminate with hash" ); |
11 | $r->addCollectDtmf($cd); |
15 | $_SESSION[ 'state' ] = "firstNumber" ; |
Step 4: KooKoo will play the specified text, collect the user input and inform us again at our URL. To handle that event add the following code sequentially
01 | else if ($_REQUEST[ 'event' ]== "GotDTMF" && $_SESSION[ 'state' ] == "firstNumber" ) |
03 | $first = $_REQUEST[ 'data' ]; |
04 | $cd = new CollectDtmf(); |
06 | $cd->setTermChar( "#" ); |
08 | $cd->setTimeOut( "4000" );( KooKoo will wait for '4000' milliseconds for the user to |
10 | $cd->addPlayText( "Please enter the Second number.Terminate with hash" ); |
12 | $_SESSION[ 'firstNumber' ]=$first; |
13 | $_SESSION[ 'state' ] = "secondNumber" ; |
16 | $r->addCollectDtmf($cd); |
Step 5: KooKoo will collect the second number and inform us. To handle this event add the following code sequentially.
01 | else if ($_REQUEST[ 'event' ]== "GotDTMF" && $_SESSION[ 'state' ] == "secondNumber" ) |
03 | $second = $_REQUEST[ 'data' ]; |
04 | $total = $_SESSION[ 'firstNumber' ]+$second; |
05 | $r->addPlayText( "your total is $total" ); |
Click to download
kookoophp
.
The KooKoo PHP Library makes it easy to write KooKoo songs without having to touch XML.
USAGE:
There are two main classes. Response and CollectDtmf. First create a response object and append any tags to it.Since CollectDtmf is a complex tag we have a seperate Class for it. To append a collectdtmf tag, first create a collectdtmf object and then append that object to the response tag.