Firebase Cloud功能不会触发onCreate

pr0*_*0t0 2 firebase google-cloud-functions

尝试使用Cloud Functions处理联系表单提交以发送电子邮件."Hello World"函数启动正常,所以我认为设置很好.表单填充了'messages'集合,但我没有获得以下触发器的日志条目(或错误):

const functions = require('firebase-functions');
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase);

const ref = admin.database().ref();

//if user contacts us
exports.sendContactEmail = functions.database
.ref('messages/{msgId}')
.onCreate(event => {

   console.log('Made it to the trigger!');
   const formData = event.data.data(); // the contact form data

   return sendContactEmail(formData);
})

// Sends an email to someone at the company
function sendContactEmail(formInfo) {
   console.log('Made it to the send function!');
   ...
Run Code Online (Sandbox Code Playgroud)

package.json看起来像:

"dependencies": {
   "firebase-admin": "~5.8.1",
   "firebase-functions": "^0.8.1",
Run Code Online (Sandbox Code Playgroud)

Bob*_*der 12

发布的代码用于实时数据库触发器.要在创建Firestore文档时触发该功能,请将代码更改为:

//if user contacts us
exports.sendContactEmail = functions.firestore  // <= CHANGED
.document('messages/{msgId}')  // <= CHANGED
.onCreate(event => {

   console.log('Made it to the trigger!');
   const formData = event.data.data(); // the contact form data

   return sendContactEmail(formData);
})
Run Code Online (Sandbox Code Playgroud)