@dongdev/fca-unofficial 2.0.31 → 3.0.0

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.
@@ -1,379 +1,272 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const { Readable } = require("stream");
1
+ /**
2
+ * Create by Donix-VN (DongDev)
3
+ * Don't change credit
4
+ * Send a message using MQTT.
5
+ * @param {string} text - The text of the message to send.
6
+ * @param {string} threadID - The ID of the thread to send the message to.
7
+ * @param {string} [msgReplace] - Optional. The message ID of the message to replace.
8
+ * @param {Array<Buffer|Stream>} [attachments] - Optional. The attachments to send with the message.
9
+ * @param {function} [callback] - Optional. The callback function to call when the message is sent.
10
+ * @returns {Promise<object>} A promise that resolves with the bodies of the sent message.
11
+ */
12
+
13
+ "use strict";
4
14
  const log = require("npmlog");
5
- const allowedProperties = {
6
- attachment: true,
7
- url: true,
8
- sticker: true,
9
- emoji: true,
10
- emojiSize: true,
11
- body: true,
12
- mentions: true,
13
- location: true,
14
- asPage: true
15
- };
16
- const { isReadableStream } = require("../../utils/constants");
17
15
  const { parseAndCheckLogin } = require("../../utils/client");
18
- const { getType, generateThreadingID, generateTimestampRelative, generateOfflineThreadingID, getSignatureID } = require("../../utils/format");
16
+ const { getType } = require("../../utils/format");
17
+ const { isReadableStream } = require("../../utils/constants");
18
+ const { generateOfflineThreadingID } = require("../../utils/format");
19
19
 
20
20
  module.exports = function (defaultFuncs, api, ctx) {
21
- function toReadable(input) {
22
- if (isReadableStream(input)) return input;
23
- if (Buffer.isBuffer(input)) return Readable.from(input);
24
- if (typeof input === "string" && fs.existsSync(input) && fs.statSync(input).isFile()) return fs.createReadStream(path.resolve(input));
25
- throw { error: "Unsupported attachment input. Use stream/buffer/filepath." };
26
- }
27
-
28
- function uploadAttachment(attachments, callback) {
29
- const uploads = [];
30
- for (let i = 0; i < attachments.length; i++) {
31
- if (!isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + getType(attachments[i]) + "." };
32
- const form = { upload_1024: attachments[i], voice_clip: "true" };
33
- uploads.push(
34
- defaultFuncs
35
- .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {}, {})
36
- .then(parseAndCheckLogin(ctx, defaultFuncs))
37
- .then(resData => {
38
- if (resData.error) throw resData;
39
- return resData.payload.metadata[0];
40
- })
41
- );
42
- }
43
- Promise.all(uploads)
44
- .then(resData => callback(null, resData))
45
- .catch(err => {
46
- log.error("uploadAttachment", err);
47
- callback(err);
48
- });
49
- }
21
+ const hasLinks = s => typeof s === "string" && /(https?:\/\/|www\.|t\.me\/|fb\.me\/|youtu\.be\/|facebook\.com\/|youtube\.com\/)/i.test(s);
22
+ const emojiSizes = { small: 1, medium: 2, large: 3 };
50
23
 
