I am new to firebase cloud functions. So, I followed the tutorial in firebase youtube channel. So, I created a function that should trigger when firestore document added,but it didn't trigger.
this is the function
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.whenAddData = functions.firestore
.document("chats/{userId}")
.onCreate((change, context) => {
const msg = change.data().msg;
const modifiedMsg = addImoji(msg);
console.log("data changing");
return change.ref({ msg: modifiedMsg });
});
const addImoji = (msg) => {
return msg.replace(/\bPizza\b/g, " ???? ");
};
firebase-functions version: "^3.6.1"