We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

bad fetch has ocurred Error when submitting responses

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
tony
Posts: 8
Joined: Fri Jan 06, 2012 4:13 pm

bad fetch has ocurred Error when submitting responses

Post by tony »

Hi,

I am mystified with my Recording code, it does not work anymore, it used to work but I was kind of switching from ANSI to utf-8 codification and when I call the submit method to save Responses it just says a bad fetch error has occurred and I can't see where the problem is; is it a codification issue? or a syntax problem, I'd really appreciate your help.

Thanks,
Tony

index.vxml

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE vxml SYSTEM "http://plumvoiceportals.com/vxml-260.dtd">
<vxml xml:lang="es" version="2.0" >

<noinput>
  <prompt>
    <speak xml:lang="es">
      Lo siento, no pude oírle.
    </speak>
  </prompt>
  <reprompt/>
</noinput>

<nomatch>
  <prompt>
    <speak xml:lang="es">
      Lo siento, no le entiendo.
    </speak>
  </prompt>
  <reprompt/>
</nomatch>

<property name="sensitivity" value="0.1"/>
<property name="completetimeout" value="0.3s"/>
<property name="incompletetimeout" value="1s"/>
<property name="timeout" value="7s"/>

<property name="documentmaxage" value="0s"/>

<var name="qCustomerId" expr="'ID-GOES-HERE'"/>
<var name="date_of_call" expr="'DATE-GOES-HERE'"/>
<var name="time_of_call" expr="'TIME-GOES-HERE'"/>
<var name="save_Name" expr="'SAVE-NEW-NAME'"/>
<var name="firsttime" expr="0"/>

<var name="q1DolorCabeza" expr="0"/>
<var name="q1_level" expr="0"/>
<var name="q2DolorPiernas" expr="0"/>
<var name="q2_level" expr="0"/>
<var name="q3TrabajoConstruccion" expr="0"/>
<var name="q4" expr="0"/>
<var name="q5TypeOfWork" expr="0"/>
<var name="q5_audio" expr="0"/>
<var name="q5_a" expr="0"/>
<var name="q6" expr="0"/>
<var name="q6HowMuchHarder" expr="0"/>
<var name="q6HowMuchEasier" expr="0"/>
<var name="q7" expr="0"/>
<var name="q7HowFaster" expr="0"/>
<var name="q7HowSlower" expr="0"/>
<var name="q8" expr="0"/>
<var name="q8HowMore" expr="0"/>
<var name="q8HowLess" expr="0"/>
<var name="q9" expr="0"/>
<var name="q9_steeltoe" expr="0"/>
<var name="q9_electric" expr="0"/>
<var name="q9_waterproof" expr="0"/>
<var name="q9_concrete" expr="0"/>
<var name="q10" expr="0"/>
<var name="q10_a" expr="0"/>
<var name="q10_b" expr="0"/>
<var name="q10_c" expr="0"/>
<var name="q10_c1" expr="0"/>
<var name="q10_c2" expr="0"/>
<var name="q10_c3" expr="2"/>
<var name="fullname" expr="0"/>

<form id="wfvt_survey">
 <property name="bargein" value="false"/>

 <subdialog name="fullname_dlog" src="audio.vxml"  cond="save_Name == true">
   <param name="confirm_prompt"
       expr="'Por favor diga su nombre y apellidos despues del tono'"/>
   <filled>
	    <assign name="fullname" expr="fullname_dlog.response"/>
   </filled>
 </subdialog>


  <block>
     <prompt bargein="false">
          Por favor responda las siguientes preguntas con veracidad.
     </prompt>
  </block>

   <subdialog name="q1_dlog" src="yesno.vxml"> 
    <param name="confirm_prompt" expr="'¿Túvo un accidente el día de hoy.?'"/>
    <filled>
	    <assign name="q1DolorCabeza" expr="q1_dlog.response"/>
    </filled>
 </subdialog>

 <subdialog name="q1_level_dlog" src="unoAcuatro.vxml" cond="q1DolorCabeza=='1'"> 
   <param name="confirm_prompt" 
       expr="'¿En qué parte del cuerpo tuvo el accidente.?'"/>
   <filled>
	    <assign name="q1_level" expr="q1_level_dlog.response"/>
   </filled>
 </subdialog>



 <subdialog name="q3_dlog" src="yesno.vxml"> 
    <param name="confirm_prompt" expr="'¿Trabajó usted en construcción esta semana.?'"/> 
    <filled>
	    <assign name="q3TrabajoConstruccion" expr="q3_dlog.response"/>
	    <if cond="q3TrabajoConstruccion=='2'">
		<submit next="saveResponses.php" namelist="qCustomerId , fullname , date_of_call , time_of_call , firsttime , q1DolorCabeza , q1_level , q2DolorPiernas , q2_level , q3TrabajoConstruccion , q4 , q5TypeOfWork , q5_audio , q5_a q6 , q6HowMuchHarder , q6HowMuchEasier , q7 , q7HowFaster , q7HowSlower , q8 , q8HowMore , q8HowLess , q9 , q9_steeltoe , q9_electric , q9_waterproof , q9_concrete , q10 , q10_a , q10_b , q10_c , q10_c1 , q10_c2 , q10_c3" method="post" enctype="multipart/form-data"/>
				<exit/>
	    </if>
    </filled>
 </subdialog>
