Firebase Cloud Function not triggering onCreate

耗尽温柔 提交于 2020-01-15 04:27:12

问题


Trying to handle a contact form submission with Cloud Functions to send the email. The 'Hello World' function fired ok, so I think the set up is fine. The form populates the 'messages' collection, but I'm not getting a log entry (or error) for the trigger on the following:

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!');
   ...

package.json looks like:

"dependencies": {
   "firebase-admin": "~5.8.1",
   "firebase-functions": "^0.8.1",

回答1:


The posted code is for a Realtime Database trigger. To trigger the function on creation of a Firestore document, change the code to this:

//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);
})


来源:https://stackoverflow.com/questions/48999651/firebase-cloud-function-not-triggering-oncreate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!