I am currently working on a web application to where a customer can come and request a private event for a valet company. I am trying to set up a trigger function so it can send an email to the owner evertytime someone requests a private event. I currently ahve this code set up in my email.js file
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.onQuoteAdded = functions.firestore.document('Manager/Quote/Quotes').onCreate( (snap, context) =>{
const values = snap.data();
//send email
db.collection('login').add({ description: 'Email was sent'});
});
I try to do the firebase deploy --only functions. I do that it says deployed succesfully. I then go into my firestore i add a new file under Quotes and nothing happens. I then also check the functions page within firebase and it says waiting on your first deploy. Does anyone know what i could to to figure out where the errror is.
The Cloud Function defined with functions.firestore.document('Manager/Quote/Quotes').onCreate() cannot deploy correctly because you are passing a wrong path to the document() method.
You need to pass a path that points to a Document, i.e. the path must contain an even number of slash-separated path elements, like:
functions.firestore.document('Manager/Quote').onCreate()
or
functions.firestore.document('Manager/{quoteId}').onCreate()
or, for a subcollection,
functions.firestore.document('Manager/{ManagerId}/subColl/{docId}').onCreate()
You most probably want to use a wildcard, as shown in the second option above and as detailed in the documentation.
I would also suggest you watch the 3 videos about "JavaScript Promises" from the Firebase video series which emphasize how it is important to correctly manage the Cloud Function life cycle, by returning a Promise when all the asynchronous work is complete.