I am trying to implement push notifications and have the same cloud functions deployed for dev and prod. For dev I am able to receive the notifications every time:
But for prod I get an error and it will never send:
Here is my notifications method:
// shows the users of the chat channel
const messageId = functions.database.ref(
"/ChatMessages/{channelType}/{channelId}/{messageId}"
);
// HANDLE NEW NOTIFICATION
export const notificationCreatedEvent = messageId.onCreate((snapshot: any, event: any) => {
// channelType is for if it is a public or private chat- if it is public it will list the mountain
const { channelId } = event.params;
const messageData = snapshot.val();
const message = messageData.text;
const trimmedMessage = truncate(message, 20, true);
// notification channel
const notificationRef = admin
.database()
.ref(`/Notifications/${channelId}`);
const notificationBody = (message.slice(0, 12) === "https://fire") ? "new image message" : trimmedMessage
const payloadPrivateUser = {
notification: {
title: "Private Message",
body: "Message: "+notificationBody
}
}
const payload = {
notification: {
title: "Message in channel "+ channelId,
body: "Message: " + notificationBody
}
}
notificationRef
.once("value")
.then(async userListSnapshot => {
const userList = await (<any>Object).values(userListSnapshot.val());
const response = channelId.length > 50 ? await admin.messaging().sendToDevice(userList, payloadPrivateUser): await admin.messaging().sendToDevice(userList, payload);
}).catch(err=> {
console.log(err)
})
});
No idea why it would fire in one vs the other since both have the same promise error anyway?
This seems to be known problem, please check following questions:
Cloud Functions for Firebase - Billing account not configured
Hope it will help!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.