0

Dialogflow agent via cloud functions inline editor gives the following error: "Webhook call failed. Error: Request timeout." When trigetting a cloud function "handleReadTemp"

Cannot observe any other errors, tested the intent itself and it works on other basic/non-firebase related responses.

Inline editor cloud function code;

'use strict';

const functions = require('firebase-functions');
const admin = require("firebase-admin");
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: 'ws://urlFromFirebase.firebaseio.com/'
});  

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }
  function handleReadTemp(agent) {
    return admin.database().ref('dev/data/012dsf/').limitToLast(1).once('value').then((snapshot) => {
    const value = snapshot.child('Temp').val();
     agent.add(`The temperature right now is`); 
    });
  }
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('temperatureStatus', handleReadTemp);
  agent.handleRequest(intentMap);
});

Diagnostic info - Response:

{
  "responseId": "ca009ac6-a732-4427-8faa-922187fd8deb",
  "queryResult": {
    "queryText": "what is temperature",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            ""
          ]
        }
      }
    ],
    "intent": {
      "name": "projects/projectName/agent/intents/d4450093-c128-4dc4-b4e1-d9c2bd9b2049",
      "displayName": "temperatureStatus"
    },
    "intentDetectionConfidence": 1,
    "diagnosticInfo": {
      "webhook_latency_ms": 5000
    },
    "languageCode": "en"
  },
  "webhookStatus": {
    "code": 4,
    "message": "Webhook call failed. Error: Request timeout."
  }
}

Diagnostic info - Fulfillment request

{
  "responseId": "ca009ac6-a732-4427-8faa-922187fd8deb",
  "queryResult": {
    "queryText": "what is temperature",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            ""
          ]
        }
      }
    ],
    "intent": {
      "name": "projects/sydneyiot-healthspace/agent/intents/d4450093-c128-4dc4-b4e1-d9c2bd9b2049",
      "displayName": "temperatureStatus"
    },
    "intentDetectionConfidence": 1,
    "diagnosticInfo": {
      "webhook_latency_ms": 5000
    },
    "languageCode": "en"
  },
  "webhookStatus": {
    "code": 4,
    "message": "Webhook call failed. Error: Request timeout."
  }
}

Diagnostic Info: Fulfillment Status

Webhook call failed. Error: Request timeout.

Any direction would be appreciated.

Dennis Alund
  • 2,916
  • 1
  • 13
  • 34
agc
  • 173
  • 1
  • 16
  • Can you provide the fulfillment URL. – Dennis Alund Mar 28 '19 at 13:49
  • And change the way you initialize your app. First off: [the database URL shold be a HTTP address](https://firebase.google.com/docs/admin/setup#initialize_the_sdk). Secondly, you can call `.initializeApp()` without any parameters if you are just using default project. – Dennis Alund Mar 28 '19 at 13:53
  • agc, your fulfillment URL should be the URL of your HTTP cloud function. It should look something like this: `https://us-central1-YOURPROJECT-ID.cloudfunctions.net/dialogflowFirebaseFulfillment` – Dennis Alund Mar 28 '19 at 13:56
  • @DennisAlund I can see few of my other functions created manually through Firebase, however cannot see the one related to dialogflow project. I am signed-in under the same account, am I missing some configuration between the two? – agc Mar 28 '19 at 14:02
  • Hard to tell. Too many unknowns. If you want the full answer to that, then your question need to provide screenshots of your Dialogflow configuration, full logs of your `firebase deploy` output and anything else that might help. – Dennis Alund Mar 28 '19 at 14:08
  • @DennisAlund I think I got it now, since it wasn't showing under my account, it meant that I didn't select the project for the agent which was the case. Now connects successfully though getting a "null" result for the value. function: ````function handleReadTemp(agent) { return admin.database().ref('avr-iot/data/01234245A3E58A0BFE/').limitToLast(1).once('value').then((snapshot) => { const value = snapshot.child('Temp').val(); agent.add(`The temperature right now is ${value}`); }); }```` and the DB structure is: [link] https://imgur.com/Tg89Gxr – agc Mar 28 '19 at 14:16

0 Answers0