dialogflow и firebase - не может читать данные из firebase - PullRequest
0 голосов
/ 09 февраля 2019

Ниже мой встроенный код выполнения

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');

// initialise DB connection
const admin = require('firebase-admin');
admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: 'ws://rochechatbot.firebaseio.com/',
});

process.env.DEBUG = 'dialogflow:debug';

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 handleData(agent) {
    const Product_name = agent.parameters.Product_name;
    agent.add('Hello');

    return admin.database().ref('rochechatbot').once("value").then((snapshot) => {
      var StockData = snapshot.child("Stock").val();
      agent.add(StockData);
    });
  }

  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('StockLevelEnquiry', handleData);
  agent.handleRequest(intentMap);
});

Ниже моя база данных firebase

enter image description here

Ниже мой диалог, веб-крюк включен

enter image description here

Интересно, почему даже «hello» не возвращается? Как прочитать данные из базы данных?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...