alicezetion 1.2.8 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +8 -1
- package/leiamnash/addExternalModule.js +6 -10
- package/leiamnash/addUserToGroup.js +16 -52
- package/leiamnash/changeAdminStatus.js +37 -69
- package/leiamnash/changeArchivedStatus.js +12 -26
- package/leiamnash/changeBio.js +6 -19
- package/leiamnash/changeBlockedStatus.js +3 -14
- package/leiamnash/changeGroupImage.js +16 -40
- package/leiamnash/changeNickname.js +11 -27
- package/leiamnash/changeThreadColor.js +10 -20
- package/leiamnash/changeThreadEmoji.js +10 -24
- package/leiamnash/chat.js +279 -414
- package/leiamnash/createNewGroup.js +12 -28
- package/leiamnash/createPoll.js +13 -25
- package/leiamnash/deleteMessage.js +12 -24
- package/leiamnash/deleteThread.js +11 -25
- package/leiamnash/forwardAttachment.js +13 -26
- package/leiamnash/forwardMessage.js +0 -0
- package/leiamnash/getCurrentUserID.js +1 -1
- package/leiamnash/getEmojiUrl.js +2 -4
- package/leiamnash/getFriendsList.js +10 -21
- package/leiamnash/getThreadHistory.js +58 -166
- package/leiamnash/getThreadHistoryDeprecated.js +20 -42
- package/leiamnash/getThreadInfo.js +25 -60
- package/leiamnash/getThreadInfoDeprecated.js +18 -42
- package/leiamnash/getThreadList.js +41 -66
- package/leiamnash/getThreadListDeprecated.js +14 -43
- package/leiamnash/getThreadPictures.js +17 -37
- package/leiamnash/getUserID.js +9 -14
- package/leiamnash/getUserInfo.js +12 -18
- package/leiamnash/handleFriendRequest.js +37 -52
- package/leiamnash/handleMessageRequest.js +14 -32
- package/leiamnash/httpGet.js +12 -17
- package/leiamnash/httpPost.js +12 -17
- package/leiamnash/listen.js +553 -0
- package/leiamnash/listenMqtt-Test.js +687 -0
- package/leiamnash/listenMqtt.js +1 -2
- package/leiamnash/logout.js +13 -20
- package/leiamnash/markAsDelivered.js +11 -22
- package/leiamnash/markAsRead.js +11 -21
- package/leiamnash/markAsReadAll.js +10 -20
- package/leiamnash/markAsSeen.js +7 -18
- package/leiamnash/muteThread.js +11 -18
- package/leiamnash/removeUserFromGroup.js +14 -48
- package/leiamnash/resolvePhotoUrl.js +8 -17
- package/leiamnash/searchForThread.js +10 -21
- package/leiamnash/sendTypingIndicator.js +14 -47
- package/leiamnash/setMessageReaction.js +12 -26
- package/leiamnash/setPostReaction.js +13 -26
- package/leiamnash/setTitle.js +13 -29
- package/leiamnash/threadColors.js +28 -44
- package/leiamnash/unfriend.js +9 -19
- package/leiamnash/unsendMessage.js +9 -19
- package/package.json +1 -1
- package/replit.nix +1 -3
- package/utils.js +0 -0
package/leiamnash/chat.js
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
A L I C E » this project recode by one
|
4
|
+
person LeiamNash
|
5
|
+
this will only work on
|
6
|
+
project alice
|
7
|
+
|
8
|
+
*/
|
9
|
+
|
1
10
|
"use strict";
|
2
11
|
|
3
12
|
var utils = require("../utils");
|
@@ -5,455 +14,311 @@ var log = require("npmlog");
|
|
5
14
|
var bluebird = require("bluebird");
|
6
15
|
|
7
16
|
var allowedProperties = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
attachment: true,
|
18
|
+
url: true,
|
19
|
+
sticker: true,
|
20
|
+
emoji: true,
|
21
|
+
emojiSize: true,
|
22
|
+
body: true,
|
23
|
+
mentions: true,
|
24
|
+
location: true,
|
16
25
|
};
|
17
26
|
|
18
|
-
module.exports = function
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
28
|
+
function uploadAttachment(attachments, callback) {
|
29
|
+
var uploads = [];
|
30
|
+
|
31
|
+
// create an array of promises
|
32
|
+
for (var i = 0; i < attachments.length; i++) {
|
33
|
+
if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
|
34
|
+
var form = {
|
35
|
+
upload_1024: attachments[i],
|
36
|
+
voice_clip: "true"
|
37
|
+
};
|
38
|
+
|
39
|
+
uploads.push(
|
40
|
+
defaultFuncs
|
41
|
+
.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
42
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
43
|
+
.then(function(resData) {
|
44
|
+
if (resData.error) throw resData;
|
45
|
+
// We have to return the data unformatted unless we want to change it
|
46
|
+
// back in sendMessage.
|
47
|
+
return resData.payload.metadata[0];
|
48
|
+
})
|
49
|
+
);
|
50
|
+
}
|
32
51
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
52
|
+
// resolve all promises
|
53
|
+
bluebird
|
54
|
+
.all(uploads)
|
55
|
+
.then(resData => callback(null, resData))
|
56
|
+
.catch(function(err) {
|
57
|
+
log.error("uploadAttachment", err);
|
58
|
+
return callback(err);
|
59
|
+
});
|
60
|
+
}
|
37
61
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
{}
|
45
|
-
)
|
46
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
47
|
-
.then(function (resData) {
|
48
|
-
if (resData.error) {
|
49
|
-
throw resData;
|
50
|
-
}
|
62
|
+
function getUrl(url, callback) {
|
63
|
+
var form = {
|
64
|
+
image_height: 960,
|
65
|
+
image_width: 960,
|
66
|
+
uri: url
|
67
|
+
};
|
51
68
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
69
|
+
defaultFuncs
|
70
|
+
.post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
|
71
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
72
|
+
.then(function(resData) {
|
73
|
+
if (resData.error) return callback(resData);
|
74
|
+
if (!resData.payload) return callback({ error: "Invalid url" });
|
75
|
+
callback(null, resData.payload.share_data.share_params);
|
76
|
+
})
|
77
|
+
.catch(function(err) {
|
78
|
+
log.error("getUrl", err);
|
79
|
+
return callback(err);
|
80
|
+
});
|
57
81
|
}
|
58
82
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
defaultFuncs
|
79
|
-
.post(
|
80
|
-
"https://www.facebook.com/message_share_attachment/fromURI/",
|
81
|
-
ctx.jar,
|
82
|
-
form
|
83
|
-
)
|
84
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
85
|
-
.then(function (resData) {
|
86
|
-
if (resData.error) {
|
87
|
-
return callback(resData);
|
83
|
+
function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
|
84
|
+
// There are three cases here:
|
85
|
+
// 1. threadID is of type array, where we're starting a new group chat with users
|
86
|
+
// specified in the array.
|
87
|
+
// 2. User is sending a message to a specific user.
|
88
|
+
// 3. No additional form params and the message goes to an existing group chat.
|
89
|
+
if (utils.getType(threadID) === "Array") {
|
90
|
+
for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
91
|
+
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
92
|
+
form["client_thread_id"] = "root:" + messageAndOTID;
|
93
|
+
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
94
|
+
} else {
|
95
|
+
// This means that threadID is the id of a user, and the chat
|
96
|
+
// is a single person chat
|
97
|
+
if (isSingleUser) {
|
98
|
+
form["specific_to_list[0]"] = "fbid:" + threadID;
|
99
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
100
|
+
form["other_user_fbid"] = threadID;
|
101
|
+
} else form["thread_fbid"] = threadID;
|
88
102
|
}
|
89
103
|
|
90
|
-
if (
|
91
|
-
|
104
|
+
if (ctx.globalOptions.pageID) {
|
105
|
+
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
106
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
107
|
+
form["creator_info[creatorID]"] = ctx.userID;
|
108
|
+
form["creator_info[creatorType]"] = "direct_admin";
|
109
|
+
form["creator_info[labelType]"] = "sent_message";
|
110
|
+
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
111
|
+
form["request_user_id"] = ctx.globalOptions.pageID;
|
112
|
+
form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
|
92
113
|
}
|
93
114
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
form["specific_to_list[0]"] = "fbid:" + threadID;
|
120
|
-
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
121
|
-
form["other_user_fbid"] = threadID;
|
122
|
-
} else {
|
123
|
-
form["thread_fbid"] = threadID;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
|
127
|
-
if (ctx.globalOptions.pageID) {
|
128
|
-
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
129
|
-
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
130
|
-
form["creator_info[creatorID]"] = ctx.userID;
|
131
|
-
form["creator_info[creatorType]"] = "direct_admin";
|
132
|
-
form["creator_info[labelType]"] = "sent_message";
|
133
|
-
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
134
|
-
form["request_user_id"] = ctx.globalOptions.pageID;
|
135
|
-
form["creator_info[profileURI]"] =
|
136
|
-
"https://www.facebook.com/profile.php?id=" + ctx.userID;
|
115
|
+
defaultFuncs
|
116
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
117
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
118
|
+
.then(function(resData) {
|
119
|
+
if (!resData) return callback({ error: "Send message failed." });
|
120
|
+
if (resData.error) {
|
121
|
+
if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
|
122
|
+
return callback(resData);
|
123
|
+
}
|
124
|
+
|
125
|
+
var messageInfo = resData.payload.actions.reduce(function(p, v) {
|
126
|
+
return ({
|
127
|
+
threadID: v.thread_fbid,
|
128
|
+
messageID: v.message_id,
|
129
|
+
timestamp: v.timestamp
|
130
|
+
} || p);
|
131
|
+
}, null);
|
132
|
+
|
133
|
+
return callback(null, messageInfo);
|
134
|
+
})
|
135
|
+
.catch(function(err) {
|
136
|
+
log.error("sendMessage", err);
|
137
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
138
|
+
return callback(err);
|
139
|
+
});
|
137
140
|
}
|
138
141
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
143
|
+
// fix lỗi = cach fetch threadID
|
144
|
+
// iq 5 trieu nam =))
|
145
|
+
if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
|
146
|
+
else {
|
147
|
+
var THREADFIX = "ThreadID".replace("ThreadID", threadID);
|
148
|
+
if (THREADFIX.length <= 15 && THREADFIX.indexOf(1) == 0) return sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
149
|
+
else if (THREADFIX.length >= 15) return sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
|
150
|
+
else return sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
|
145
151
|
}
|
152
|
+
}
|
146
153
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
154
|
+
function handleUrl(msg, form, callback, cb) {
|
155
|
+
if (msg.url) {
|
156
|
+
form["shareable_attachment[share_type]"] = "100";
|
157
|
+
getUrl(msg.url, function(err, params) {
|
158
|
+
if (err) return callback(err);
|
159
|
+
form["shareable_attachment[share_params]"] = params;
|
160
|
+
cb();
|
161
|
+
});
|
162
|
+
} else cb();
|
163
|
+
}
|
157
164
|
|
158
|
-
|
159
|
-
|
160
|
-
{
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
} || p
|
165
|
-
);
|
166
|
-
}, null);
|
167
|
-
|
168
|
-
return callback(null, messageInfo);
|
169
|
-
})
|
170
|
-
.catch(function (err) {
|
171
|
-
log.error("sendMessage", err);
|
172
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
173
|
-
ctx.loggedIn = false;
|
165
|
+
function handleLocation(msg, form, callback, cb) {
|
166
|
+
if (msg.location) {
|
167
|
+
if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
|
168
|
+
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
169
|
+
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
170
|
+
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
174
171
|
}
|
175
|
-
|
176
|
-
});
|
177
|
-
}
|
178
|
-
|
179
|
-
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
180
|
-
// We're doing a query to this to check if the given id is the id of
|
181
|
-
// a user or of a group chat. The form will be different depending
|
182
|
-
// on that.
|
183
|
-
if (utils.getType(threadID) === "Array") {
|
184
|
-
sendContent(form, threadID, false, messageAndOTID, callback);
|
185
|
-
} else {
|
186
|
-
if (utils.getType(isGroup) != "Boolean") {
|
187
|
-
api.getUserInfo(threadID, function (err, res) {
|
188
|
-
if (err) {
|
189
|
-
return callback(err);
|
190
|
-
}
|
191
|
-
sendContent(
|
192
|
-
form,
|
193
|
-
threadID,
|
194
|
-
Object.keys(res).length > 0,
|
195
|
-
messageAndOTID,
|
196
|
-
callback
|
197
|
-
);
|
198
|
-
});
|
199
|
-
} else {
|
200
|
-
sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
201
|
-
}
|
172
|
+
cb();
|
202
173
|
}
|
203
|
-
}
|
204
|
-
|
205
|
-
function handleUrl(msg, form, callback, cb) {
|
206
|
-
if (msg.url) {
|
207
|
-
form["shareable_attachment[share_type]"] = "100";
|
208
|
-
getUrl(msg.url, function (err, params) {
|
209
|
-
if (err) {
|
210
|
-
return callback(err);
|
211
|
-
}
|
212
174
|
|
213
|
-
|
175
|
+
function handleSticker(msg, form, callback, cb) {
|
176
|
+
if (msg.sticker) form["sticker_id"] = msg.sticker;
|
214
177
|
cb();
|
215
|
-
});
|
216
|
-
} else {
|
217
|
-
cb();
|
218
178
|
}
|
219
|
-
}
|
220
|
-
|
221
|
-
function handleLocation(msg, form, callback, cb) {
|
222
|
-
if (msg.location) {
|
223
|
-
if (msg.location.latitude == null || msg.location.longitude == null) {
|
224
|
-
return callback({ error: "location property needs both latitude and longitude" });
|
225
|
-
}
|
226
179
|
|
227
|
-
|
228
|
-
|
229
|
-
|
180
|
+
function handleEmoji(msg, form, callback, cb) {
|
181
|
+
if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
|
182
|
+
if (msg.emoji) {
|
183
|
+
if (msg.emojiSize == null) msg.emojiSize = "medium";
|
184
|
+
if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
|
185
|
+
if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
|
186
|
+
form["body"] = msg.emoji;
|
187
|
+
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
188
|
+
}
|
189
|
+
cb();
|
230
190
|
}
|
231
191
|
|
232
|
-
cb
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
192
|
+
function handleAttachment(msg, form, callback, cb) {
|
193
|
+
if (msg.attachment) {
|
194
|
+
form["image_ids"] = [];
|
195
|
+
form["gif_ids"] = [];
|
196
|
+
form["file_ids"] = [];
|
197
|
+
form["video_ids"] = [];
|
198
|
+
form["audio_ids"] = [];
|
199
|
+
|
200
|
+
if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
|
201
|
+
|
202
|
+
uploadAttachment(msg.attachment, function(err, files) {
|
203
|
+
if (err) return callback(err);
|
204
|
+
files.forEach(function(file) {
|
205
|
+
var key = Object.keys(file);
|
206
|
+
var type = key[0]; // image_id, file_id, etc
|
207
|
+
form["" + type + "s"].push(file[type]); // push the id
|
208
|
+
});
|
209
|
+
cb();
|
210
|
+
});
|
211
|
+
} else cb();
|
238
212
|
}
|
239
|
-
cb();
|
240
|
-
}
|
241
213
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
form["body"] = msg.emoji;
|
261
|
-
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
262
|
-
}
|
263
|
-
cb();
|
264
|
-
}
|
265
|
-
|
266
|
-
function handleAttachment(msg, form, callback, cb) {
|
267
|
-
if (msg.attachment) {
|
268
|
-
form["image_ids"] = [];
|
269
|
-
form["gif_ids"] = [];
|
270
|
-
form["file_ids"] = [];
|
271
|
-
form["video_ids"] = [];
|
272
|
-
form["audio_ids"] = [];
|
273
|
-
|
274
|
-
if (utils.getType(msg.attachment) !== "Array") {
|
275
|
-
msg.attachment = [msg.attachment];
|
276
|
-
}
|
277
|
-
|
278
|
-
uploadAttachment(msg.attachment, function (err, files) {
|
279
|
-
if (err) {
|
280
|
-
return callback(err);
|
214
|
+
function handleMention(msg, form, callback, cb) {
|
215
|
+
if (msg.mentions) {
|
216
|
+
for (let i = 0; i < msg.mentions.length; i++) {
|
217
|
+
const mention = msg.mentions[i];
|
218
|
+
const tag = mention.tag;
|
219
|
+
if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
|
220
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
221
|
+
if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
|
222
|
+
if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
|
223
|
+
|
224
|
+
const id = mention.id || 0;
|
225
|
+
const emptyChar = '\u200E';
|
226
|
+
form["body"] = emptyChar + msg.body;
|
227
|
+
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
228
|
+
form["profile_xmd[" + i + "][length]"] = tag.length;
|
229
|
+
form["profile_xmd[" + i + "][id]"] = id;
|
230
|
+
form["profile_xmd[" + i + "][type]"] = "p";
|
231
|
+
}
|
281
232
|
}
|
282
|
-
|
283
|
-
files.forEach(function (file) {
|
284
|
-
var key = Object.keys(file);
|
285
|
-
var type = key[0]; // image_id, file_id, etc
|
286
|
-
form["" + type + "s"].push(file[type]); // push the id
|
287
|
-
});
|
288
233
|
cb();
|
289
|
-
});
|
290
|
-
} else {
|
291
|
-
cb();
|
292
234
|
}
|
293
|
-
}
|
294
|
-
|
295
|
-
function handleMention(msg, form, callback, cb) {
|
296
|
-
if (msg.mentions) {
|
297
|
-
for (let i = 0; i < msg.mentions.length; i++) {
|
298
|
-
const mention = msg.mentions[i];
|
299
235
|
|
300
|
-
|
301
|
-
|
302
|
-
|
236
|
+
return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
|
237
|
+
typeof isGroup == "undefined" ? isGroup = null : "";
|
238
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
|
239
|
+
if (!replyToMessage && utils.getType(callback) === "String") {
|
240
|
+
replyToMessage = callback;
|
241
|
+
callback = function() {};
|
303
242
|
}
|
304
243
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
);
|
312
|
-
}
|
313
|
-
|
314
|
-
if (mention.id == null) {
|
315
|
-
log.warn("handleMention", "Mention id should be non-null.");
|
316
|
-
}
|
317
|
-
|
318
|
-
const id = mention.id || 0;
|
319
|
-
form["profile_xmd[" + i + "][offset]"] = offset;
|
320
|
-
form["profile_xmd[" + i + "][length]"] = tag.length;
|
321
|
-
form["profile_xmd[" + i + "][id]"] = id;
|
322
|
-
form["profile_xmd[" + i + "][type]"] = "p";
|
323
|
-
}
|
324
|
-
}
|
325
|
-
cb();
|
326
|
-
}
|
327
|
-
|
328
|
-
return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
|
329
|
-
typeof isGroup == "undefined" ? isGroup = null : "";
|
330
|
-
if (
|
331
|
-
!callback &&
|
332
|
-
(utils.getType(threadID) === "Function" ||
|
333
|
-
utils.getType(threadID) === "AsyncFunction")
|
334
|
-
) {
|
335
|
-
return threadID({ error: "Pass a threadID as a second argument." });
|
336
|
-
}
|
337
|
-
if (
|
338
|
-
!replyToMessage &&
|
339
|
-
utils.getType(callback) === "String"
|
340
|
-
) {
|
341
|
-
replyToMessage = callback;
|
342
|
-
callback = function () { };
|
343
|
-
}
|
244
|
+
var resolveFunc = function() {};
|
245
|
+
var rejectFunc = function() {};
|
246
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
247
|
+
resolveFunc = resolve;
|
248
|
+
rejectFunc = reject;
|
249
|
+
});
|
344
250
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
});
|
351
|
-
|
352
|
-
if (!callback) {
|
353
|
-
callback = function (err, friendList) {
|
354
|
-
if (err) {
|
355
|
-
return rejectFunc(err);
|
251
|
+
if (!callback) {
|
252
|
+
callback = function(err, data) {
|
253
|
+
if (err) return rejectFunc(err);
|
254
|
+
resolveFunc(data);
|
255
|
+
};
|
356
256
|
}
|
357
|
-
resolveFunc(friendList);
|
358
|
-
};
|
359
|
-
}
|
360
|
-
|
361
|
-
var msgType = utils.getType(msg);
|
362
|
-
var threadIDType = utils.getType(threadID);
|
363
|
-
var messageIDType = utils.getType(replyToMessage);
|
364
257
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
timestamp: Date.now(),
|
415
|
-
timestamp_absolute: "Today",
|
416
|
-
timestamp_relative: utils.generateTimestampRelative(),
|
417
|
-
timestamp_time_passed: "0",
|
418
|
-
is_unread: false,
|
419
|
-
is_cleared: false,
|
420
|
-
is_forward: false,
|
421
|
-
is_filtered_content: false,
|
422
|
-
is_filtered_content_bh: false,
|
423
|
-
is_filtered_content_account: false,
|
424
|
-
is_filtered_content_quasar: false,
|
425
|
-
is_filtered_content_invalid_app: false,
|
426
|
-
is_spoof_warning: false,
|
427
|
-
source: "source:chat:web",
|
428
|
-
"source_tags[0]": "source:chat",
|
429
|
-
body: msg.body ? msg.body.toString() : "",
|
430
|
-
html_body: false,
|
431
|
-
ui_push_phase: "V3",
|
432
|
-
status: "0",
|
433
|
-
offline_threading_id: messageAndOTID,
|
434
|
-
message_id: messageAndOTID,
|
435
|
-
threading_id: utils.generateThreadingID(ctx.clientID),
|
436
|
-
"ephemeral_ttl_mode:": "0",
|
437
|
-
manual_retry_cnt: "0",
|
438
|
-
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
439
|
-
signatureID: utils.getSignatureID(),
|
440
|
-
replied_to_message_id: replyToMessage
|
441
|
-
};
|
258
|
+
var msgType = utils.getType(msg);
|
259
|
+
var threadIDType = utils.getType(threadID);
|
260
|
+
var messageIDType = utils.getType(replyToMessage);
|
261
|
+
|
262
|
+
if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
|
263
|
+
|
264
|
+
// Changing this to accomodate an array of users
|
265
|
+
if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
|
266
|
+
|
267
|
+
if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
|
268
|
+
|
269
|
+
if (msgType === "String") msg = { body: msg };
|
270
|
+
var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
|
271
|
+
if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
|
272
|
+
|
273
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
274
|
+
|
275
|
+
var form = {
|
276
|
+
client: "mercury",
|
277
|
+
action_type: "ma-type:user-generated-message",
|
278
|
+
author: "fbid:" + ctx.userID,
|
279
|
+
timestamp: Date.now(),
|
280
|
+
timestamp_absolute: "Today",
|
281
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
282
|
+
timestamp_time_passed: "0",
|
283
|
+
is_unread: false,
|
284
|
+
is_cleared: false,
|
285
|
+
is_forward: false,
|
286
|
+
is_filtered_content: false,
|
287
|
+
is_filtered_content_bh: false,
|
288
|
+
is_filtered_content_account: false,
|
289
|
+
is_filtered_content_quasar: false,
|
290
|
+
is_filtered_content_invalid_app: false,
|
291
|
+
is_spoof_warning: false,
|
292
|
+
source: "source:chat:web",
|
293
|
+
"source_tags[0]": "source:chat",
|
294
|
+
body: msg.body ? msg.body.toString() : "",
|
295
|
+
html_body: false,
|
296
|
+
ui_push_phase: "V3",
|
297
|
+
status: "0",
|
298
|
+
offline_threading_id: messageAndOTID,
|
299
|
+
message_id: messageAndOTID,
|
300
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
301
|
+
"ephemeral_ttl_mode:": "0",
|
302
|
+
manual_retry_cnt: "0",
|
303
|
+
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
304
|
+
signatureID: utils.getSignatureID(),
|
305
|
+
replied_to_message_id: replyToMessage
|
306
|
+
};
|
442
307
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
308
|
+
handleLocation(msg, form, callback, () =>
|
309
|
+
handleSticker(msg, form, callback, () =>
|
310
|
+
handleAttachment(msg, form, callback, () =>
|
311
|
+
handleUrl(msg, form, callback, () =>
|
312
|
+
handleEmoji(msg, form, callback, () =>
|
313
|
+
handleMention(msg, form, callback, () =>
|
314
|
+
send(form, threadID, messageAndOTID, callback, isGroup)
|
315
|
+
)
|
316
|
+
)
|
317
|
+
)
|
318
|
+
)
|
451
319
|
)
|
452
|
-
|
453
|
-
)
|
454
|
-
)
|
455
|
-
);
|
320
|
+
);
|
456
321
|
|
457
|
-
|
458
|
-
|
459
|
-
};
|
322
|
+
return returnPromise;
|
323
|
+
};
|
324
|
+
};
|