shadowx-fca 1.2.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/index.js +479 -0
- package/package.json +55 -0
- package/src/OldMessage.js +329 -0
- package/src/Screenshot.js +83 -0
- package/src/addExternalModule.js +25 -0
- package/src/addUserToGroup.js +115 -0
- package/src/changeAdminStatus.js +103 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/changeAvatar.js +136 -0
- package/src/changeAvatarV2.js +86 -0
- package/src/changeAvt.js +85 -0
- package/src/changeBio.js +76 -0
- package/src/changeBlockedStatus.js +49 -0
- package/src/changeBlockedStatusMqtt.js +80 -0
- package/src/changeCover.js +72 -0
- package/src/changeGroupImage.js +135 -0
- package/src/changeName.js +79 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +65 -0
- package/src/changeThreadEmoji.js +55 -0
- package/src/changeUsername.js +59 -0
- package/src/createCommentPost.js +230 -0
- package/src/createNewGroup.js +88 -0
- package/src/createPoll.js +71 -0
- package/src/createPost.js +276 -0
- package/src/data/cache/system/data.json +4 -0
- package/src/data/cache/system/datahandle.js +21 -0
- package/src/data/getThreadInfo.json +1 -0
- package/src/deleteMessage.js +56 -0
- package/src/deleteThread.js +56 -0
- package/src/editMessage.js +68 -0
- package/src/editMessageOld.js +67 -0
- package/src/follow.js +74 -0
- package/src/forwardAttachment.js +60 -0
- package/src/friendList.js +103 -0
- package/src/getAccess.js +112 -0
- package/src/getAvatarUser.js +78 -0
- package/src/getBotInitialData.js +42 -0
- package/src/getCtx.js +5 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/getFriendsList.js +83 -0
- package/src/getMessage.js +847 -0
- package/src/getOptions.js +5 -0
- package/src/getRegion.js +7 -0
- package/src/getThreadHistory.js +680 -0
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +232 -0
- package/src/getThreadInfoDeprecated.js +56 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getThreadTheme.js +82 -0
- package/src/getUID.js +119 -0
- package/src/getUserID.js +61 -0
- package/src/getUserInfo.js +66 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/httpPostFormData.js +70 -0
- package/src/listenMqtt.js +870 -0
- package/src/listenNotification.js +85 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +47 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +40 -0
- package/src/markAsSeen.js +48 -0
- package/src/metaTheme.js +190 -0
- package/src/muteThread.js +45 -0
- package/src/note.js +228 -0
- package/src/pinMessage.js +59 -0
- package/src/refreshFb_dtsg.js +89 -0
- package/src/removeSuspiciousAccount.js +79 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/reply.js +442 -0
- package/src/resolvePhotoUrl.js +45 -0
- package/src/searchForThread.js +53 -0
- package/src/searchFriends.js +139 -0
- package/src/searchStickers.js +53 -0
- package/src/send.js +46 -0
- package/src/sendComment.js +159 -0
- package/src/sendFriendRequest.js +113 -0
- package/src/sendMessage.js +243 -0
- package/src/sendMessageMqtt.js +322 -0
- package/src/sendTypingIndicator.js +101 -0
- package/src/sendTypingIndicatorV2.js +28 -0
- package/src/setActiveStatus.js +93 -0
- package/src/setMessageReaction.js +122 -0
- package/src/setMessageReactionMqtt.js +62 -0
- package/src/setPostReaction.js +112 -0
- package/src/setProfileGuard.js +44 -0
- package/src/setProfileLock.js +98 -0
- package/src/setStoryReaction.js +134 -0
- package/src/setStorySeen.js +109 -0
- package/src/setThreadTheme.js +103 -0
- package/src/setTitle.js +90 -0
- package/src/shareContact.js +110 -0
- package/src/shareLink.js +59 -0
- package/src/stopListenMqtt.js +23 -0
- package/src/storyManager.js +358 -0
- package/src/suggestFriend.js +133 -0
- package/src/threadColors.js +131 -0
- package/src/unfriend.js +52 -0
- package/src/unsendMessage.js +45 -0
- package/src/uploadAttachment.js +93 -0
- package/utils.js +2867 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var utils = require('../utils.js');
|
|
5
|
+
var log = require('npmlog');
|
|
6
|
+
|
|
7
|
+
module.exports = function (http, api, ctx) {
|
|
8
|
+
function formatData(res) {
|
|
9
|
+
return {
|
|
10
|
+
id: res.node.id,
|
|
11
|
+
image: res.node.image,
|
|
12
|
+
package: res.node.pack != null ? {
|
|
13
|
+
name: res.node.pack.name,
|
|
14
|
+
id: res.node.pack.id
|
|
15
|
+
} : {},
|
|
16
|
+
label: res.node.label
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return function searchStickers(query = '', callback) {
|
|
21
|
+
var cb;
|
|
22
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
23
|
+
cb = function (error, data) {
|
|
24
|
+
data ? resolve(data) : reject(error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (typeof callback == 'function') cb = callback;
|
|
29
|
+
|
|
30
|
+
var form = {
|
|
31
|
+
fb_api_req_friendly_name: 'StickersFlyoutTagSelectorQuery',
|
|
32
|
+
variables: JSON.stringify({
|
|
33
|
+
stickerWidth: 64,
|
|
34
|
+
stickerHeight: 64,
|
|
35
|
+
stickerInterface: 'messages',
|
|
36
|
+
query
|
|
37
|
+
}),
|
|
38
|
+
doc_id: '4642836929159953'
|
|
39
|
+
}
|
|
40
|
+
http
|
|
41
|
+
.post('https://www.facebook.com/api/graphql/', ctx.jar, form)
|
|
42
|
+
.then(utils.parseAndCheckLogin(ctx, http))
|
|
43
|
+
.then(function (res) {
|
|
44
|
+
return cb(null, res.data.sticker_search.sticker_results.edges.map(formatData));
|
|
45
|
+
})
|
|
46
|
+
.catch(function (err) {
|
|
47
|
+
console.error('searchStickers', err);
|
|
48
|
+
return cb(err);
|
|
49
|
+
});
|
|
50
|
+
return returnPromise;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
package/src/send.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return async function send(text, senderID, threadID, mentionID, author, participantInfo, userID, leaverID, callback) {
|
|
8
|
+
var resolveFunc = function () { };
|
|
9
|
+
var rejectFunc = function () { };
|
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = function (err, data) {
|
|
16
|
+
if (err) return rejectFunc(err);
|
|
17
|
+
resolveFunc(data);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let count_req = 0;
|
|
21
|
+
var form = JSON.stringify({
|
|
22
|
+
"app_id": "2220391788200892",
|
|
23
|
+
"payload": JSON.stringify({
|
|
24
|
+
tasks: [{
|
|
25
|
+
label: '359',
|
|
26
|
+
payload: JSON.stringify({
|
|
27
|
+
"contact_id": senderID,
|
|
28
|
+
"sync_group": 1,
|
|
29
|
+
"text": text || "",
|
|
30
|
+
"thread_id": threadID
|
|
31
|
+
}),
|
|
32
|
+
queue_name: 'messenger_contact_sharing',
|
|
33
|
+
task_id: Math.random() * 1001 << 0,
|
|
34
|
+
failure_count: null,
|
|
35
|
+
}],
|
|
36
|
+
epoch_id: utils.generateOfflineThreadingID(),
|
|
37
|
+
version_id: '7214102258676893',
|
|
38
|
+
}),
|
|
39
|
+
"request_id": ++count_req,
|
|
40
|
+
"type": 3
|
|
41
|
+
});
|
|
42
|
+
ctx.mqttClient.publish('/ls_req', form);
|
|
43
|
+
|
|
44
|
+
return returnPromise;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//added by jonell Magallanes hshs
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
var bluebird = require("bluebird");
|
|
6
|
+
|
|
7
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
8
|
+
function getGUID() {
|
|
9
|
+
let _0x161e32 = Date.now(),
|
|
10
|
+
_0x4ec135 = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
11
|
+
/[xy]/g,
|
|
12
|
+
function (_0x32f946) {
|
|
13
|
+
let _0x141041 = Math.floor((_0x161e32 + Math.random() * 16) % 16);
|
|
14
|
+
_0x161e32 = Math.floor(_0x161e32 / 16);
|
|
15
|
+
let _0x31fcdd = (
|
|
16
|
+
_0x32f946 == "x" ? _0x141041 : (_0x141041 & 0x3) | 0x8
|
|
17
|
+
).toString(16);
|
|
18
|
+
return _0x31fcdd;
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
return _0x4ec135;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function uploadAttachment(attachment, callback) {
|
|
25
|
+
var uploads = [];
|
|
26
|
+
|
|
27
|
+
// create an array of promises
|
|
28
|
+
if (!utils.isReadableStream(attachment)) {
|
|
29
|
+
throw {
|
|
30
|
+
error:
|
|
31
|
+
"Attachment should be a readable stream and not " +
|
|
32
|
+
utils.getType(attachment) +
|
|
33
|
+
".",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var form = {
|
|
38
|
+
file: attachment,
|
|
39
|
+
av: api.getCurrentUserID(),
|
|
40
|
+
profile_id: api.getCurrentUserID(),
|
|
41
|
+
source: "19",
|
|
42
|
+
target_id: api.getCurrentUserID(),
|
|
43
|
+
__user: api.getCurrentUserID(),
|
|
44
|
+
__a: "1",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
uploads.push(
|
|
48
|
+
defaultFuncs
|
|
49
|
+
.postFormData(
|
|
50
|
+
"https://www.facebook.com/ajax/ufi/upload",
|
|
51
|
+
ctx.jar,
|
|
52
|
+
form,
|
|
53
|
+
{},
|
|
54
|
+
)
|
|
55
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
56
|
+
.then(function (resData) {
|
|
57
|
+
if (resData.error) {
|
|
58
|
+
throw resData;
|
|
59
|
+
}
|
|
60
|
+
return resData.payload;
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// resolve all promises
|
|
65
|
+
bluebird
|
|
66
|
+
.all(uploads)
|
|
67
|
+
.then(function (resData) {
|
|
68
|
+
callback(null, resData);
|
|
69
|
+
})
|
|
70
|
+
.catch(function (err) {
|
|
71
|
+
log.error("uploadAttachment", err);
|
|
72
|
+
return callback(err);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function sendCommentToFb(postId, text, fileID) {
|
|
77
|
+
const feedback_id = Buffer.from("feedback:" + postId).toString("base64");
|
|
78
|
+
|
|
79
|
+
const ss1 = getGUID();
|
|
80
|
+
const ss2 = getGUID();
|
|
81
|
+
|
|
82
|
+
const form = {
|
|
83
|
+
av: api.getCurrentUserID(),
|
|
84
|
+
fb_api_req_friendly_name: "CometUFICreateCommentMutation",
|
|
85
|
+
fb_api_caller_class: "RelayModern",
|
|
86
|
+
doc_id: "4744517358977326",
|
|
87
|
+
variables: JSON.stringify({
|
|
88
|
+
displayCommentsFeedbackContext: null,
|
|
89
|
+
displayCommentsContextEnableComment: null,
|
|
90
|
+
displayCommentsContextIsAdPreview: null,
|
|
91
|
+
displayCommentsContextIsAggregatedShare: null,
|
|
92
|
+
displayCommentsContextIsStorySet: null,
|
|
93
|
+
feedLocation: "TIMELINE",
|
|
94
|
+
feedbackSource: 0,
|
|
95
|
+
focusCommentID: null,
|
|
96
|
+
includeNestedComments: false,
|
|
97
|
+
input: {
|
|
98
|
+
attachments: fileID ? [{ media: { id: fileID } }] : null,
|
|
99
|
+
feedback_id: feedback_id,
|
|
100
|
+
formatting_style: null,
|
|
101
|
+
message: {
|
|
102
|
+
ranges: [],
|
|
103
|
+
text: text,
|
|
104
|
+
},
|
|
105
|
+
is_tracking_encrypted: true,
|
|
106
|
+
tracking: [],
|
|
107
|
+
feedback_source: "PROFILE",
|
|
108
|
+
idempotence_token: "client:" + ss1,
|
|
109
|
+
session_id: ss2,
|
|
110
|
+
actor_id: api.getCurrentUserID(),
|
|
111
|
+
client_mutation_id: Math.round(Math.random() * 19),
|
|
112
|
+
},
|
|
113
|
+
scale: 3,
|
|
114
|
+
useDefaultActor: false,
|
|
115
|
+
UFI2CommentsProvider_commentsKey: "ProfileCometTimelineRoute",
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const res = JSON.parse(
|
|
120
|
+
await api.httpPost("https://www.facebook.com/api/graphql/", form),
|
|
121
|
+
);
|
|
122
|
+
return res;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return async function sendComment(content, postId, callback) {
|
|
126
|
+
if (typeof content === "object") {
|
|
127
|
+
var text = content.body || "";
|
|
128
|
+
if (content.attachment) {
|
|
129
|
+
if (!utils.isReadableStream(content.attachment)) {
|
|
130
|
+
throw new Error("Attachment must be a ReadableStream");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
uploadAttachment(content.attachment, async function (err, files) {
|
|
134
|
+
if (err) {
|
|
135
|
+
return callback(err);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
await sendCommentToFb(postId, text, files[0].fbid)
|
|
139
|
+
.then((res) => {
|
|
140
|
+
return callback(null, res);
|
|
141
|
+
})
|
|
142
|
+
.catch((err) => {
|
|
143
|
+
return callback(err);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
} else if (typeof content === "string") {
|
|
148
|
+
var text = content;
|
|
149
|
+
await sendCommentToFb(postId, text, null)
|
|
150
|
+
.then((res) => {
|
|
151
|
+
return callback(null, res);
|
|
152
|
+
})
|
|
153
|
+
.catch((_) => {
|
|
154
|
+
return;
|
|
155
|
+
});
|
|
156
|
+
} else throw new Error("Invalid content");
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
// example usage
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ===========================================================
|
|
3
|
+
* 🧑💻 Author: Sheikh Tamim (ST | Sheikh Tamim)
|
|
4
|
+
* 🔰 Owner & Developer
|
|
5
|
+
* 🌐 GitHub: https://github.com/sheikhtamimlover
|
|
6
|
+
* 📸 Instagram: https://instagram.com/sheikh.tamim_lover
|
|
7
|
+
* -----------------------------------------------------------
|
|
8
|
+
* 🕊️ Respect the creator & give proper credits if reused.
|
|
9
|
+
* ===========================================================
|
|
10
|
+
*/
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
var utils = require("../utils");
|
|
14
|
+
var log = require("npmlog");
|
|
15
|
+
|
|
16
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
17
|
+
/** Developed by Sheikh Tamim | GitHub: sheikhtamimlover | Instagram: @sheikh.tamim_lover */
|
|
18
|
+
return function sendFriendRequest(userID, callback) {
|
|
19
|
+
var resolveFunc = function () { };
|
|
20
|
+
var rejectFunc = function () { };
|
|
21
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
22
|
+
resolveFunc = resolve;
|
|
23
|
+
rejectFunc = reject;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (!callback) {
|
|
27
|
+
callback = function (err, data) {
|
|
28
|
+
if (err) return rejectFunc(err);
|
|
29
|
+
resolveFunc(data);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!userID) {
|
|
34
|
+
return callback({ error: "User ID is required" });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var form = {
|
|
38
|
+
av: ctx.userID,
|
|
39
|
+
__aaid: 0,
|
|
40
|
+
__user: ctx.userID,
|
|
41
|
+
__a: 1,
|
|
42
|
+
__req: utils.getSignatureID(),
|
|
43
|
+
__hs: "20353.HYP:comet_pkg.2.1...0",
|
|
44
|
+
dpr: 1,
|
|
45
|
+
__ccg: "EXCELLENT",
|
|
46
|
+
__rev: "1027405870",
|
|
47
|
+
__s: utils.getSignatureID(),
|
|
48
|
+
__hsi: "7552782279085106329",
|
|
49
|
+
__comet_req: 15,
|
|
50
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
51
|
+
jazoest: ctx.ttstamp,
|
|
52
|
+
lsd: ctx.fb_dtsg,
|
|
53
|
+
__spin_r: "1027405870",
|
|
54
|
+
__spin_b: "trunk",
|
|
55
|
+
__spin_t: Date.now(),
|
|
56
|
+
__crn: "comet.fbweb.CometFriendingRoute",
|
|
57
|
+
fb_api_caller_class: "RelayModern",
|
|
58
|
+
fb_api_req_friendly_name: "FriendingCometFriendRequestSendMutation",
|
|
59
|
+
variables: JSON.stringify({
|
|
60
|
+
input: {
|
|
61
|
+
click_correlation_id: Date.now().toString(),
|
|
62
|
+
click_proof_validation_result: '{"validated":true}',
|
|
63
|
+
friend_requestee_ids: [userID.toString()],
|
|
64
|
+
friending_channel: "FRIENDS_HOME_MAIN",
|
|
65
|
+
warn_ack_for_ids: [],
|
|
66
|
+
actor_id: ctx.userID,
|
|
67
|
+
client_mutation_id: Math.floor(Math.random() * 10).toString()
|
|
68
|
+
},
|
|
69
|
+
scale: 1
|
|
70
|
+
}),
|
|
71
|
+
server_timestamps: true,
|
|
72
|
+
doc_id: "24614631718227645"
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
defaultFuncs
|
|
76
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
77
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
78
|
+
.then(function (resData) {
|
|
79
|
+
if (resData.error) {
|
|
80
|
+
throw resData;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (resData.data && resData.data.friend_request_send) {
|
|
84
|
+
var responseData = resData.data.friend_request_send;
|
|
85
|
+
if (responseData.friend_requestees && responseData.friend_requestees.length > 0) {
|
|
86
|
+
var requestee = responseData.friend_requestees[0];
|
|
87
|
+
var result = {
|
|
88
|
+
userID: requestee.id,
|
|
89
|
+
friendshipStatus: requestee.friendship_status,
|
|
90
|
+
success: requestee.friendship_status === "OUTGOING_REQUEST"
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (requestee.profile_action) {
|
|
94
|
+
result.actionTitle = requestee.profile_action.title ? requestee.profile_action.title.text : "";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return callback(null, result);
|
|
98
|
+
} else {
|
|
99
|
+
return callback({ error: "No friend request data received" });
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
return callback({ error: "Invalid response format" });
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
.catch(function (err) {
|
|
106
|
+
log.error("sendFriendRequest", err);
|
|
107
|
+
return callback(err);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return returnPromise;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
/** Developed by Sheikh Tamim | GitHub: sheikhtamimlover | Please give credits if reused. */
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
// @NethWs3Dev
|
|
5
|
+
|
|
6
|
+
const allowedProperties = {
|
|
7
|
+
attachment: true,
|
|
8
|
+
url: true,
|
|
9
|
+
sticker: true,
|
|
10
|
+
emoji: true,
|
|
11
|
+
emojiSize: true,
|
|
12
|
+
body: true,
|
|
13
|
+
mentions: true,
|
|
14
|
+
location: true,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
18
|
+
async function uploadAttachment(attachments) {
|
|
19
|
+
var uploads = [];
|
|
20
|
+
for (var i = 0; i < attachments.length; i++) {
|
|
21
|
+
if (!utils.isReadableStream(attachments[i])) {
|
|
22
|
+
throw new Error("Attachment should be a readable stream and not " + utils.getType(attachments[i]) + ".");
|
|
23
|
+
}
|
|
24
|
+
const oksir = await defaultFuncs.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar,{
|
|
25
|
+
upload_1024: attachments[i],
|
|
26
|
+
voice_clip: "true"
|
|
27
|
+
}, {}).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
28
|
+
if (oksir.error) {
|
|
29
|
+
throw new Error(resData);
|
|
30
|
+
}
|
|
31
|
+
uploads.push(oksir.payload.metadata[0]);
|
|
32
|
+
}
|
|
33
|
+
return uploads;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function getUrl(url) {
|
|
37
|
+
const resData = await defaultFuncs.post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, {
|
|
38
|
+
image_height: 960,
|
|
39
|
+
image_width: 960,
|
|
40
|
+
uri: url
|
|
41
|
+
}).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
42
|
+
if (!resData || resData.error || !resData.payload){
|
|
43
|
+
throw new Error(resData);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
|
|
48
|
+
// There are three cases here:
|
|
49
|
+
// 1. threadID is of type array, where we're starting a new group chat with users
|
|
50
|
+
// specified in the array.
|
|
51
|
+
// 2. User is sending a message to a specific user.
|
|
52
|
+
// 3. No additional form params and the message goes to an existing group chat.
|
|
53
|
+
if (utils.getType(threadID) === "Array") {
|
|
54
|
+
for (var i = 0; i < threadID.length; i++) {
|
|
55
|
+
form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
|
56
|
+
}
|
|
57
|
+
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
|
58
|
+
form["client_thread_id"] = "root:" + messageAndOTID;
|
|
59
|
+
utils.log("sendMessage", "Sending message to multiple users: " + threadID);
|
|
60
|
+
} else {
|
|
61
|
+
const threadIDStr = threadID.toString();
|
|
62
|
+
// Check if it's a DM: doesn't start with numeric group ID pattern or explicitly marked as single user
|
|
63
|
+
const isDM = !threadIDStr.match(/^\d{15,}$/) || isSingleUser === true;
|
|
64
|
+
|
|
65
|
+
// This means that threadID is the id of a user, and the chat
|
|
66
|
+
// is a single person chat
|
|
67
|
+
if (isDM) {
|
|
68
|
+
form["specific_to_list[0]"] = "fbid:" + threadID;
|
|
69
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
|
70
|
+
form["other_user_fbid"] = threadID;
|
|
71
|
+
} else {
|
|
72
|
+
form["thread_fbid"] = threadID;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (ctx.globalOptions.pageID) {
|
|
77
|
+
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
|
78
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
|
79
|
+
form["creator_info[creatorID]"] = ctx.userID;
|
|
80
|
+
form["creator_info[creatorType]"] = "direct_admin";
|
|
81
|
+
form["creator_info[labelType]"] = "sent_message";
|
|
82
|
+
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
|
83
|
+
form["request_user_id"] = ctx.globalOptions.pageID;
|
|
84
|
+
form["creator_info[profileURI]"] =
|
|
85
|
+
"https://www.facebook.com/profile.php?id=" + ctx.userID;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const resData = await defaultFuncs.post("https://www.facebook.com/messaging/send/", ctx.jar, form).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
89
|
+
if (!resData) {
|
|
90
|
+
throw new Error("Send message failed.");
|
|
91
|
+
}
|
|
92
|
+
if (resData.error) {
|
|
93
|
+
if (resData.error === 1545012) {
|
|
94
|
+
utils.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
|
|
95
|
+
throw new Error(`Cannot send message to thread ${threadID}: Bot is not part of this conversation (Error 1545012)`);
|
|
96
|
+
}
|
|
97
|
+
throw new Error(resData);
|
|
98
|
+
}
|
|
99
|
+
const messageInfo = resData.payload.actions.reduce((p, v) => {
|
|
100
|
+
return { threadID: v.thread_fbid, messageID: v.message_id, timestamp: v.timestamp } || p;
|
|
101
|
+
}, null);
|
|
102
|
+
return messageInfo;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return async (msg, threadID, callback, replyToMessage, isSingleUser = null) => {
|
|
106
|
+
// Handle different parameter patterns for backward compatibility
|
|
107
|
+
if (typeof callback === "string" || (callback && typeof callback === "object")) {
|
|
108
|
+
// callback is actually replyToMessage, shift parameters
|
|
109
|
+
isSingleUser = replyToMessage;
|
|
110
|
+
replyToMessage = callback;
|
|
111
|
+
callback = function() {};
|
|
112
|
+
} else if (typeof callback !== "function") {
|
|
113
|
+
callback = function() {};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let msgType = utils.getType(msg);
|
|
117
|
+
let threadIDType = utils.getType(threadID);
|
|
118
|
+
let messageIDType = utils.getType(replyToMessage);
|
|
119
|
+
if (msgType !== "String" && msgType !== "Object") throw new Error("Message should be of type string or object and not " + msgType + ".");
|
|
120
|
+
if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") throw new Error("ThreadID should be of type number, string, or array and not " + threadIDType + ".");
|
|
121
|
+
if (replyToMessage && messageIDType !== 'String' && messageIDType !== 'string') throw new Error("MessageID should be of type string and not " + messageIDType + ".");
|
|
122
|
+
if (msgType === "String") {
|
|
123
|
+
msg = { body: msg };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Auto-detect if this is a DM if not explicitly specified
|
|
127
|
+
if (isSingleUser === null && ctx.threadTypes && ctx.threadTypes[threadID]) {
|
|
128
|
+
isSingleUser = ctx.threadTypes[threadID] === 'dm';
|
|
129
|
+
} else if (isSingleUser === null) {
|
|
130
|
+
// Fallback: check if threadID looks like a user ID (15 digits) vs group ID (longer)
|
|
131
|
+
const threadIDStr = threadID.toString();
|
|
132
|
+
isSingleUser = threadIDStr.length === 15 || !threadIDStr.match(/^\d{16,}$/);
|
|
133
|
+
}
|
|
134
|
+
let disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
|
|
135
|
+
if (disallowedProperties.length > 0) {
|
|
136
|
+
throw new Error("Dissallowed props: `" + disallowedProperties.join(", ") + "`");
|
|
137
|
+
}
|
|
138
|
+
let messageAndOTID = utils.generateOfflineThreadingID();
|
|
139
|
+
let form = {
|
|
140
|
+
client: "mercury",
|
|
141
|
+
action_type: "ma-type:user-generated-message",
|
|
142
|
+
author: "fbid:" + ctx.userID,
|
|
143
|
+
timestamp: Date.now(),
|
|
144
|
+
timestamp_absolute: "Today",
|
|
145
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
|
146
|
+
timestamp_time_passed: "0",
|
|
147
|
+
is_unread: false,
|
|
148
|
+
is_cleared: false,
|
|
149
|
+
is_forward: false,
|
|
150
|
+
is_filtered_content: false,
|
|
151
|
+
is_filtered_content_bh: false,
|
|
152
|
+
is_filtered_content_account: false,
|
|
153
|
+
is_filtered_content_quasar: false,
|
|
154
|
+
is_filtered_content_invalid_app: false,
|
|
155
|
+
is_spoof_warning: false,
|
|
156
|
+
source: "source:chat:web",
|
|
157
|
+
"source_tags[0]": "source:chat",
|
|
158
|
+
...(msg.body && {
|
|
159
|
+
body: msg.body
|
|
160
|
+
}),
|
|
161
|
+
html_body: false,
|
|
162
|
+
ui_push_phase: "V3",
|
|
163
|
+
status: "0",
|
|
164
|
+
offline_threading_id: messageAndOTID,
|
|
165
|
+
message_id: messageAndOTID,
|
|
166
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
|
167
|
+
"ephemeral_ttl_mode:": "0",
|
|
168
|
+
manual_retry_cnt: "0",
|
|
169
|
+
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
|
170
|
+
signatureID: utils.getSignatureID(),
|
|
171
|
+
...(replyToMessage && {
|
|
172
|
+
replied_to_message_id: replyToMessage
|
|
173
|
+
})
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
if (msg.location) {
|
|
177
|
+
if (!msg.location.latitude || !msg.location.longitude) throw new Error("location property needs both latitude and longitude");
|
|
178
|
+
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
|
179
|
+
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
|
180
|
+
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
|
181
|
+
}
|
|
182
|
+
if (msg.sticker) {
|
|
183
|
+
form["sticker_id"] = msg.sticker;
|
|
184
|
+
}
|
|
185
|
+
if (msg.attachment) {
|
|
186
|
+
form.image_ids = [];
|
|
187
|
+
form.gif_ids = [];
|
|
188
|
+
form.file_ids = [];
|
|
189
|
+
form.video_ids = [];
|
|
190
|
+
form.audio_ids = [];
|
|
191
|
+
if (utils.getType(msg.attachment) !== "Array") {
|
|
192
|
+
msg.attachment = [msg.attachment];
|
|
193
|
+
}
|
|
194
|
+
const files = await uploadAttachment(msg.attachment);
|
|
195
|
+
files.forEach(file => {
|
|
196
|
+
const type = Object.keys(file)[0];
|
|
197
|
+
form["" + type + "s"].push(file[type]);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (msg.url) {
|
|
201
|
+
form["shareable_attachment[share_type]"] = "100";
|
|
202
|
+
const params = await getUrl(msg.url);
|
|
203
|
+
form["shareable_attachment[share_params]"] = params;
|
|
204
|
+
}
|
|
205
|
+
if (msg.emoji) {
|
|
206
|
+
if (!msg.emojiSize) {
|
|
207
|
+
msg.emojiSize = "medium";
|
|
208
|
+
}
|
|
209
|
+
if (msg.emojiSize !== "small" && msg.emojiSize !== "medium" && msg.emojiSize !== "large") {
|
|
210
|
+
throw new Error("emojiSize property is invalid");
|
|
211
|
+
}
|
|
212
|
+
if (!form.body) {
|
|
213
|
+
throw new Error("body is not empty");
|
|
214
|
+
}
|
|
215
|
+
form.body = msg.emoji;
|
|
216
|
+
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
|
217
|
+
}
|
|
218
|
+
if (msg.mentions) {
|
|
219
|
+
for (let i = 0; i < msg.mentions.length; i++) {
|
|
220
|
+
const mention = msg.mentions[i];
|
|
221
|
+
const tag = mention.tag;
|
|
222
|
+
if (typeof tag !== "string") {
|
|
223
|
+
throw new Error("Mention tags must be strings.");
|
|
224
|
+
}
|
|
225
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
|
226
|
+
if (offset < 0) utils.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
|
|
227
|
+
if (!mention.id) utils.warn("handleMention", "Mention id should be non-null.");
|
|
228
|
+
const id = mention.id || 0;
|
|
229
|
+
const emptyChar = '\u200E';
|
|
230
|
+
form["body"] = emptyChar + msg.body;
|
|
231
|
+
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
|
232
|
+
form["profile_xmd[" + i + "][length]"] = tag.length;
|
|
233
|
+
form["profile_xmd[" + i + "][id]"] = id;
|
|
234
|
+
form["profile_xmd[" + i + "][type]"] = "p";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const result = await sendContent(form, threadID, isSingleUser, messageAndOTID);
|
|
238
|
+
if (callback && typeof callback === "function") {
|
|
239
|
+
callback(null, result);
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
};
|
|
243
|
+
};
|