Im currently working on a firebase cloud function which needs to work with my firestore. The structure of my firebase is the following:
chatrooms/{chatID}/{chatID}/anymessage
Both chatIDs are same, they resemble an individual chatroom and each chatroom has anymessages inside. Also, each chatroom has a "hello" document in which I have crucial data I need to use inside my cloud function because I need to extract a key from there so I can send a push notification.
This is my cloud function Im trying to deploy currently:
exports.createpushnotification = functions.firestore.document('chatrooms/{chatID}/{chatID}/hello').onUpdate((change, context) => {
const keyofuser1 = change.after.data().partner1pushkey; //key to use for push notification
fetch("https://exp.host/--/api/v2/push/send", {
method:"POST",
headers:{
"Accept": "application/json",
"Content-Type": "application/json"
},
body:JSON.stringify({"to":keyofuser1, "body":"New Message!"})
})
})
Basically I want a cloud function which goes into each chatroom directory, fetches the "hello" file from there and waits for it to update and when it does, execute the fetch operation. Unluckily I get an error and even with --debug I can not see any error log that could help me:
Functions deploy had errors with the following functions: createpushnotification(us-central1)
To try redeploying those functions, run: firebase deploy --only "functions:createpushnotification"
To continue deploying other features (such as database), run: firebase deploy --except functions [2021-08-23T07:33:26.669Z] Error during update for projects/*********/locations/us-central1/functions/createpushnotification:
Error: Functions did not deploy properly.
What am I doing wrong here?
returnbeforefetch(...). Also can you share a screenshot of your Firestore doc?chatrooms/{chatID}/{chatID}/anymessagewhy do you havechatIDtwice? - Dharmaraj