</form>
</vxml>
saveResponses.php file

Code: Select all

<?php

header('Cache-Control: no-cache');
date_default_timezone_set('America/New_York');

$headers = array(
"qCustomerId" , "date_of_call" , "time_of_call" , "end_date_of_call" , "end_time_of_call" , "firsttime" , "q1DolorCabeza" , "q1_level" , "q2DolorPiernas" , "q2_level" , "q3TrabajoConstruccion" , "q4" , "q5TypeOfWork" , "q5_audio" , "q5_a" , "q6" , "q6HowMuchHarder" , "q6HowMuchEasier" , "q7" , "q7HowFaster" , "q7HowSlower" , "q8" , "q8HowMore" , "q8HowLess" , "q9" , "q9_steeltoe" , "q9_electric" , "q9_waterproof" , "q9_concrete" , "q10" , "q10_a" , "q10_b" , "q10_c" , "q10_c1" , "q10_c2" , "q10_c3");

$mapping = array(
	"q1DolorCabeza" => "q1DolorCabeza",
	"q2PicanOjos" => "q2PicanOjos",
	"q3RonquidoPecho" => "q3RonquidoPecho",
	"q4DificultadRespirar" => "q4DificultadRespirar",
	"q5RonchasManos" => "q5RonchasManos",
	"q6RonchasPies" => "q6RonchasPies",
	"q7EntumecimientoManos" => "q7EntumecimientoManos",
	"q8DolorManos" => "q8DolorManos",
	"q9HinchazonManos" => "q9HinchazonManos",
	"q10RigidezCuello" => "q10RigidezCuello");

function write_headers($fp)
{
	GLOBAL $headers, $mapping;

	// used to be: fputcsv($fp, $headers);	
	$results = array();
	foreach($headers as $v)		// use headers as a way to order the results
		$results[] = map($v);	// map spanish to english, if there is a translation
	fputcsv($fp, $results);		// write them all out
}

function map($spanish)
{
	GLOBAL $mapping;
	if (isset($mapping[$spanish]))
		return $mapping[$spanish];
	else
		return $spanish;
}

function saveFile($msg, $prefix)
{
	global $_FILES;
	// based on code from Save.php available at 
	// http://www.plumvoice.com/docs/dev/developer_reference:dataexchange

  // if (isset($_FILES[$msg])) {
  //   //echo "found the audio attachment for $msg\n";
  // }

  if (isset($_FILES[$msg]) && is_uploaded_file($_FILES[$msg]['tmp_name'])) {
		$filename = $prefix . time() . ".wav";
    move_uploaded_file($_FILES[$msg]['tmp_name'], $filename);
		return $filename;
  }
	else {
    //echo "Audio not saved.\n";
		return "Error";
  }
}

// These one is audio file response which corresponds to the user's full name
// qCustomerId

# copy the audio responses to a local file, named with a unique identifier

if (isset($_FILES['fullname'])) {
		$fn_fullname = saveFile('fullname', "fullname-");
		$_POST['qCustomerId'] = $fn_fullname;
	}
	//else
		//$_POST['qCustomerId'] = 'not set';


