I need help with my cloud function to send notifications to a topic. My current setup uses an interpolated string for the topic:
"topic": `Group: ${groupID}`,
Unfortunately, every time the function is triggered, I encounter an error message: malformed topic name
export const groupMessageReceived = functions.firestore
.document("Groups/{groupID}/Chat/{message}").onCreate((create, context) => {
const messageDoc = create.data();
const groupID = context.params.groupID;
console.log(`Group: ${groupID}`);
// const topicName = "Group: " + groupID;
// sending message to the person who is in the group
const message = {
"notification": {
"title": groupID,
"body": messageDoc.senderName + ": " + messageDoc.messageContent,
},
"topic": `Group: ${groupID}`,
};
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log("Successfully sent message:", response);
})
.catch((error) => {
console.log("Error sending message:", error);
});
});
I'm stuck on this issue and haven't been able to find a solution online. Any insight or suggestions would be greatly appreciated. Feel free to ask for more code if needed! Thank you.