51
- function getUrl(url, callback) {
52
- const form = { image_height: 960, image_width: 960, uri: url };
53
- defaultFuncs
54
- .post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
55
- .then(parseAndCheckLogin(ctx, defaultFuncs))
56
- .then(resData => {
57
- if (resData.error) return callback(resData);
58
- if (!resData.payload) return callback({ error: "Invalid url" });
59
- callback(null, resData.payload.share_data.share_params);
60
- })
61
- .catch(err => {
62
- log.error("getUrl", err);
63
- callback(err);
64
- });
65
- }
66
-
67
- function sleep(ms) {
68
- return new Promise(r => setTimeout(r, ms));
24
+ async function uploadAttachment(streams) {
25
+ const uploads = streams.map(stream => {
26
+ if (!isReadableStream(stream)) throw { error: "Attachment should be a readable stream and not " + getType(stream) + "." };
27
+ const form = { upload_1024: stream, voice_clip: "true" };
28
+ return defaultFuncs
29
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
30
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
31
+ .then(resData => {
32
+ if (resData.error) throw resData;
33
+ return resData.payload.metadata[0];
34
+ });
35
+ });
36
+ return Promise.all(uploads);
69
37
  }
70
38
 
71
- async function postWithRetry(url, jar, form, tries = 3) {
72
- let lastErr;
73
- for (let i = 0; i < tries; i++) {
74
- try {
75
- const res = await defaultFuncs.post(url, jar, form).then(parseAndCheckLogin(ctx, defaultFuncs));
76
- if (res && !res.error) return res;
77
- lastErr = res;
78
- if (res && (res.error === 1545003 || res.error === 368)) await sleep(500 * (i + 1));
79
- else break;
80
- } catch (e) {
81
- lastErr = e;
82
- await sleep(500 * (i + 1));
39
+ function extractIdsFromPayload(payload) {
40
+ let messageID = null;
41
+ let threadID = null;
42
+ function walk(n) {
43
+ if (Array.isArray(n)) {
44
+ if (n[0] === 5 && (n[1] === "replaceOptimsiticMessage" || n[1] === "replaceOptimisticMessage")) {
45
+ messageID = String(n[3]);
46
+ }
47
+ if (n[0] === 5 && n[1] === "writeCTAIdToThreadsTable") {
48
+ const a = n[2];
49
+ if (Array.isArray(a) && a[0] === 19) threadID = String(a[1]);
50
+ }
51
+ for (const x of n) walk(x);
83
52
  }
84
53
  }
85
- throw lastErr || { error: "Send failed" };
54
+ walk(payload?.step);
55
+ return { threadID, messageID };
86
56
  }
87
57
 
88
- function applyPageAuthor(form, msg) {
89
- const pageID = msg && msg.asPage ? msg.asPage : ctx.globalOptions.pageID;
90
- if (!pageID) return;
91
- form["author"] = "fbid:" + pageID;
92
- form["specific_to_list[1]"] = "fbid:" + pageID;
93
- form["creator_info[creatorID]"] = ctx.userID;
94
- form["creator_info[creatorType]"] = "direct_admin";
95
- form["creator_info[labelType]"] = "sent_message";
96
- form["creator_info[pageID]"] = pageID;
97
- form["request_user_id"] = pageID;
98
- form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
58
+ function publishWithAck(content, text, reqID, callback) {
59
+ return new Promise((resolve, reject) => {
60
+ let done = false;
61
+ const cleanup = () => {
62
+ if (done) return;
63
+ done = true;
64
+ ctx.mqttClient.removeListener("message", handleRes);
65
+ };
66
+ const handleRes = (topic, message) => {
67
+ if (topic !== "/ls_resp") return;
68
+ let jsonMsg;
69
+ try {
70
+ jsonMsg = JSON.parse(message.toString());
71
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
72
+ } catch {
73
+ return;
74
+ }
75
+ if (jsonMsg.request_id !== reqID) return;
76
+ const { threadID, messageID } = extractIdsFromPayload(jsonMsg.payload);
77
+ const bodies = { body: text || null, messageID, threadID };
78
+ cleanup();
79
+ callback && callback(undefined, bodies);
80
+ resolve(bodies);
81
+ };
82
+ ctx.mqttClient.on("message", handleRes);
83
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(content), { qos: 1, retain: false }, err => {
84
+ if (err) {
85
+ cleanup();
86
+ callback && callback(err);
87
+ reject(err);
88
+ }
89
+ });
90
+ setTimeout(() => {
91
+ if (done) return;
92
+ cleanup();
93
+ const err = { error: "Timeout waiting for ACK" };
94
+ callback && callback(err);
95
+ reject(err);
96
+ }, 15000);
97
+ });
99
98
  }
100
99
 
101
- function applyMentions(msg, form) {
102
- if (!msg.mentions || !msg.mentions.length) return;
103
- let body = typeof msg.body === "string" ? msg.body : "";
104
- const need = [];
100
+ function buildMentionData(msg, baseBody) {
101
+ if (!msg.mentions || !Array.isArray(msg.mentions) || !msg.mentions.length) return null;
102
+ const base = typeof baseBody === "string" ? baseBody : "";
103
+ const ids = [];
104
+ const offsets = [];
105
+ const lengths = [];
106
+ const types = [];
107
+ let cursor = 0;
105
108
  for (const m of msg.mentions) {
106
- const tag = String(m.tag || "");
107
- if (tag && !body.includes(tag)) need.push(tag);
109
+ const raw = String(m.tag || "");
110
+ const name = raw.replace(/^@+/, "");
111
+ const start = Number.isInteger(m.fromIndex) ? m.fromIndex : cursor;
112
+ let idx = base.indexOf(raw, start);
113
+ let adj = 0;
114
+ if (idx === -1) {
115
+ idx = base.indexOf(name, start);
116
+ adj = 0;
117
+ } else {
118
+ adj = raw.length - name.length;
119
+ }
120
+ if (idx < 0) {
121
+ idx = 0;
122
+ adj = 0;
123
+ }
124
+ const off = idx + adj;
125
+ ids.push(String(m.id || 0));
126
+ offsets.push(off);
127
+ lengths.push(name.length);
128
+ types.push("p");
129
+ cursor = off + name.length;
108
130
  }
109
- if (need.length) body = (body ? body + " " : "") + need.join(" ");
110
- const emptyChar = "\u200E";
111
- form["body"] = emptyChar + body;
112
- let searchFrom = 0;
113
- msg.mentions.forEach((m, i) => {
114
- const tag = String(m.tag || "");
115
- const from = typeof m.fromIndex === "number" ? m.fromIndex : searchFrom;
116
- const off = Math.max(0, body.indexOf(tag, from));
117
- form[`profile_xmd[${i}][offset]`] = off + 1;
118
- form[`profile_xmd[${i}][length]`] = tag.length;
119
- form[`profile_xmd[${i}][id]`] = m.id || 0;
120
- form[`profile_xmd[${i}][type]`] = "p";
121
- searchFrom = off + tag.length;
122
- });
131
+ return {
132
+ mention_ids: ids.join(","),
133
+ mention_offsets: offsets.join(","),
134
+ mention_lengths: lengths.join(","),
135
+ mention_types: types.join(",")
136
+ };
123
137
  }
124
138
 
125
- function finalizeHasAttachment(form) {
126
- const keys = ["image_ids", "gif_ids", "file_ids", "video_ids", "audio_ids", "sticker_id", "shareable_attachment[share_params]"];
127
- form.has_attachment = keys.some(k => k in form && (Array.isArray(form[k]) ? form[k].length > 0 : !!form[k]));
139
+ function coerceMsg(x) {
140
+ if (x == null) return { body: "" };
141
+ if (typeof x === "string") return { body: x };
142
+ if (typeof x === "object") return x;
143
+ return { body: String(x) };
128
144
  }
129
145
 
130
- function extractMessageInfo(resData, fallbackThreadID) {
131
- let messageID = null;
132
- let threadFBID = null;
133
- let timestamp = null;
134
- const actions = resData && resData.payload && Array.isArray(resData.payload.actions) ? resData.payload.actions : null;
135
- if (actions && actions.length) {
136
- const v = actions.find(x => x && x.message_id) || actions[0];
137
- messageID = v && v.message_id ? v.message_id : null;
138
- threadFBID = (v && (v.thread_fbid || v.thread_id)) || fallbackThreadID || null;
139
- timestamp = v && v.timestamp ? v.timestamp : null;
146
+ return async function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
147
+ if (typeof threadID === "function") return threadID({ error: "Pass a threadID as a second argument." });
148
+ if (typeof callback === "string" && !replyToMessage) {
149
+ replyToMessage = callback;
150
+ callback = () => { };
140
151
  }
141
- if (!messageID) messageID = (resData && resData.payload && resData.payload.message_id) || resData.message_id || null;
142
- if (!threadFBID) threadFBID = (resData && resData.payload && resData.payload.thread_id) || fallbackThreadID || null;
143
- if (!timestamp) timestamp = (resData && resData.timestamp) || Date.now();
144
- if (!messageID) return null;
145
- return { threadID: threadFBID, messageID, timestamp };
146
- }
147
-
148
- function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
149
- if (getType(threadID) === "Array") {
150
- for (let i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
151
- form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
152
- form["client_thread_id"] = "root:" + messageAndOTID;
153
- } else {
154
- if (isSingleUser) {
155
- form["specific_to_list[0]"] = "fbid:" + threadID;
156
- form["specific_to_list[1]"] = "fbid:" + ctx.userID;
157
- form["other_user_fbid"] = threadID;
158
- } else {
159
- form["thread_fbid"] = threadID;
160
- }
152
+ if (typeof callback !== "function") callback = () => { };
153
+ if (!threadID) {
154
+ const err = { error: "threadID is required" };
155
+ callback(err);
156
+ throw err;
161
157
  }
162
- postWithRetry("https://www.facebook.com/messaging/send/", ctx.jar, form)
163
- .then(resData => {
164
- if (!resData) return callback({ error: "Send message failed." });
165
- if (resData.error) {
166
- if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
167
- else log.error("sendMessage", resData);
168
- return callback(resData);
169
- }
170
- const info = extractMessageInfo(resData, getType(threadID) === "Array" ? null : String(threadID));
171
- if (!info) return callback({ error: "Cannot parse message info." });
172
- callback(null, info);
173
- })
174
- .catch(err => {
175
- log.error("sendMessage", err);
176
- if (getType(err) === "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
177
- callback(err);
178
- });
179
- }
180
158
 
181
- function sendOnce(baseForm, threadID, isSingleUser) {
182
- const otid = generateOfflineThreadingID();
183
- const form = { ...baseForm, offline_threading_id: otid, message_id: otid };
184
- return new Promise((resolve, reject) => {
185
- sendContent(form, threadID, isSingleUser, otid, (err, info) => (err ? reject(err) : resolve(info)));
186
- });
187
- }
159
+ const m = coerceMsg(msg);
160
+ const baseBody = m.body != null ? String(m.body) : "";
161
+ const reqID = Math.floor(100 + Math.random() * 900);
162
+ const epoch = (BigInt(Date.now()) << 22n).toString();
188
163
 
189
- function send(form, threadID, messageAndOTID, callback, isGroup) {
190
- if (getType(threadID) === "Array") return sendContent(form, threadID, false, messageAndOTID, callback);
191
- if (getType(isGroup) === "Boolean") return sendContent(form, threadID, !isGroup, messageAndOTID, callback);
192
- sendOnce(form, threadID, false)
193
- .then(info => callback(null, info))
194
- .catch(() => {
195
- sendOnce(form, threadID, true)
196
- .then(info => callback(null, info))
197
- .catch(err => callback(err));
198
- });
199
- }
164
+ const payload0 = {
165
+ thread_id: String(threadID),
166
+ otid: generateOfflineThreadingID(),
167
+ source: 2097153,
168
+ send_type: 1,
169
+ sync_group: 1,
170
+ mark_thread_read: 1,
171
+ text: baseBody === "" ? null : baseBody,
172
+ initiating_source: 0,
173
+ skip_url_preview_gen: 0,
174
+ text_has_links: hasLinks(baseBody) ? 1 : 0,
175
+ multitab_env: 0,
176
+ metadata_dataclass: JSON.stringify({ media_accessibility_metadata: { alt_text: null } })
177
+ };
200
178
 
201
- function handleUrl(msg, form, callback, cb) {
202
- if (msg.url) {
203
- form["shareable_attachment[share_type]"] = "100";
204
- getUrl(msg.url, function (err, params) {
205
- if (err) return callback(err);
206
- form["shareable_attachment[share_params]"] = params;
207
- cb();
208
- });
209
- } else cb();
210
- }
179
+ const mentionData = buildMentionData(m, baseBody);
180
+ if (mentionData) payload0.mention_data = mentionData;
211
181
 
212
- function handleLocation(msg, form, callback, cb) {
213
- if (msg.location) {
214
- if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
215
- form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
216
- form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
217
- form["location_attachment[is_current_location]"] = !!msg.location.current;
182
+ if (m.sticker) {
183
+ payload0.send_type = 2;
184
+ payload0.sticker_id = m.sticker;
218
185
  }
219
- cb();
220
- }
221
186
 
222
- function handleSticker(msg, form, callback, cb) {
223
- if (msg.sticker) form["sticker_id"] = msg.sticker;
224
- cb();
225
- }
226
-
227
- function handleEmoji(msg, form, callback, cb) {
228
- if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
229
- if (msg.emoji) {
230
- if (msg.emojiSize == null) msg.emojiSize = "medium";
231
- if (msg.emojiSize !== "small" && msg.emojiSize !== "medium" && msg.emojiSize !== "large") return callback({ error: "emojiSize property is invalid" });
232
- if (form["body"] != null && form["body"] !== "") return callback({ error: "body is not empty" });
233
- form["body"] = msg.emoji;
234
- form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
187
+ if (m.emoji) {
188
+ const size = !isNaN(m.emojiSize) ? Number(m.emojiSize) : emojiSizes[m.emojiSize || "small"] || 1;
189
+ payload0.send_type = 1;
190
+ payload0.text = m.emoji;
191
+ payload0.hot_emoji_size = Math.min(3, Math.max(1, size));
235
192
  }
236
- cb();
237
- }
238
193
 
239
- function splitAttachments(list) {
240
- if (!Array.isArray(list)) list = [list];
241
- const ids = [];
242
- const streams = [];
243
- for (const a of list) {
244
- if (Array.isArray(a) && /_id$/.test(a[0])) {
245
- ids.push([a[0], String(a[1])]);
246
- continue;
247
- }
248
- if (a && typeof a === "object") {
249
- if (a.id && a.type && /_id$/.test(a.type)) {
250
- ids.push([a.type, String(a.id)]);
251
- continue;
252
- }
253
- const k = Object.keys(a || {}).find(x => /_id$/.test(x));
254
- if (k) {
255
- ids.push([k, String(a[k])]);
256
- continue;
257
- }
258
- }
259
- streams.push(toReadable(a));
194
+ if (m.location && m.location.latitude != null && m.location.longitude != null) {
195
+ payload0.send_type = 1;
196
+ payload0.location_data = {
197
+ coordinates: { latitude: m.location.latitude, longitude: m.location.longitude },
198
+ is_current_location: !!m.location.current,
199
+ is_live_location: !!m.location.live
200
+ };
260
201
  }
261
- return { ids, streams };
262
- }
263
202
 
264
- function handleAttachment(msg, form, callback, cb) {
265
- if (!msg.attachment) return cb();
266
- form["image_ids"] = [];
267
- form["gif_ids"] = [];
268
- form["file_ids"] = [];
269
- form["video_ids"] = [];
270
- form["audio_ids"] = [];
271
- const { ids, streams } = splitAttachments(msg.attachment);
272
- for (const [type, id] of ids) form[`${type}s`].push(id);
273
- if (!streams.length) return cb();
274
- uploadAttachment(streams, function (err, files) {
275
- if (err) return callback(err);
276
- files.forEach(function (file) {
277
- const type = Object.keys(file)[0];
278
- form[type + "s"].push(file[type]);
279
- });
280
- cb();
281
- });
282
- }
283
-
284
- function handleMention(msg, form, callback, cb) {
285
- try {
286
- applyMentions(msg, form);
287
- cb();
288
- } catch (e) {
289
- callback(e);
203
+ if (replyToMessage) {
204
+ payload0.reply_metadata = { reply_source_id: replyToMessage, reply_source_type: 1, reply_type: 0 };
290
205
  }
291
- }
292
-
293
- return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
294
- const isFn = v => typeof v === "function";
295
- const isStr = v => typeof v === "string";
296
206
 
297
- if (typeof isGroup === "undefined") isGroup = null;
298
- if (!callback && (getType(threadID) === "Function" || getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
299
-
300
- if (isStr(callback) && isFn(replyToMessage)) {
301
- const t = callback;
302
- callback = replyToMessage;
303
- replyToMessage = t;
304
- } else if (!replyToMessage && isStr(callback)) {
305
- replyToMessage = callback;
306
- callback = null;
207
+ if (m.attachment) {
208
+ payload0.send_type = 3;
209
+ if (payload0.text === "") payload0.text = null;
210
+ payload0.attachment_fbids = [];
211
+ let list = m.attachment;
212
+ if (getType(list) !== "Array") list = [list];
213
+ const idsFromPairs = [];
214
+ const streams = [];
215
+ for (const it of list) {
216
+ if (Array.isArray(it) && typeof it[0] === "string") {
217
+ idsFromPairs.push(String(it[1]));
218
+ } else if (isReadableStream(it)) {
219
+ streams.push(it);
220
+ }
221
+ }
222
+ if (idsFromPairs.length) payload0.attachment_fbids.push(...idsFromPairs);
223
+ if (streams.length) {
224
+ try {
225
+ const files = await uploadAttachment(streams);
226
+ for (const file of files) {
227
+ const key = Object.keys(file)[0];
228
+ payload0.attachment_fbids.push(file[key]);
229
+ }
230
+ } catch (err) {
231
+ log.error("uploadAttachment", err);
232
+ callback(err);
233
+ throw err;
234
+ }
235
+ }
307
236
  }
308
237
 
309
- let resolveFunc = function () { };
310
- let rejectFunc = function () { };
311
- const returnPromise = new Promise(function (resolve, reject) {
312
- resolveFunc = resolve;
313
- rejectFunc = reject;
314
- });
315
- if (!callback) {
316
- callback = function (err, data) {
317
- if (err) return rejectFunc(err);
318
- resolveFunc(data);
319
- };
320
- }
321
- const msgType = getType(msg);
322
- const threadIDType = getType(threadID);
323
- const messageIDType = getType(replyToMessage);
324
- if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
325
- if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
326
- if (replyToMessage && messageIDType !== "String") return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
327
- if (msgType === "String") msg = { body: msg };
328
- const disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
329
- if (disallowedProperties.length > 0) return callback({ error: "Disallowed props: `" + disallowedProperties.join(", ") + "`" });
330
- const messageAndOTID = generateOfflineThreadingID();
331
- const form = {
332
- client: "mercury",
333
- action_type: "ma-type:user-generated-message",
334
- author: "fbid:" + ctx.userID,
335
- timestamp: Date.now(),
336
- timestamp_absolute: "Today",
337
- timestamp_relative: generateTimestampRelative(),
338
- timestamp_time_passed: "0",
339
- is_unread: false,
340
- is_cleared: false,
341
- is_forward: false,
342
- is_filtered_content: false,
343
- is_filtered_content_bh: false,
344
- is_filtered_content_account: false,
345
- is_filtered_content_quasar: false,
346
- is_filtered_content_invalid_app: false,
347
- is_spoof_warning: false,
348
- source: "source:chat:web",
349
- "source_tags[0]": "source:chat",
350
- body: msg.body ? msg.body.toString() : "",
351
- html_body: false,
352
- ui_push_phase: "V3",
353
- status: "0",
354
- offline_threading_id: messageAndOTID,
355
- message_id: messageAndOTID,
356
- threading_id: generateThreadingID(ctx.clientID),
357
- ephemeral_ttl_mode: "0",
358
- manual_retry_cnt: "0",
359
- signatureID: getSignatureID(),
360
- replied_to_message_id: replyToMessage ? replyToMessage.toString() : ""
238
+ const content = {
239
+ app_id: "2220391788200892",
240
+ payload: {
241
+ tasks: [
242
+ {
243
+ label: "46",
244
+ payload: payload0,
245
+ queue_name: String(threadID),
246
+ task_id: 400,
247
+ failure_count: null
248
+ },
249
+ {
250
+ label: "21",
251
+ payload: {
252
+ thread_id: String(threadID),
253
+ last_read_watermark_ts: Date.now(),
254
+ sync_group: 1
255
+ },
256
+ queue_name: String(threadID),
257
+ task_id: 401,
258
+ failure_count: null
259
+ }
260
+ ],
261
+ epoch_id: epoch,
262
+ version_id: "24804310205905615",
263
+ data_trace_id: "#" + Buffer.from(String(Math.random())).toString("base64").replace(/=+$/g, "")
264
+ },
265
+ request_id: reqID,
266
+ type: 3
361
267
  };
362
- applyPageAuthor(form, msg);
363
- handleLocation(msg, form, callback, () =>
364
- handleSticker(msg, form, callback, () =>
365
- handleAttachment(msg, form, callback, () =>
366
- handleUrl(msg, form, callback, () =>
367
- handleEmoji(msg, form, callback, () =>
368
- handleMention(msg, form, callback, () => {
369
- finalizeHasAttachment(form);
370
- send(form, threadID, messageAndOTID, callback, isGroup);
371
- })
372
- )
373
- )
374
- )
375
- )
376
- );
377
- return returnPromise;
268
+ content.payload.tasks.forEach(t => (t.payload = JSON.stringify(t.payload)));
269
+ content.payload = JSON.stringify(content.payload);
270
+ return publishWithAck(content, baseBody, reqID, callback);
378
271
  };
379
272
  };