尝试集成dialogflow和firebase

时间:2019-08-08 10:27:21

标签: javascript firebase google-cloud-functions dialogflow

我正在尝试使用Webhook将dialogflow与firebase集成。 我收到的回复是:

“ webhookStatus”:{     “代码”:13    “消息”:“ Webhook调用失败。错误:500内部服务器错误。”  }

Webhook是:https://us-central1-miarduino-844c8.cloudfunctions.net/receiveAssistantRequests

Firebase规则为:

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {
    ".read": true,
    ".write": true
  }
}
我使用的

index.js是:

const functions = require('firebase-functions');

// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
//  response.send("Hello from Firebase!");
// });
const admin = require('firebase-admin');
admin.initializeApp();

const DialogflowApp = require('actions-on-google').DialogflowApp;

exports.receiveAssistantRequests = functions.https.onRequest((request, response) => {

    const app = new DialogflowApp({ request: request, response: response });

    function handlerRequest(app) {

        const device = app.getArgument('devices');
        const status = app.getArgument('status');

        return admin.database().ref(`/automation/${device}/value`).set(status)
            .then(snapshot => {
                app.ask(`Ok, switching ${device} ${status}. Do you want to control anything else?`);
            });

    }
    app.handleRequest(handlerRequest);
});

如果我使用soapUI发出以下请求:https://us-central1-miarduino-844c8.cloudfunctions.net/receiveAssistantRequests 我得到:

HTTP/1.1 500 Internal Server Error

Content-Type=text/plain; charset=utf-8

X-Content-Type-Options=nosniff

X-Cloud-Trace-Context=7327cb053558c4598e01b0218e61e5cf;o=1

Date=Thu, 08 Aug 2019 10:19:12 GMT

Server=Google Frontend

Content-Length=36

Alt-Svc=quic=":443"; ma=2592000; v="46,43,39"


Error: could not handle the request

有人知道如何解决此问题吗?

不确定问题出在Dialogflow还是Firebase中

1 个答案:

答案 0 :(得分:0)

这可能会对您有所帮助。

const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp({
      databaseURL: "YOUR_DATABASE_URL"});
    process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

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