通过条件将Firebase Cloud Messaging(FCM)发送到多个主题的正确语法是什么 [英] What is the correct syntax to send Firebase Cloud Messaging (FCM) to multiple topics via condition
问题描述
我只是想使用Google Cloud Functions将通知发送到订阅了主题组合的设备.
Simply I want to use the Google Cloud Functions to send notifications to devices that subscribe to a combination of topics.
文档说:
主题&&中的"TopicA"(主题中的"TopicB" |主题中的"TopicC")"
"'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);
});
但我一直收到此错误:
发送消息时出错:{错误:提供了无效的参数.原始服务器响应:无效的"条件"字段:仅支持主题"条件 .状态码:400. 在FirebaseMessagingError.Error(本机) 在FirebaseMessagingError.FirebaseError [作为构造函数](/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28) 在FirebaseMessagingError.PrefixedFirebaseError [作为构造函数](/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28) 在新的FirebaseMessagingError(/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16) 在/user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:115:23 在process._tickDomainCallback(内部/进程/next_tick.js:135:7) errorInfo: {代码:消息/无效参数", 消息:提供了无效的参数.原始服务器响应:无效的"条件"字段:仅支持\'topics \'条件\ n.状态码:400. }, codePrefix:'messaging'}
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' }
任何人都可以指导我使用正确的语法吗?
Anyone can direct me to the correct syntax?
主题的日志输出为:
主题&&中的主题条件="MyType +" (主题为埃及吉萨" |主题为"|القاهرةالكبرى")
Topic conditions = 'MyType+' in topics && ('Giza, Egypt ' in topics || 'القاهرة الكبرى' in topics)
推荐答案
主题名称中可能使用的字符限于:
The characters that may be used in a topic name are limited to:
- 小写字母
a
至z
- 大写字母
A
至Z
- 位数
0
至9
- 字符
-
_
.
~
%
- lowercase letters
a
toz
- uppercase letters
A
toZ
- digits
0
to9
- characters
-
_
.
~
%
您的主题名称包含无效字符+
,,
,空格和阿拉伯语.
Your topic names contain invalid characters +
, ,
, space, and Arabic.
更多详细信息位于文档:>
Further details are in the documentation:
开发人员可以选择与常规名称匹配的任何主题名称 表达式:"[a-zA-Z0-9 -_.〜%] +"
Developers can choose any topic name that matches the regular expression: "[a-zA-Z0-9-_.~%]+"
有效条件字符串的示例是:
An example of a valid condition string is:
var topicsConditions = "'Aswan' in topics && ('Giza' in topics || 'Cairo' in topics)";
我在调用admin.messaging().sendToCondition()
这篇关于通过条件将Firebase Cloud Messaging(FCM)发送到多个主题的正确语法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!