[英]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.