简体   繁体   English

export.module 和 Firebase-admin 的问题

[英]Problem with exports.module and Firebase-admin

I'm having a problem my code in the index looks like this:我在索引中的代码有问题,如下所示:

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

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 SubmitFeedback (agent) {
        var functioncaoFeedback = require ('./EnviarFeedback');
        functionFeedback.SendFeedback (agent);
    }

    let intentMap = new Map ();
    intentMap.set ('inputName', CheckName);
    intentMap.set ('confirmFeedback', SendFeedback);
    intentMap.set ('InputMessage', CheckMessage);
    intentMap.set ('InputValues', CheckValue);
    intentMap.set ('negacaoFeedback', CheckNegacao);
    agent.handleRequest (intentMap);
});

And I'm calling the function "EnviarFeedback" of the file EnviarFeedback.js but it is giving errors in the log and the errors are:我正在调用文件 EnviarFeedback.js 的函数“EnviarFeedback”,但它在日志中给出错误,错误是:

Unhandled rejection未经处理的拒绝

Function execution took 537 ms, finished with status: 'crash'函数执行耗时 537 毫秒,完成状态为:'crash'

And here is the SubmitFeedback.js file:这是 SubmitFeedback.js 文件:

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

admin.initializeApp ({
    credential: admin.credential.applicationDefault (),
    databaseURL: 'https://pri-ambiente-de-teste.firebaseio.com/'
});

module.exports.SendFeedback = function (agent) {
    var context = agent.context.get ('result');
    var name = context.parameters.name;
    var value = context.parameters.valor;
    var message = context.parameters.mensagem;
    console.log (name, value, message);
    let banco = admin.database (). ref ('Data /');
    console.log (JSON.stringify (bank));
    return banco.push ({
        Name: name,
        Value: value,
        Message: message
    }, function (error) {
        if (error)
            console.log ('Error has occured during saving process')
        else
            console.log ("Data hss been saved succesfully")
    });
}

Well, it looks like there is a space between the slash and the file name in your import.好吧,在您的导入中,斜线和文件名之间似乎有一个空格。 Maybe it's just that.也许仅此而已。

Anyway, you should also use a try/catch block to handle any exception in your code and log in the firebase console the error message.无论如何,您还应该使用 try/catch 块来处理代码中的任何异常,并在 firebase 控制台中记录错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.jsexports.module如何将变量导出到其他脚本 - Nodejs exports.module How to export Variable to other Script 使用 Nuxt 的 Firebase 管理员 - Firebase-Admin with Nuxt Firebase-Admin,导入它以响应应用程序抛出模块未找到错误 - Firebase-Admin, importing it to react application throws Module not found error java 脚本中的“module.exports”和“exports.module”有什么区别 - What is the difference between "module.exports" and "exports.module" in java script 导入firebase-admin时出错 - Error importing firebase-admin 如何使用 firebase-admin 删除集合中的字段? - How to delete a field in a collection with firebase-admin? admin.messaging() 在“firebase-admin”上时不是 function:“^11.3.0”, - admin.messaging() is not a function while on "firebase-admin": "^11.3.0", 如何使用firebase-admin模块使用Node.js从Firebase数据库返回有序数据? - How can I return ordered data from Firebase database with Node.js using the firebase-admin module? 单元测试firebase函数:如何存根firebase-admin sdk - Unit testing firebase functions: how to stub firebase-admin sdk 如何在Firebase-Admin API中获得所有用户 - How to get all users in firebase-admin api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM