如何使用插值字符串作为Firebase Cloud函数和Typescript的主题名称



我正在尝试编写一个向主题发送通知的云函数。目前,我将主题列为一个插值字符串,如下所示:

"topic": `Group: ${groupID}`,

然而,每当调用函数时,我都会得到以下错误: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);
});
});

有人对如何解决这个问题有什么建议吗?我似乎想不通,也找不到任何帖子。谢谢你的任何建议!如果你需要我附上更多的源代码,请告诉我!

通过查看错误,我认为您需要仔细检查主题名称,并确保其符合Firebase文档中的要求:

开发人员可以选择任何与正则表达式匹配的主题名称表达式:CCD_ 2。

最新更新