function updateMessage(input, response) {
	//console.log(input);
  var responseText = null;
  if (!response.output) {
    response.output = {};
  } else {
	  
          var flag = 0;
            var rsText ='';
             rsText = String(response.output.text[1]);

             if(rsText == 'undefined' || rsText == '') {
              rsText = String(response.output.text[0]);
              flag = 1;
             }
             
             
              if (rsText.indexOf('ReplaceBalance') !== -1) {
                console.log("Inside replace balace");
                 dbstore.getBalance(response.context.number, function(error,data){
                     if(error) {
                       throw err;
                     }
                     console.log("LALA Balance is ",data[0].balance);
					 console.log("flag="+flag);
                     if (flag == 1){
						response.output.text[0]="Your current outstanding balance is RM "+ data[0].balance;
					 }else{
                        response.output.text[1]="Your current outstanding balance is RM "+ data[0].balance;
					}
                    console.log(response);
				   return response;
                   }); //db store bracket 
				   
               }  

console.log("2:response="+response);
 return response;				   
	
  }
  if (response.intents && response.intents[0]) {
    var intent = response.intents[0];
    // Depending on the confidence of the response the app can return different messages.
    // The confidence will vary depending on how well the system is trained. The service will always try to assign
    // a class/intent to the input. If the confidence is low, then it suggests the service is unsure of the
    // user's intent . In these cases it is usually best to return a disambiguation message
    // ('I did not understand your intent, please rephrase your question', etc..)
    if (intent.confidence >= 0.75) {
      responseText = 'I understood your intent was ' + intent.intent;
    } else if (intent.confidence >= 0.5) {
      responseText = 'I think your intent was ' + intent.intent;
    } else {
      responseText = 'I did not understand your intent';
    }
  }
  console.log("LAST:response="+responseText);
  response.output.text = responseText;
  return response;
}
/**
 * Updates the response text using the intent confidence
 * @param  {Object} input The request to the Conversation service
 * @param  {Object} response The response from the Conversation service
 * @return {Object}          The response with the updated message
 */
Updates the response text using the intent confidence
@param  {Object} input The request to the Conversation service
@param  {Object} response The response from the Conversation service
@return {Object}          The response with the updated message
Updates the response text using the intent confidence @param { Object } input The request to the Conversation service @param { Object } response The response from the Conversation service @return { Object } The response with the updated message
function updateMessage(input, response) {
  var responseText = null;
  if (!response.output) {
    response.output = {};
  } else {
          var flag = 0;
            var rsText ='';
             rsText = String(response.output.text[1]);
             if(rsText == 'undefined' || rsText == '') {
              rsText = String(response.output.text[0]);
              flag = 1;
             }
              if (rsText.indexOf('ReplaceBalance') !== -1) {
                console.log("Inside replace balace");
                 dbstore.getBalance(response.context.number, function(error,data){
                     if(error) {
                       throw err;
                     }
                     console.log("LALA Balance is ",data[0].balance);
					 console.log("flag="+flag);
                     if (flag == 1){
						response.output.text[0]="Your current outstanding balance is RM "+ data[0].balance;
					 }else{
                        response.output.text[1]="Your current outstanding balance is RM "+ data[0].balance;
					}
                    console.log(response);
				   return response;
                   }); 
               }  
console.log("2:response="+response);
 return response;				   
  }
  if (response.intents && response.intents[0]) {
    var intent = response.intents[0];
    if (intent.confidence >= 0.75) {
      responseText = 'I understood your intent was ' + intent.intent;
    } else if (intent.confidence >= 0.5) {
      responseText = 'I think your intent was ' + intent.intent;
    } else {
      responseText = 'I did not understand your intent';
    }
  }
  console.log("LAST:response="+responseText);
  response.output.text = responseText;
  return response;
}
function updateMessage ( input , response ) { var responseText = null ; if ( ! response . output ) { response . output = { } ; } else { var flag = 0 ; var rsText = '' ; rsText = String ( response . output . text [ 1 ] ) ; if ( rsText == 'undefined' || rsText == '' ) { rsText = String ( response . output . text [ 0 ] ) ; flag = 1 ; } if ( rsText . indexOf ( 'ReplaceBalance' ) !== - 1 ) { console . log ( "Inside replace balace" ) ; dbstore . getBalance ( response . context . number , function ( error , data ) { if ( error ) { throw err ; } console . log ( "LALA Balance is " , data [ 0 ] . balance ) ; console . log ( "flag=" + flag ) ; if ( flag == 1 ) { response . output . text [ 0 ] = "Your current outstanding balance is RM " + data [ 0 ] . balance ; } else { response . output . text [ 1 ] = "Your current outstanding balance is RM " + data [ 0 ] . balance ; } console . log ( response ) ; return response ; } ) ; } console . log ( "2:response=" + response ) ; return response ; } if ( response . intents && response . intents [ 0 ] ) { var intent = response . intents [ 0 ] ; if ( intent . confidence >= 0.75 ) { responseText = 'I understood your intent was ' + intent . intent ; } else if ( intent . confidence >= 0.5 ) { responseText = 'I think your intent was ' + intent . intent ; } else { responseText = 'I did not understand your intent' ; } } console . log ( "LAST:response=" + responseText ) ; response . output . text = responseText ; return response ; }
Updates the response text using the intent confidence
 @param  {Object} input The request to the Conversation service
 @param  {Object} response The response from the Conversation service
 @return {Object}          The response with the updated message
Updates the response text using the intent confidence @param { Object } input The request to the Conversation service @param { Object } response The response from the Conversation service @return { Object } The response with the updated message
//console.log(input); //db store bracket  // Depending on the confidence of the response the app can return different messages. // The confidence will vary depending on how well the system is trained. The service will always try to assign // a class/intent to the input. If the confidence is low, then it suggests the service is unsure of the // user's intent . In these cases it is usually best to return a disambiguation message // ('I did not understand your intent, please rephrase your question', etc..)