0

I'm trying to use fulfillment from the entity that I created Google Cloud but, even with no errors in the Deploy, when I test I have the error:

{
  "error": "Cannot read property 'Definicion' of undefined"
}

I attach the link with the image of the Cloud entity enter image description here

Also attach here the code.

'use strict';


const functions = require ('firebase-functions');
const {dialogflow} = require ('actions-on-google');
// instantiate the object
const datastore_enfermedades = require('@google-cloud/datastore');
// instantiate a datastore client
const datastore = datastore_enfermedades ();


const WELCOME_INTENT = 'Default Welcome Intent';
const FALLBACK_INTENT = 'Default Fallback Intent';
const LOOKING_FOR_DISEASE_INTENT = 'InfoDisease';
const DISEASE_TYPE_ENTITY = 'TypeDisease';


const app = dialogflow ();

app.intent (WELCOME_INTENT, (conv) => {
    conv.ask('Hola! Si quieres puedo darte más información sobre alguna enfermedad, pregúntame!');
  });


app.intent (FALLBACK_INTENT, (conv) => {
    conv.ask('Ai, no te he entendido, ¿puedes repetirmelo por favor?');
  });

const disease1 = datastore.createQuery('Tabla de enfermedades').filter('Enfermedad', '=','artritis');
app.intent(LOOKING_FOR_DISEASE_INTENT, (conv) => {
    const disease_type = conv.parameters[DISEASE_TYPE_ENTITY].toLowerCase();
    if (disease_type == "artritis") {
        return datastore.runQuery(disease1).then(results => {
            conv.ask(results[0][1].Definicion);
        });
    } else {
        conv.ask("Puedes repetirlo por favor?");
    }
});


 exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
MariaGon
  • 11
  • 2

1 Answers1

0

This doesn't appear to have anything to do with handling it through fulfillment.

the issue appears to be that results[0][1] is undefined. Since the RunQueryResponse is in results[0] it suggests that you may need to examine results[0] to see what you're actually getting back and which values you intend to use.

You can look at that by calling console.log(results[0]).

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Thank you again for helping me! I am kind of new with this whole thing, could you tell me how can I examine results[0]? Thank you!! – MariaGon Jan 10 '19 at 08:30
  • Ok thank you, it was results[1], but now the error is { "error": "Cannot read property 'simpleResponse' of undefined" } Do you know where is simpleResponse? cause I cannot find it – MariaGon Jan 14 '19 at 09:39
  • And when I try ni actions on google the error is : { "responseMetadata": { "status": { "code": 10, "message": "Failed to parse Dialogflow response into AppResponse because of empty speech response", "details": [ { "@type": "type.googleapis.com/google.protobuf.Value", "value": "{\"id\":\"0783191e-da98-40d2-9da4-1b3df7dd8ce7\",\"timestamp\":\"2019-01-14T09:44:07.188Z\",\"lang\":\"es-es\",\"result\":{},\"alternateResult\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: 500... – MariaGon Jan 14 '19 at 09:54
  • Please don't try to put code or errors in comments - they are very difficult to read. Update your original question with the latest code and errors that you're seeing. – Prisoner Jan 14 '19 at 11:22