@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.
- package/CHANGELOG.md +6 -0
- package/LICENSE-MIT +1 -1
- package/README.md +402 -95
- package/func/checkUpdate.js +0 -1
- package/index.d.ts +685 -607
- package/package.json +1 -1
- package/src/api/messaging/createThemeAI.js +98 -0
- package/src/api/messaging/sendMessage.js +234 -341
- package/src/api/socket/core/connectMqtt.js +58 -11
- package/src/api/socket/core/emitAuth.js +39 -9
- package/src/api/socket/core/parseDelta.js +13 -4
- package/src/api/socket/listenMqtt.js +79 -10
- package/src/utils/client.js +98 -25
- package/src/utils/request.js +30 -12
- package/src/api/messaging/sendMessageMqtt.js +0 -323
|
@@ -1,379 +1,272 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
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
|
-
|
|
22
|
-
|
|
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
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
54
|
+
walk(payload?.step);
|
|
55
|
+
return { threadID, messageID };
|
|
86
56
|
}
|
|
87
57
|
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
102
|
-
if (!msg.mentions || !msg.mentions.length) return;
|
|
103
|
-
|
|
104
|
-
const
|
|
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
|
|
107
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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 (
|
|
142
|
-
if (!
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
202
|
-
if (
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
265
|
-
|
|
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 (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
};
|