gpt4 book ai didi

node.js - 通过条件将 Firebase 云消息传递 (FCM) 发送到多个主题的正确语法是什么

转载 作者:太空宇宙 更新时间:2023-11-03 22:50:24 29 4
gpt4 key购买 nike

我只是想使用 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)

最佳答案

主题名称中可以使用的字符仅限于:

  • 小写字母az
  • 大写字母AZ
  • 数字09
  • 字符- _ . ~ %

您的主题名称包含无效字符 +、空格和阿拉伯语。

更多详细信息请参见 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com