Page 1 of 1

Using a Web Service with a Scrath Pad Application

Posted: Thu Jun 16, 2011 10:50 am
by Nampaw
Hello I have created an IVR using the scratchpad feature but I can't add a data source/webservice to it. I can only add web services to the pre built applications. I would appreciate some help with this.

Thanks

Re: Using a Web Service with a Scrath Pad Application

Posted: Thu Jun 16, 2011 12:01 pm
by support
Hi Nampaw,

The scratchpad itself cannot handle web service requests. It was designed to only handle VXML. To correctly handle this situation you should use a subdialog tag to make your web service request. Here's an example using the Plum Survey's test web service.

Scratchpad:

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
  <form>
    <var name="question" expr="'Say yes or no.'"/>
    <var name="answer"/>

    <field name="statement">
      <grammar type="application/srgs+xml" root="ROOT" mode="voice">
	<rule id="ROOT">
	  <one-of>
	    <item>
	      yes
	    </item>
	    <item>
	      no
	    </item>
	  </one-of>
	</rule>
      </grammar>

      <prompt>
	<value expr="question"/>
      </prompt>

      <filled>
	<assign name="answer" expr="statement"/>
      </filled>
    </field>

    <subdialog name="webservice" src="http://www.plumvoice.com/example/webservice.php" namelist="question answer">
      <filled>
	<prompt>
	  The web service returned: <value expr="webservice.Value"/>
	</prompt>
      </filled>
    </subdialog>
  </form>
</vxml>
webservice.php:

Code: Select all

<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\"?>";

$question = array($_GET['question']);
$answer = array($_GET['answer']);

ob_start();
$soap_client = new SoapClient("http://survey.plumvoice.com/ws/sample-webservice.php?wsdl", array('trace' => 1, 'exceptions' => 0));
ob_end_clean();

$result = $soap_client->plumEval($question, $answer);
?>

<vxml version="2.0">
<form id="main">
  <block>
    <var name="Value" expr="'<?= $result ?>'"/>
    <return namelist="Value"/>
  </block>
</form>
</vxml>
This example submits both the question and answer to the web service. This test web service looks at the answers that were submitted and looks for the keyword "yes". If "yes" was sent the web service should return "accepted" while any other value returns "rejected" (in this case, "no").

Hope this helps!

Regards,
Plum Support