rapido-fca 0.0.1 → 0.0.2
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/index.js +415 -419
- package/package.json +1 -1
- package/readme.md +39 -237
- package/src/addExternalModule.js +23 -19
- package/src/addUserToGroup.js +97 -99
- package/src/changeAdminStatus.js +62 -86
- package/src/changeArchivedStatus.js +49 -49
- package/src/changeAvatar.js +108 -118
- package/src/changeBio.js +64 -63
- package/src/changeBlockedStatus.js +38 -40
- package/src/changeGroupImage.js +126 -129
- package/src/changeNickname.js +49 -49
- package/src/changeThreadColor.js +53 -53
- package/src/changeThreadEmoji.js +45 -45
- package/src/createNewGroup.js +72 -74
- package/src/createPoll.js +59 -59
- package/src/deleteMessage.js +50 -50
- package/src/deleteThread.js +50 -50
- package/src/editMessage.js +49 -51
- package/src/forwardAttachment.js +54 -54
- package/src/getCurrentUserID.js +3 -3
- package/src/getEmojiUrl.js +17 -17
- package/src/getFriendsList.js +67 -67
- package/src/getMessage.js +767 -806
- package/src/getThreadHistory.js +642 -656
- package/src/getThreadInfo.js +1 -1
- package/src/getThreadList.js +227 -199
- package/src/getThreadPictures.js +71 -51
- package/src/getUserID.js +58 -53
- package/src/getUserInfo.js +60 -52
- package/src/handleFriendRequest.js +65 -41
- package/src/handleMessageRequest.js +60 -42
- package/src/httpGet.js +57 -49
- package/src/httpPost.js +57 -48
- package/src/httpPostFormData.js +63 -0
- package/src/listenMqtt.js +895 -827
- package/src/logout.js +61 -61
- package/src/markAsDelivered.js +53 -42
- package/src/markAsRead.js +69 -59
- package/src/markAsReadAll.js +42 -32
- package/src/markAsSeen.js +54 -43
- package/src/muteThread.js +47 -40
- package/src/refreshFb_dtsg.js +69 -77
- package/src/removeUserFromGroup.js +67 -67
- package/src/resolvePhotoUrl.js +34 -34
- package/src/searchForThread.js +43 -43
- package/src/sendMessage.js +228 -80
- package/src/sendTypingIndicator.js +88 -86
- package/src/setMessageReaction.js +109 -110
- package/src/setPostReaction.js +87 -90
- package/src/setTitle.js +72 -76
- package/src/threadColors.js +121 -121
- package/src/unfriend.js +43 -43
- package/src/unsendMessage.js +38 -34
- package/src/uploadAttachment.js +81 -79
- package/utils.js +1401 -2732
- package/src/changeAvatarV2.js +0 -86
- package/src/changeAvt.js +0 -85
- package/src/changeBlockedStatusMqtt.js +0 -80
- package/src/changeCover.js +0 -72
- package/src/changeName.js +0 -79
- package/src/changeUsername.js +0 -59
- package/src/createCommentPost.js +0 -230
- package/src/createPost.js +0 -276
- package/src/editMessageOld.js +0 -67
- package/src/follow.js +0 -74
- package/src/getAccess.js +0 -112
- package/src/getAvatarUser.js +0 -78
- package/src/getRegion.js +0 -7
- package/src/getThreadHistoryDeprecated.js +0 -71
- package/src/getThreadInfoDeprecated.js +0 -56
- package/src/getThreadListDeprecated.js +0 -46
- package/src/getUID.js +0 -119
- package/src/searchStickers.js +0 -53
- package/src/sendMessageMqtt.js +0 -322
- package/src/sendTypingIndicatorV2.js +0 -28
- package/src/setMessageReactionMqtt.js +0 -62
- package/src/setStoryReaction.js +0 -64
- package/src/shareContact.js +0 -110
- package/src/shareLink.js +0 -59
- package/src/stopListenMqtt.js +0 -23
package/src/sendMessage.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var bluebird = require("bluebird");
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
const allowedProperties = {
|
|
8
7
|
attachment: true,
|
|
9
8
|
url: true,
|
|
10
9
|
sticker: true,
|
|
@@ -12,27 +11,65 @@ var allowedProperties = {
|
|
|
12
11
|
emojiSize: true,
|
|
13
12
|
body: true,
|
|
14
13
|
mentions: true,
|
|
15
|
-
location: true
|
|
14
|
+
location: true
|
|
16
15
|
};
|
|
17
16
|
|
|
17
|
+
function removeSpecialChar(inputString) { // remove char banned by facebook
|
|
18
|
+
if (typeof inputString !== "string")
|
|
19
|
+
return inputString;
|
|
20
|
+
// Convert string to Buffer
|
|
21
|
+
const buffer = Buffer.from(inputString, 'utf8');
|
|
22
|
+
|
|
23
|
+
// Filter buffer start with ef b8 8f
|
|
24
|
+
let filteredBuffer = Buffer.alloc(0);
|
|
25
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
26
|
+
if (buffer[i] === 0xEF && buffer[i + 1] === 0xB8 && buffer[i + 2] === 0x8F) {
|
|
27
|
+
i += 2; // Skip 3 bytes of buffer starting with ef b8 8f
|
|
28
|
+
} else {
|
|
29
|
+
filteredBuffer = Buffer.concat([filteredBuffer, buffer.slice(i, i + 1)]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Convert filtered buffer to string
|
|
34
|
+
const convertedString = filteredBuffer.toString('utf8');
|
|
35
|
+
|
|
36
|
+
return convertedString;
|
|
37
|
+
}
|
|
38
|
+
|
|
18
39
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
19
40
|
function uploadAttachment(attachments, callback) {
|
|
20
|
-
|
|
41
|
+
const uploads = [];
|
|
21
42
|
|
|
22
43
|
// create an array of promises
|
|
23
|
-
for (
|
|
24
|
-
if (!utils.isReadableStream(attachments[i]))
|
|
25
|
-
|
|
44
|
+
for (let i = 0; i < attachments.length; i++) {
|
|
45
|
+
if (!utils.isReadableStream(attachments[i])) {
|
|
46
|
+
throw {
|
|
47
|
+
error:
|
|
48
|
+
"Attachment should be a readable stream and not " +
|
|
49
|
+
utils.getType(attachments[i]) +
|
|
50
|
+
"."
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const form = {
|
|
26
55
|
upload_1024: attachments[i],
|
|
27
56
|
voice_clip: "true"
|
|
28
57
|
};
|
|
29
58
|
|
|
30
59
|
uploads.push(
|
|
31
60
|
defaultFuncs
|
|
32
|
-
.postFormData(
|
|
61
|
+
.postFormData(
|
|
62
|
+
"https://upload.facebook.com/ajax/mercury/upload.php",
|
|
63
|
+
ctx.jar,
|
|
64
|
+
form,
|
|
65
|
+
{}
|
|
66
|
+
)
|
|
33
67
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
34
68
|
.then(function (resData) {
|
|
35
|
-
if (resData.error)
|
|
69
|
+
if (resData.error) {
|
|
70
|
+
throw resData;
|
|
71
|
+
}
|
|
72
|
+
|
|
36
73
|
// We have to return the data unformatted unless we want to change it
|
|
37
74
|
// back in sendMessage.
|
|
38
75
|
return resData.payload.metadata[0];
|
|
@@ -41,9 +78,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
41
78
|
}
|
|
42
79
|
|
|
43
80
|
// resolve all promises
|
|
44
|
-
|
|
81
|
+
Promise
|
|
45
82
|
.all(uploads)
|
|
46
|
-
.then(
|
|
83
|
+
.then(function (resData) {
|
|
84
|
+
callback(null, resData);
|
|
85
|
+
})
|
|
47
86
|
.catch(function (err) {
|
|
48
87
|
log.error("uploadAttachment", err);
|
|
49
88
|
return callback(err);
|
|
@@ -51,18 +90,28 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
51
90
|
}
|
|
52
91
|
|
|
53
92
|
function getUrl(url, callback) {
|
|
54
|
-
|
|
93
|
+
const form = {
|
|
55
94
|
image_height: 960,
|
|
56
95
|
image_width: 960,
|
|
57
96
|
uri: url
|
|
58
97
|
};
|
|
59
98
|
|
|
60
99
|
defaultFuncs
|
|
61
|
-
.post(
|
|
100
|
+
.post(
|
|
101
|
+
"https://www.facebook.com/message_share_attachment/fromURI/",
|
|
102
|
+
ctx.jar,
|
|
103
|
+
form
|
|
104
|
+
)
|
|
62
105
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
63
106
|
.then(function (resData) {
|
|
64
|
-
if (resData.error)
|
|
65
|
-
|
|
107
|
+
if (resData.error) {
|
|
108
|
+
return callback(resData);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!resData.payload) {
|
|
112
|
+
return callback({ error: "Invalid url" });
|
|
113
|
+
}
|
|
114
|
+
|
|
66
115
|
callback(null, resData.payload.share_data.share_params);
|
|
67
116
|
})
|
|
68
117
|
.catch(function (err) {
|
|
@@ -78,41 +127,51 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
78
127
|
// 2. User is sending a message to a specific user.
|
|
79
128
|
// 3. No additional form params and the message goes to an existing group chat.
|
|
80
129
|
if (utils.getType(threadID) === "Array") {
|
|
81
|
-
for (
|
|
82
|
-
|
|
130
|
+
for (let i = 0; i < threadID.length; i++) {
|
|
131
|
+
form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
|
132
|
+
}
|
|
133
|
+
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + (ctx.i_userID || ctx.userID);
|
|
83
134
|
form["client_thread_id"] = "root:" + messageAndOTID;
|
|
84
135
|
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
136
|
+
} else {
|
|
87
137
|
// This means that threadID is the id of a user, and the chat
|
|
88
138
|
// is a single person chat
|
|
89
139
|
if (isSingleUser) {
|
|
90
140
|
form["specific_to_list[0]"] = "fbid:" + threadID;
|
|
91
|
-
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
|
141
|
+
form["specific_to_list[1]"] = "fbid:" + (ctx.i_userID || ctx.userID);
|
|
92
142
|
form["other_user_fbid"] = threadID;
|
|
143
|
+
} else {
|
|
144
|
+
form["thread_fbid"] = threadID;
|
|
93
145
|
}
|
|
94
|
-
else form["thread_fbid"] = threadID;
|
|
95
146
|
}
|
|
96
147
|
|
|
97
148
|
if (ctx.globalOptions.pageID) {
|
|
98
149
|
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
|
99
150
|
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
|
100
|
-
form["creator_info[creatorID]"] = ctx.userID;
|
|
151
|
+
form["creator_info[creatorID]"] = ctx.i_userID || ctx.userID;
|
|
101
152
|
form["creator_info[creatorType]"] = "direct_admin";
|
|
102
153
|
form["creator_info[labelType]"] = "sent_message";
|
|
103
154
|
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
|
104
155
|
form["request_user_id"] = ctx.globalOptions.pageID;
|
|
105
|
-
form["creator_info[profileURI]"] =
|
|
156
|
+
form["creator_info[profileURI]"] =
|
|
157
|
+
"https://www.facebook.com/profile.php?id=" + (ctx.i_userID || ctx.userID);
|
|
106
158
|
}
|
|
107
159
|
|
|
108
160
|
defaultFuncs
|
|
109
161
|
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
|
110
162
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
111
163
|
.then(function (resData) {
|
|
112
|
-
if (!resData)
|
|
164
|
+
if (!resData) {
|
|
165
|
+
return callback({ error: "Send message failed." });
|
|
166
|
+
}
|
|
167
|
+
|
|
113
168
|
if (resData.error) {
|
|
114
169
|
if (resData.error === 1545012) {
|
|
115
|
-
log.warn(
|
|
170
|
+
log.warn(
|
|
171
|
+
"sendMessage",
|
|
172
|
+
"Got error 1545012. This might mean that you're not part of the conversation " +
|
|
173
|
+
threadID
|
|
174
|
+
);
|
|
116
175
|
}
|
|
117
176
|
else {
|
|
118
177
|
log.error("sendMessage", resData);
|
|
@@ -120,7 +179,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
120
179
|
return callback(resData);
|
|
121
180
|
}
|
|
122
181
|
|
|
123
|
-
|
|
182
|
+
const messageInfo = resData.payload.actions.reduce(function (p, v) {
|
|
124
183
|
return (
|
|
125
184
|
{
|
|
126
185
|
threadID: v.thread_fbid,
|
|
@@ -134,7 +193,9 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
134
193
|
})
|
|
135
194
|
.catch(function (err) {
|
|
136
195
|
log.error("sendMessage", err);
|
|
137
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
|
196
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
|
197
|
+
ctx.loggedIn = false;
|
|
198
|
+
}
|
|
138
199
|
return callback(err);
|
|
139
200
|
});
|
|
140
201
|
}
|
|
@@ -143,10 +204,15 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
143
204
|
// We're doing a query to this to check if the given id is the id of
|
|
144
205
|
// a user or of a group chat. The form will be different depending
|
|
145
206
|
// on that.
|
|
146
|
-
if (utils.getType(threadID) === "Array")
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
207
|
+
if (utils.getType(threadID) === "Array") {
|
|
208
|
+
sendContent(form, threadID, false, messageAndOTID, callback);
|
|
209
|
+
} else {
|
|
210
|
+
if (utils.getType(isGroup) != "Boolean") {
|
|
211
|
+
// Removed the use of api.getUserInfo() in the old version to reduce account lockout
|
|
212
|
+
sendContent(form, threadID, threadID.toString().length < 16, messageAndOTID, callback);
|
|
213
|
+
} else {
|
|
214
|
+
sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
|
215
|
+
}
|
|
150
216
|
}
|
|
151
217
|
}
|
|
152
218
|
|
|
@@ -154,35 +220,57 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
154
220
|
if (msg.url) {
|
|
155
221
|
form["shareable_attachment[share_type]"] = "100";
|
|
156
222
|
getUrl(msg.url, function (err, params) {
|
|
157
|
-
if (err)
|
|
223
|
+
if (err) {
|
|
224
|
+
return callback(err);
|
|
225
|
+
}
|
|
226
|
+
|
|
158
227
|
form["shareable_attachment[share_params]"] = params;
|
|
159
228
|
cb();
|
|
160
229
|
});
|
|
230
|
+
} else {
|
|
231
|
+
cb();
|
|
161
232
|
}
|
|
162
|
-
else cb();
|
|
163
233
|
}
|
|
164
234
|
|
|
165
235
|
function handleLocation(msg, form, callback, cb) {
|
|
166
236
|
if (msg.location) {
|
|
167
|
-
if (msg.location.latitude == null || msg.location.longitude == null)
|
|
237
|
+
if (msg.location.latitude == null || msg.location.longitude == null) {
|
|
238
|
+
return callback({ error: "location property needs both latitude and longitude" });
|
|
239
|
+
}
|
|
240
|
+
|
|
168
241
|
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
|
169
242
|
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
|
170
243
|
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
|
171
244
|
}
|
|
245
|
+
|
|
172
246
|
cb();
|
|
173
247
|
}
|
|
174
248
|
|
|
175
249
|
function handleSticker(msg, form, callback, cb) {
|
|
176
|
-
if (msg.sticker)
|
|
250
|
+
if (msg.sticker) {
|
|
251
|
+
form["sticker_id"] = msg.sticker;
|
|
252
|
+
}
|
|
177
253
|
cb();
|
|
178
254
|
}
|
|
179
255
|
|
|
180
256
|
function handleEmoji(msg, form, callback, cb) {
|
|
181
|
-
if (msg.emojiSize != null && msg.emoji == null)
|
|
257
|
+
if (msg.emojiSize != null && msg.emoji == null) {
|
|
258
|
+
return callback({ error: "emoji property is empty" });
|
|
259
|
+
}
|
|
182
260
|
if (msg.emoji) {
|
|
183
|
-
if (msg.emojiSize == null)
|
|
184
|
-
|
|
185
|
-
|
|
261
|
+
if (msg.emojiSize == null) {
|
|
262
|
+
msg.emojiSize = "medium";
|
|
263
|
+
}
|
|
264
|
+
if (
|
|
265
|
+
msg.emojiSize != "small" &&
|
|
266
|
+
msg.emojiSize != "medium" &&
|
|
267
|
+
msg.emojiSize != "large"
|
|
268
|
+
) {
|
|
269
|
+
return callback({ error: "emojiSize property is invalid" });
|
|
270
|
+
}
|
|
271
|
+
if (form["body"] != null && form["body"] != "") {
|
|
272
|
+
return callback({ error: "body is not empty" });
|
|
273
|
+
}
|
|
186
274
|
form["body"] = msg.emoji;
|
|
187
275
|
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
|
188
276
|
}
|
|
@@ -197,39 +285,52 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
197
285
|
form["video_ids"] = [];
|
|
198
286
|
form["audio_ids"] = [];
|
|
199
287
|
|
|
200
|
-
if (utils.getType(msg.attachment) !== "Array")
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return cb();
|
|
205
|
-
}
|
|
288
|
+
if (utils.getType(msg.attachment) !== "Array") {
|
|
289
|
+
msg.attachment = [msg.attachment];
|
|
290
|
+
}
|
|
291
|
+
|
|
206
292
|
uploadAttachment(msg.attachment, function (err, files) {
|
|
207
|
-
if (err)
|
|
293
|
+
if (err) {
|
|
294
|
+
return callback(err);
|
|
295
|
+
}
|
|
296
|
+
|
|
208
297
|
files.forEach(function (file) {
|
|
209
|
-
|
|
210
|
-
|
|
298
|
+
const key = Object.keys(file);
|
|
299
|
+
const type = key[0]; // image_id, file_id, etc
|
|
211
300
|
form["" + type + "s"].push(file[type]); // push the id
|
|
212
301
|
});
|
|
213
302
|
cb();
|
|
214
303
|
});
|
|
304
|
+
} else {
|
|
305
|
+
cb();
|
|
215
306
|
}
|
|
216
|
-
else cb();
|
|
217
307
|
}
|
|
218
308
|
|
|
219
309
|
function handleMention(msg, form, callback, cb) {
|
|
220
310
|
if (msg.mentions) {
|
|
221
311
|
for (let i = 0; i < msg.mentions.length; i++) {
|
|
222
312
|
const mention = msg.mentions[i];
|
|
313
|
+
|
|
223
314
|
const tag = mention.tag;
|
|
224
|
-
if (typeof tag !== "string")
|
|
315
|
+
if (typeof tag !== "string") {
|
|
316
|
+
return callback({ error: "Mention tags must be strings." });
|
|
317
|
+
}
|
|
318
|
+
|
|
225
319
|
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
|
226
|
-
|
|
227
|
-
if (
|
|
320
|
+
|
|
321
|
+
if (offset < 0) {
|
|
322
|
+
log.warn(
|
|
323
|
+
"handleMention",
|
|
324
|
+
'Mention for "' + tag + '" not found in message string.'
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (mention.id == null) {
|
|
329
|
+
log.warn("handleMention", "Mention id should be non-null.");
|
|
330
|
+
}
|
|
228
331
|
|
|
229
332
|
const id = mention.id || 0;
|
|
230
|
-
|
|
231
|
-
form["body"] = emptyChar + msg.body;
|
|
232
|
-
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
|
333
|
+
form["profile_xmd[" + i + "][offset]"] = offset;
|
|
233
334
|
form["profile_xmd[" + i + "][length]"] = tag.length;
|
|
234
335
|
form["profile_xmd[" + i + "][id]"] = id;
|
|
235
336
|
form["profile_xmd[" + i + "][type]"] = "p";
|
|
@@ -240,47 +341,94 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
240
341
|
|
|
241
342
|
return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
|
|
242
343
|
typeof isGroup == "undefined" ? isGroup = null : "";
|
|
243
|
-
if (
|
|
244
|
-
|
|
344
|
+
if (
|
|
345
|
+
!callback &&
|
|
346
|
+
(utils.getType(threadID) === "Function" ||
|
|
347
|
+
utils.getType(threadID) === "AsyncFunction")
|
|
348
|
+
) {
|
|
349
|
+
return threadID({ error: "Pass a threadID as a second argument." });
|
|
350
|
+
}
|
|
351
|
+
if (
|
|
352
|
+
!replyToMessage &&
|
|
353
|
+
utils.getType(callback) === "String"
|
|
354
|
+
) {
|
|
245
355
|
replyToMessage = callback;
|
|
246
356
|
callback = function () { };
|
|
247
357
|
}
|
|
248
358
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
359
|
+
let resolveFunc = function () { };
|
|
360
|
+
let rejectFunc = function () { };
|
|
361
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
252
362
|
resolveFunc = resolve;
|
|
253
363
|
rejectFunc = reject;
|
|
254
364
|
});
|
|
255
365
|
|
|
256
366
|
if (!callback) {
|
|
257
|
-
callback = function (err,
|
|
258
|
-
if (err)
|
|
259
|
-
|
|
367
|
+
callback = function (err, friendList) {
|
|
368
|
+
if (err) {
|
|
369
|
+
return rejectFunc(err);
|
|
370
|
+
}
|
|
371
|
+
resolveFunc(friendList);
|
|
260
372
|
};
|
|
261
373
|
}
|
|
262
374
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
375
|
+
const msgType = utils.getType(msg);
|
|
376
|
+
const threadIDType = utils.getType(threadID);
|
|
377
|
+
const messageIDType = utils.getType(replyToMessage);
|
|
266
378
|
|
|
267
|
-
if (msgType !== "String" && msgType !== "Object")
|
|
379
|
+
if (msgType !== "String" && msgType !== "Object") {
|
|
380
|
+
return callback({
|
|
381
|
+
error:
|
|
382
|
+
"Message should be of type string or object and not " + msgType + "."
|
|
383
|
+
});
|
|
384
|
+
}
|
|
268
385
|
|
|
269
386
|
// Changing this to accomodate an array of users
|
|
270
|
-
if (
|
|
387
|
+
if (
|
|
388
|
+
threadIDType !== "Array" &&
|
|
389
|
+
threadIDType !== "Number" &&
|
|
390
|
+
threadIDType !== "String"
|
|
391
|
+
) {
|
|
392
|
+
return callback({
|
|
393
|
+
error:
|
|
394
|
+
"ThreadID should be of type number, string, or array and not " +
|
|
395
|
+
threadIDType +
|
|
396
|
+
"."
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (replyToMessage && messageIDType !== 'String') {
|
|
401
|
+
return callback({
|
|
402
|
+
error:
|
|
403
|
+
"MessageID should be of type string and not " +
|
|
404
|
+
threadIDType +
|
|
405
|
+
"."
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (msgType === "String") {
|
|
410
|
+
msg = { body: msg };
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (utils.getType(msg.body) === "String") {
|
|
414
|
+
msg.body = removeSpecialChar(msg.body);
|
|
415
|
+
}
|
|
271
416
|
|
|
272
|
-
|
|
417
|
+
const disallowedProperties = Object.keys(msg).filter(
|
|
418
|
+
prop => !allowedProperties[prop]
|
|
419
|
+
);
|
|
420
|
+
if (disallowedProperties.length > 0) {
|
|
421
|
+
return callback({
|
|
422
|
+
error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`"
|
|
423
|
+
});
|
|
424
|
+
}
|
|
273
425
|
|
|
274
|
-
|
|
275
|
-
var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
|
|
276
|
-
if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
|
|
426
|
+
const messageAndOTID = utils.generateOfflineThreadingID();
|
|
277
427
|
|
|
278
|
-
|
|
279
|
-
// console.log(messageAndOTID)
|
|
280
|
-
var form = {
|
|
428
|
+
const form = {
|
|
281
429
|
client: "mercury",
|
|
282
430
|
action_type: "ma-type:user-generated-message",
|
|
283
|
-
author: "fbid:" + ctx.userID,
|
|
431
|
+
author: "fbid:" + (ctx.i_userID || ctx.userID),
|
|
284
432
|
timestamp: Date.now(),
|
|
285
433
|
timestamp_absolute: "Today",
|
|
286
434
|
timestamp_relative: utils.generateTimestampRelative(),
|
|
@@ -309,7 +457,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
309
457
|
signatureID: utils.getSignatureID(),
|
|
310
458
|
replied_to_message_id: replyToMessage
|
|
311
459
|
};
|
|
312
|
-
// console.log(form)
|
|
313
460
|
|
|
314
461
|
handleLocation(msg, form, callback, () =>
|
|
315
462
|
handleSticker(msg, form, callback, () =>
|
|
@@ -324,6 +471,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
324
471
|
)
|
|
325
472
|
)
|
|
326
473
|
);
|
|
474
|
+
|
|
327
475
|
return returnPromise;
|
|
328
476
|
};
|
|
329
|
-
};
|
|
477
|
+
};
|