我只是想使用 Google Cloud Functions 向订阅主题组合的设备发送通知。
文档说:
"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"
我尝试做的是:
var topicsConditions = `'${type}' in topics && ('${area}' in topics || '${city}' in topics)`;
// Send a message to devices subscribed to the provided topic.
admin.messaging().sendToCondition(topicsConditions, notificationPayload)
.then(function(response) {
// See the MessagingTopicResponse reference documentation for the
// contents of response.
console.log("Successfully sent message:", response);
})
.catch(function(error) {
console.log("Error sending message:", error);
});
但我不断收到此错误:
Error sending message: { Error: Invalid argument provided. Raw server response: "Invalid "condition" field: only support 'topics' conditions ". Status code: 400. at FirebaseMessagingError.Error (native) at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28) at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28) at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16) at /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:115:23 at process._tickDomainCallback (internal/process/next_tick.js:135:7) errorInfo: { code: 'messaging/invalid-argument', message: 'Invalid argument provided. Raw server response: "Invalid "condition" field: only support \'topics\' conditions\n". Status code: 400.' }, codePrefix: 'messaging' }
任何人都可以指导我正确的语法吗?
编辑:主题的日志输出为:
Topic conditions = 'MyType+' in topics && ('Giza, Egypt ' in topics || 'القاهرة الكبرى' in topics)
最佳答案
主题名称中可以使用的字符仅限于:
- 小写字母
a
到z
- 大写字母
A
到Z
- 数字
0
到9
- 字符
-
_
.
~
%
您的主题名称包含无效字符 +
、、
、空格和阿拉伯语。
更多详细信息请参见 the documentation :
Developers can choose any topic name that matches the regular expression: "[a-zA-Z0-9-_.~%]+"
有效条件字符串的示例是:
var topicsConditions = "'Aswan' in topics && ('Giza' in topics || 'Cairo' in topics)";
我在对 admin.messaging().sendToCondition() 的调用中成功使用了此字符串
关于node.js - 通过条件将 Firebase 云消息传递 (FCM) 发送到多个主题的正确语法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48652101/