我在我的firebase控制台中部署的Typescript中有这个功能:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
admin.initializeApp()
export const onEditModeUpdate =
functions.firestore.document("Settings/ShiftsEditMode").onUpdate(change => {
if (change.after) {
const after = change.after.data();
const payload = {
data: {
temp: String(after.temp),
conditions: String(after.conditions)
}
}
return admin.messaging().sendToTopic("Settings/ShiftsEditMode", payload)
}
else {
return null;
}
})
部署是正确的,但是当我更改数据时,我在控制台日志中收到错误:
Error: Topic provided to sendToTopic() must be a string which matches the format "/topics/[a-zA-Z0-9-_.~%]+".
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:253:16)
at Messaging.validateTopic (/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:964:19)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:650:19
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
任何建议我做错了请。
仔细阅读错误消息:
错误:提供给sendToTopic()的主题必须是匹配格式“/topics/[a-zA-Z0-9-_.~%]+”的字符串。
您提供的字符串“Settings / ShiftsEditMode”与所需的模式不匹配。该模式表示该字符串应以“/ topics /”开头。字符串的其余部分(主题名称)只能包含字母,数字,下划线,点,波浪号和百分比。您提供的字符串也与该模式不匹配,因为它包含非法斜杠。