// old use: "m:d:Y G:i:s"
$_POST['end_date_of_call'] = date("Y/m/d");
$_POST['end_time_of_call'] = date("H:i:s");

$file = "./data.csv";

# if file is empty or doesn't exist, then write  headers
if (!file_exists($file)) {
	$fp = fopen($file, "w");
	write_headers($fp);
}
else if (filesize($file) == 0){
	$fp = fopen($file, "w");
	write_headers($fp);
}
else # file is there, so open it in append mode and add more results at the end
	$fp = fopen($file, "a+");


$results = array();
foreach($headers as $v)		// use headers as a way to order the results
	$results[] = $_POST[$v];

# write results
fputcsv($fp, $results);
# close the file
fclose ($fp);

# echo a VXML with the goodbye message
echo "<?xml version=\"1.0\"?>\n";
echo "<vxml xml:lang=\"es-MX\" version=\"2.0\" xmlns=\"http://www.w3.org/2001/vxml\<form id="form_main">
<block>
  <prompt>
    Gracias por su tiempo. Este es el final del cuestionario. 
		Por favor recuerde llamar mañana a la misma hora. 
  </prompt>
</block>
</form>

</vxml>
">\n";
?>

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: bad fetch has ocurred Error when submitting responses

Post by support »

Hi Tony,

When we did an initial review of your code, we discovered that your echo returning VXML within saveResponses.php was not completed escaped/closed. Specifically replace:

Code: Select all

<form id="form_main">
with

Code: Select all

<form id=\"form_main\">
as well as the final few lines:

Code: Select all

</vxml>
">\n";
with:

Code: Select all

</vxml>\n";
We will continue to look into this to see if we can find any other issues.

Regards,
Plum Support

tony
Posts: 8
Joined: Fri Jan 06, 2012 4:13 pm

Re: bad fetch has ocurred Error when submitting responses

Post by tony »

Hi, thanks for the response I changed that section of the code to the code below where I am placing <form id="form_main"> outside of the php end sign ?> according to this tutorial http://www.plumvoice.com/docs/dev/devel ... erence:tts, and I was able to get rid of the the Bad fetch error message however, it does not prompt the goodbye message, how can I make it to prompt from a php file? In addition, I had to save this php file as a ANSI encoding file otherwise (utf-8) it still prompts a bad fetch error. Since I am using Spanish characters I think it should be Ok to save it as Utf-8 file, but it does not work. Again any help is appreciated.

Tony

Code: Select all

<?php
header('Cache-Control: no-cache');
date_default_timezone_set('America/New_York');
...
...
fclose ($fp);

echo "<?xml version=\"1.0\"?>\n";
echo "<vxml xml:lang=\"es-MX\" version=\"2.0\" xmlns=\"http://www.w3.org/2001/vxml\">\n";
?>
<form id="form_main">
<block>
  <prompt>
    Gracias por su tiempo. Este es el final del cuestionario. 
		Por favor recuerde llamar mañana a la misma hora. Adiós.
  </prompt>
</block>
</form>

</vxml>

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: bad fetch has ocurred Error when submitting responses

Post by support »

Hi Tony,

Dealing with language encodings is pretty tricky. There are 3 pieces you'd want to look into.
  • 1) Editor encoding
    2) PHP-level encoding
    3) XML-level encoding
1) Editor encoding - what is the encoding that your editor saves your files in?
Our engineers utilize a coding editor that allows you to manually adjust the encoding on a per-document basis. You'll want to ensure that the editor's encoding matches the encoding you will want to utilize. If you cannot modify the document encoding and your editor is saving the documents in a Latin-1 encoding you can replace the "utf-8" with "iso-8895-1" within our examples.

2) PHP-level encoding
This information can be set within the PHP header information.

Code: Select all

header('Content-Type: charset=utf-8');
3) XML-level encoding
This encoding would be set within the XML tag.

Code: Select all

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
Once all 3 encoding levels match (you can utilize either Latin-1 or UTF-8 in this case) you should be able to fetch the script and hear the goodbye message be played.

Hope this helps.

Regards,
Plum Support

tony
Posts: 8
Joined: Fri Jan 06, 2012 4:13 pm

Re: bad fetch has ocurred Error when submitting responses

Post by tony »

Sorry for late reply your guidelines were great I solved this issue.

Thanks,
Tony

Post Reply