dialogflow和firebase-无法从Firebase读取数据

时间:2019-02-09 16:11:44

标签: firebase firebase-realtime-database dialogflow dialogflow-fulfillment

下面是我的内嵌代码

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

下面是我的对话流,已启用Webhook

enter image description here

想知道为什么甚至没有返回“ hello”吗? 如何从Firebase读取数据?

0 个答案:

没有答案