CCXML 1.0-W3C Development Guide Home  |  Frameset Home

  ANI and DNIS  |  TOC  |  I: CCXML 1.0 Objects  

Appendix G: <Send> Element & HTTP Requests

The <send>  element is used for one main purposes: to send events to a separate CCXML session. The Voxeo implementation adds to this by allowing  the developer to trigger a HTTP request.

When the <send>  is used to reach a HTTP server, then the resulting document will be examined. This document, or the HTTP body, can be empty, leading to a silent send without any feedback. Notice that it still will be transactional, since errors are always reported.

It is also possible, in the "returned document", to provide a specific, defined data structure that will result in a user-defined event in the originating CCXML 1.0 session. Let's look at a sample data structure:


          hello
          test=123
          more=is that it


The above example illustrates how your "return document" should look.  The document should always be in "text/plain" format with the first line containing the name of the user-defined event to be thrown, each of the following lines should contain any name/value pairs (delimited by an 'equals' sign) that you wish to return to your CCXML 1.0 application.  The name/value pairs in this example will be accessible via the event object when transitioning the 'user.hello' event.  Note that if parsing of the requested document fails, (such as what would be caused when missing an '=' sign),  no event will be sent at all, but the event error.send will be returned to the invoking document.

send_http_request.xml


<?xml version="1.0" encoding="UTF-8"?>
<ccxml version="1.0" xmlns="http://www.w3.org/2002/09/ccxml">

  <var name="myVar" expr="'some cool value'"/>
  <var name="statevar" expr="'init'"/>
  <var name="what_i_sent"/>
 
  <eventprocessor statevariable="statevar">
 
  <transition state="init" event="ccxml.loaded">
    <send target="'sendTarget.php'" name="what_i_sent" namelist="myVar" delay="'1s'" targettype="'basichttp'"/>
    <assign name="statevar" expr="'state1'"/>
  </transition>

  <transition event="myEvent" state="state1">
  <var name="myObj" expr="JSON.parse(event$.myVar)"/>
  <log expr="'***** DATA RECIEVED FROM SERVER *****'"/>
  <log expr="'***** myObj = ' + myVar"/>
  </transition>

  <transition event="error.send">
    <log expr=" ' ** Problem: ' + event$.reason + ' (eventid = ' + event$.eventid + ') **' "/>
  </transition>


</eventprocessor>

</ccxml>


sendTarget.php


<?php

echo "myEvent\n"
?>
<?php
header('Cache-Control: no-cache');


foreach($_REQUEST as $key => $value )
{
    echo $key , "=", $value, "\n";
}

?>



Note that you may also download the complete code for testing by clicking here. Copy and paste is SO last-century....



  ANNOTATIONS: EXISTING POSTS
amitsood
10/11/2007 4:32 PM (EDT)

Here is the sample  ASP.net code that will return the values as expected by CCXML,
in this case EventFromAspPage is the event name that will handeled by CCXML
set content type to plain text
public class MyForm: System.Web.UI.Page
    {
        private void Page_Load(object sender, System.EventArgs e)
{
string callId = string.Empty;
string outputStr = string.Empty;

try
{
this.Context.Response.ContentType  = "text/plain"; //Needs for CCXML version 1.0
                                    callId = FormatInputParam("callID");
string InputParam1= FormatInputParam("param1");
string InputParam2= FormatInputParam ("param2");
string InputParam3= FormatInputParam ("param3");
//Do your processing
outputStr =  CreateCCXMLResponse("EventFromAspPage", "Value1", "Value2"); }
}
catch(Exception ex)
{
                                  // Handle the errors
                                  outputStr =  CreateCCXMLResponse( "EventFromAspPage", "Value1", "Value2");
}

this.Context.Response.Write(outputStr);
      }
      private string FormatInputParam(string paramName)
{
string retString = this.Context.Request[paramName];
if (null == retString)
{
retString = string.Empty;
}
return retString;
}
      private string CreateCCXMLResponse(string eventName, string value1, string value2)
{

StringBuilder returnStringBuilder = new StringBuilder(eventName);

returnStringBuilder.Append("\n");
returnStringBuilder.Append("Key1");
returnStringBuilder.Append("=");
returnStringBuilder.Append(value1);
                            returnStringBuilder.Append("\n");
returnStringBuilder.Append("Key2");
returnStringBuilder.Append("=");
returnStringBuilder.Append(value2);

return returnStringBuilder.ToString();
}
}
jbuehring
11/23/2007 7:31 PM (EST)
On our test-bed installation of Prophecy 8.0.x, it appears to be the default behavior of the send element when using basichttp to transmit namelist data as base64-encoded HTTP POST.  In this case, the target's server-side logic needs to process it accordingly before the data can be meaningful to it.

The way around this appears to be to specify 'http.get' as the name attribute, which transmits the namelist in plain-text via the HTTP GET method.

Needless to say, this caveat should be documented, both in the send element's page, and in Appendix G!
VoxeoBrian
11/23/2007 9:24 PM (EST)
Hello,

You are correct, it is possible to specify the name attribute as http.get, which will transmit your parameters as plain text via GET.  This however is not valid per the CCXMl specification and is a "hack", if you will that was created for our specific platform implementation.

Allowing CCXML sends via GET is not something provided by the specification and as such was not included in the documentation.  I will however make note of this, as I believe this should be documented for future use.  Please let us know if you have any additional questions, we are always happy to help.


Regards,

Brian
ScapeLogic
3/2/2008 2:46 PM (EST)
I think it'd be useful for this example to be updated with the following:

First, the example output above has an event called 'hello', whereas the code example uses an event called 'myEvent'. 

Second, <log expr='***** myObj = ' + myVar"/> shouldnt that be + myObj instead of + myVar?

Third, I think it'd be useful for people to understand they can get access to the actual key/value pairs like event$.keynamehere
mikethompson
3/2/2008 6:07 PM (EST)
Good eye there!  I will need to follow up with the keepers of our documentation and see if we can get this changed.

Thanks,
Mike Thompson
Voxeo Corporation
samo.jst
4/7/2008 7:55 AM (EDT)
Hi,

I've noticed that the link to 'complete code' zip file is not available. Could you please send it to me by email or republish it on the web site...

... I would really like to try the example, becouse I can see the PHP http response in the ccxml log file:
<parameter name="content" value="clir=1" /> ,
but the expected new variable 'clir' can not be accessed - it remains undefined:
<log expr="'CLIR:'+ clir"/>
<log expr="'CLIR:'+ evt.clir"/>
==>
<log>CLIR:undefined</log>
<log>CLIR:undefined</log>


br,
Samo
voxeodamonic
4/7/2008 8:18 AM (EDT)
Hello,

We apologize for the broken link.  I will do some investigation and find out why this link is broken and get the page republished. 

Thank,

Damonic
Voxeo Support
voxeojeff
4/17/2008 10:51 AM (EDT)
Hi Samo,

My apologies for the delayed update here.  This issue has been rectified, and all links should now be fully functional. :-)

Best regards,

Jeff

login

  ANI and DNIS  |  TOC  |  I: CCXML 1.0 Objects  

© 2003-2008 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site