Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DialogFlow实现中的代码问题,因为它无法识别Firebase异步函数_Firebase_Firebase Realtime Database_Google Cloud Functions_Dialogflow Es_Dialogflow Es Fulfillment - Fatal编程技术网

DialogFlow实现中的代码问题,因为它无法识别Firebase异步函数

DialogFlow实现中的代码问题,因为它无法识别Firebase异步函数,firebase,firebase-realtime-database,google-cloud-functions,dialogflow-es,dialogflow-es-fulfillment,Firebase,Firebase Realtime Database,Google Cloud Functions,Dialogflow Es,Dialogflow Es Fulfillment,我遇到了问题,因为我在DialogFlow Fulfillment index.js中编写的代码,当我获取上下文参数时,他无法向DialogFlow支持发送对话,我被告知DialogFlow Fulfillment无法识别异步函数,所以当我使用Firebase推送发送他没有发送的参数时我相信他希望从上下文中得到一些参数,但是因为他没有收到,他跳过了push函数,结果没有执行,也没有发送任何东西 DialogFlow Fulfillment index.js代码: const functions

我遇到了问题,因为我在DialogFlow Fulfillment index.js中编写的代码,当我获取上下文参数时,他无法向DialogFlow支持发送对话,我被告知DialogFlow Fulfillment无法识别异步函数,所以当我使用Firebase推送发送他没有发送的参数时我相信他希望从上下文中得到一些参数,但是因为他没有收到,他跳过了push函数,结果没有执行,也没有发送任何东西

DialogFlow Fulfillment index.js代码:

const functions = require('firebase-functions'); const { WebhookClient } = require('dialogflow-fulfillment'); const { Card, Suggestion } = require('dialogflow-fulfillment'); const admin = require('firebase-admin'); admin.initializeApp({ credential: admin.credential.applicationDefault(), databaseURL: 'https://testechatbot-2020.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 Mensagem(agent) { var context = agent.context.get('awainting_nome'); var nome = context.parameters.nome; var mensagem = agent.parameters.mensagem; let teste = nome + " " + mensagem; try { admin.database().ref('Dados/').push({ Nome: nome, Mensagem: mensagem }); } catch (err) { console.error(err); return; } } let intentMap = new Map(); intentMap.set('EntradaMensagem', Mensagem); agent.handleRequest(intentMap); }); DialogFlow Fulfillment package.json代码:

{ "name": "dialogflowFirebaseFulfillment", "description": "Fluxo com envio de parametros para o Firebase", "version": "1.0.0", "private": true, "license": "Apache Version 2.0", "author": "Google Inc.", "esversion": 8, "engines": { "node": ">=10.0.0" }, "scripts": { "start": "firebase serve", "deploy": "firebase deploy" }, "dependencies": { "@google-cloud/firestore": "^0.16.1", "firebase-admin": "^8.13.0", "actions-on-google": "^2.2.0", "firebase-functions": "^3.7.0", "dialogflow": "^1.2.0", "dialogflow-fulfillment": "^0.6.0", "@google-cloud/dialogflow": "^3.0.0", "node-fetch": "^2.6.0" } }
带有DialogFlow support关于异步函数的响应的图像


我不确定您在哪里听说过Intent处理程序不能支持异步函数。他们当然可以。如果您使用的是异步函数或返回承诺的函数,则必须将其声明为异步函数或返回承诺

您的处理函数应该看起来更像

    function Mensagem(agent) {
        var context = agent.context.get('awainting_nome');
        var nome = context.parameters.nome;
        var mensagem = agent.parameters.mensagem;
        let teste = nome + " " + mensagem;
        return admin.database().ref('Dados/').push({
                Nome: nome,
                Mensagem: mensagem
            })
            .then( snapshot => {
                agent.add( "pushed" );
            })
            .catch (err => {
                console.error(err);
                agent.add( "Error." );
            })
    }

我不确定您在哪里听说过Intent处理程序不能支持异步函数。他们当然可以。如果您使用的是异步函数或返回承诺的函数,则必须将其声明为异步函数或返回承诺

您的处理函数应该看起来更像

    function Mensagem(agent) {
        var context = agent.context.get('awainting_nome');
        var nome = context.parameters.nome;
        var mensagem = agent.parameters.mensagem;
        let teste = nome + " " + mensagem;
        return admin.database().ref('Dados/').push({
                Nome: nome,
                Mensagem: mensagem
            })
            .then( snapshot => {
                agent.add( "pushed" );
            })
            .catch (err => {
                console.error(err);
                agent.add( "Error." );
            })
    }

图为DialogFlow support对异步函数的响应,我将告诉他们他们是否误解了您的问题。事实上,webhook必须同步处理是正确的,这正是您等待Firebase调用或承诺处理它所要做的。DialogFlow support关于异步函数的响应图片我将告诉他们他们是否误解了您的问题。事实上,webhook必须同步处理是正确的,这正是等待Firebase调用或承诺处理它所要做的。