Simply I want to use the Google Cloud Functions to send notifications to devices that subscribe to a combination of topics.
The documentation says:
"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"
What I tried to do is:
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);
});
But I keep getting this 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' }
Anyone can direct me to the correct syntax?
Edit: The log output of the topics is:
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
toz
A
toZ
0
to9
-
_
.
~
%
Your topic names contain invalid characters
+
,,
, space, and Arabic.Further details are in the documentation:
An example of a valid condition string is:
I successfully used this string in a call to
admin.messaging().sendToCondition()