0

以下是我的履行内联代码

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);
});

下面是我的火力数据库

在此处输入图像描述

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

在此处输入图像描述

想知道为什么连“你好”都没有返回?如何从火力库中读取数据?

4

0 回答 0