backend-manager 4.2.6 → 4.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "4.2.6",
3
+ "version": "4.2.7",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -4,6 +4,7 @@ const BAD_TOKEN_REASONS = [
4
4
  'messaging/invalid-registration-token',
5
5
  'messaging/registration-token-not-registered',
6
6
  ];
7
+ const BATCH_SIZE = 500;
7
8
 
8
9
  // Module
9
10
  function Module() {
@@ -114,7 +115,7 @@ Module.prototype.processTokens = async function (note, options) {
114
115
  {
115
116
  collection: PATH_NOTIFICATIONS,
116
117
  where: queryConditions,
117
- batchSize: 1000,
118
+ batchSize: BATCH_SIZE,
118
119
  log: true,
119
120
  }
120
121
  )
@@ -126,6 +127,7 @@ Module.prototype.processTokens = async function (note, options) {
126
127
  });
127
128
  };
128
129
 
130
+ // https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices
129
131
  Module.prototype.sendBatch = async function (batch, note, id) {
130
132
  const self = this;
131
133
 
@@ -141,9 +143,39 @@ Module.prototype.sendBatch = async function (batch, note, id) {
141
143
  try {
142
144
  // Log
143
145
  assistant.log(`Sending batch ID: ${id}`);
146
+ console.log('🚩🚩🚩🚩🚩', 1, ); // FLAG
147
+ assistant.log(`batch`, batch);
148
+ assistant.log(`note`, note);
144
149
 
145
150
  // Send the batch
146
- const response = await admin.messaging().sendToDevice(batch, note);
151
+ // const response = await admin.messaging().sendToDevice(batch, note);
152
+ try {
153
+ const response = await admin.messaging().sendMulticast({
154
+ tokens: batch,
155
+ notification: {
156
+ title: 'Your Notification Title',
157
+ body: 'This is the notification message.'
158
+ },
159
+ data: {
160
+ customDataKey: 'customDataValue' // Optional custom data payload
161
+ }
162
+ })
163
+
164
+ assistant.log(`🚩🚩🚩🚩🚩 222 response ${id}`, response); // FLAG
165
+ } catch (e) {
166
+ assistant.error(`🚩🚩🚩🚩🚩 222 error ${id}`, e);
167
+ }
168
+
169
+ try {
170
+ const response = await admin.messaging().sendMulticast({
171
+ tokens: batch,
172
+ notification: note.notification,
173
+ })
174
+
175
+ assistant.log(`🚩🚩🚩🚩🚩 333 response ${id}`, response); // FLAG
176
+ } catch (e) {
177
+ assistant.error(`🚩🚩🚩🚩🚩 333 error ${id}`, e);
178
+ }
147
179
 
148
180
  // Log
149
181
  assistant.log(`Sent batch ID: ${id}, Success: ${response.successCount}, Failures: ${response.failureCount}`);
@@ -170,7 +202,7 @@ Module.prototype.cleanTokens = async function (batch, results, id) {
170
202
  const payload = self.payload;
171
203
 
172
204
  // Log
173
- assistant.log(`Cleaning tokens of batch ID: ${id}`);
205
+ assistant.log(`Cleaning ${results.length} tokens of batch ID: ${id}`);
174
206
 
175
207
  // Filter out bad tokens
176
208
  const cleanPromises = results