backend-manager 4.2.6 → 4.2.8
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
|
@@ -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:
|
|
118
|
+
batchSize: BATCH_SIZE,
|
|
118
119
|
log: true,
|
|
119
120
|
}
|
|
120
121
|
)
|
|
@@ -126,6 +127,12 @@ Module.prototype.processTokens = async function (note, options) {
|
|
|
126
127
|
});
|
|
127
128
|
};
|
|
128
129
|
|
|
130
|
+
// Sending using SDK
|
|
131
|
+
// https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices
|
|
132
|
+
|
|
133
|
+
// Manually sending
|
|
134
|
+
// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send
|
|
135
|
+
// https://firebase.google.com/docs/cloud-messaging/migrate-v1#provide-credentials-manually
|
|
129
136
|
Module.prototype.sendBatch = async function (batch, note, id) {
|
|
130
137
|
const self = this;
|
|
131
138
|
|
|
@@ -141,6 +148,53 @@ Module.prototype.sendBatch = async function (batch, note, id) {
|
|
|
141
148
|
try {
|
|
142
149
|
// Log
|
|
143
150
|
assistant.log(`Sending batch ID: ${id}`);
|
|
151
|
+
console.log('🚩🚩🚩🚩🚩', 1, ); // FLAG
|
|
152
|
+
assistant.log(`batch`, batch);
|
|
153
|
+
assistant.log(`note`, note);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
const response = await admin.messaging().sendMulticast({
|
|
157
|
+
tokens: batch,
|
|
158
|
+
notification: {
|
|
159
|
+
title: 'Your Notification Title',
|
|
160
|
+
body: 'This is the notification message.'
|
|
161
|
+
},
|
|
162
|
+
data: {
|
|
163
|
+
customDataKey: 'customDataValue' // Optional custom data payload
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
assistant.log(`🚩🚩🚩🚩🚩 222 response ${id}`, response); // FLAG
|
|
168
|
+
} catch (e) {
|
|
169
|
+
assistant.error(`🚩🚩🚩🚩🚩 222 error ${id}`, e);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
const response = await admin.messaging().sendMulticast({
|
|
174
|
+
tokens: batch,
|
|
175
|
+
notification: note.notification,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
assistant.log(`🚩🚩🚩🚩🚩 333 response ${id}`, response); // FLAG
|
|
179
|
+
} catch (e) {
|
|
180
|
+
assistant.error(`🚩🚩🚩🚩🚩 333 error ${id}`, e);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const messages = batch.map(token => ({
|
|
185
|
+
token: token,
|
|
186
|
+
notification: {
|
|
187
|
+
title: 'Your Notification Title',
|
|
188
|
+
body: 'This is the notification message.'
|
|
189
|
+
},
|
|
190
|
+
}));
|
|
191
|
+
|
|
192
|
+
const response = await admin.messaging().sendEach(messages);
|
|
193
|
+
|
|
194
|
+
assistant.log(`🚩🚩🚩🚩🚩 444 response ${id}`, response); // FLAG
|
|
195
|
+
} catch (e) {
|
|
196
|
+
assistant.error(`🚩🚩🚩🚩🚩 444 error ${id}`, e);
|
|
197
|
+
}
|
|
144
198
|
|
|
145
199
|
// Send the batch
|
|
146
200
|
const response = await admin.messaging().sendToDevice(batch, note);
|
|
@@ -170,7 +224,7 @@ Module.prototype.cleanTokens = async function (batch, results, id) {
|
|
|
170
224
|
const payload = self.payload;
|
|
171
225
|
|
|
172
226
|
// Log
|
|
173
|
-
assistant.log(`Cleaning tokens of batch ID: ${id}`);
|
|
227
|
+
assistant.log(`Cleaning ${results.length} tokens of batch ID: ${id}`);
|
|
174
228
|
|
|
175
229
|
// Filter out bad tokens
|
|
176
230
|
const cleanPromises = results
|