fca-riyad 37.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 +325 -0
- package/DOCS.md +2712 -0
- package/README.md +410 -0
- package/func/checkUpdate.js +7 -0
- package/func/logAdapter.js +33 -0
- package/func/logger.js +48 -0
- package/index.d.ts +751 -0
- package/index.js +22 -0
- package/module/config.js +40 -0
- package/module/login.js +133 -0
- package/module/loginHelper.js +1359 -0
- package/module/options.js +44 -0
- package/package.json +95 -0
- package/src/api/action/addExternalModule.js +25 -0
- package/src/api/action/changeAvatar.js +137 -0
- package/src/api/action/changeBio.js +75 -0
- package/src/api/action/enableAutoSaveAppState.js +73 -0
- package/src/api/action/getCurrentUserID.js +7 -0
- package/src/api/action/handleFriendRequest.js +57 -0
- package/src/api/action/logout.js +76 -0
- package/src/api/action/refreshFb_dtsg.js +48 -0
- package/src/api/action/setPostReaction.js +106 -0
- package/src/api/action/unfriend.js +54 -0
- package/src/api/http/httpGet.js +46 -0
- package/src/api/http/httpPost.js +52 -0
- package/src/api/http/postFormData.js +47 -0
- package/src/api/messaging/addUserToGroup.js +68 -0
- package/src/api/messaging/changeAdminStatus.js +126 -0
- package/src/api/messaging/changeArchivedStatus.js +55 -0
- package/src/api/messaging/changeBlockedStatus.js +48 -0
- package/src/api/messaging/changeGroupImage.js +91 -0
- package/src/api/messaging/changeNickname.js +70 -0
- package/src/api/messaging/changeThreadColor.js +79 -0
- package/src/api/messaging/changeThreadEmoji.js +111 -0
- package/src/api/messaging/createNewGroup.js +88 -0
- package/src/api/messaging/createPoll.js +46 -0
- package/src/api/messaging/createThemeAI.js +98 -0
- package/src/api/messaging/deleteMessage.js +136 -0
- package/src/api/messaging/deleteThread.js +56 -0
- package/src/api/messaging/editMessage.js +90 -0
- package/src/api/messaging/forwardAttachment.js +57 -0
- package/src/api/messaging/forwardMessage.js +134 -0
- package/src/api/messaging/getEmojiUrl.js +29 -0
- package/src/api/messaging/getFriendsList.js +82 -0
- package/src/api/messaging/getMessage.js +829 -0
- package/src/api/messaging/getThemePictures.js +62 -0
- package/src/api/messaging/handleMessageRequest.js +65 -0
- package/src/api/messaging/markAsDelivered.js +57 -0
- package/src/api/messaging/markAsRead.js +88 -0
- package/src/api/messaging/markAsReadAll.js +49 -0
- package/src/api/messaging/markAsSeen.js +61 -0
- package/src/api/messaging/muteThread.js +50 -0
- package/src/api/messaging/pinMessage.js +115 -0
- package/src/api/messaging/removeUserFromGroup.js +62 -0
- package/src/api/messaging/resolvePhotoUrl.js +43 -0
- package/src/api/messaging/scheduler.js +264 -0
- package/src/api/messaging/searchForThread.js +53 -0
- package/src/api/messaging/sendBroadcast.js +93 -0
- package/src/api/messaging/sendMessage.js +269 -0
- package/src/api/messaging/sendTypingIndicator.js +74 -0
- package/src/api/messaging/sessionGuard.js +130 -0
- package/src/api/messaging/setMessageReaction.js +95 -0
- package/src/api/messaging/setTitle.js +124 -0
- package/src/api/messaging/shareContact.js +49 -0
- package/src/api/messaging/threadColors.js +128 -0
- package/src/api/messaging/unsendMessage.js +81 -0
- package/src/api/messaging/uploadAttachment.js +492 -0
- package/src/api/socket/OldMessage.js +186 -0
- package/src/api/socket/core/connectMqtt.js +269 -0
- package/src/api/socket/core/emitAuth.js +103 -0
- package/src/api/socket/core/getSeqID.js +321 -0
- package/src/api/socket/core/getTaskResponseData.js +25 -0
- package/src/api/socket/core/parseDelta.js +387 -0
- package/src/api/socket/detail/buildStream.js +215 -0
- package/src/api/socket/detail/constants.js +28 -0
- package/src/api/socket/e2ee/crypto.js +173 -0
- package/src/api/socket/e2ee/e2ee/crypto.js +173 -0
- package/src/api/socket/e2ee/e2ee/index.js +421 -0
- package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/e2ee/e2ee/proto/proto-writer.ts +76 -0
- package/src/api/socket/e2ee/e2ee/protocol.js +196 -0
- package/src/api/socket/e2ee/e2ee/ratchet.js +219 -0
- package/src/api/socket/e2ee/e2ee/store.js +182 -0
- package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +9162 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/e2ee/e2ee/vendor/proto/proto-writer.ts +76 -0
- package/src/api/socket/e2ee/index.js +437 -0
- package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/e2ee/proto/proto-writer.ts +76 -0
- package/src/api/socket/e2ee/protocol.js +196 -0
- package/src/api/socket/e2ee/ratchet.js +219 -0
- package/src/api/socket/e2ee/store.js +182 -0
- package/src/api/socket/e2ee/vendor/fb-e2ee.cjs +9162 -0
- package/src/api/socket/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/vendor/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/vendor/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/vendor/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/e2ee/vendor/proto/proto-writer.ts +76 -0
- package/src/api/socket/listenE2EE.js +75 -0
- package/src/api/socket/listenMqtt.js +388 -0
- package/src/api/socket/middleware/index.js +216 -0
- package/src/api/socket/sendMessage.js +309 -0
- package/src/api/socket/sendMessageMqtt.js +69 -0
- package/src/api/threads/getThreadHistory.js +664 -0
- package/src/api/threads/getThreadInfo.js +296 -0
- package/src/api/threads/getThreadList.js +293 -0
- package/src/api/threads/getThreadPictures.js +78 -0
- package/src/api/users/getUserID.js +65 -0
- package/src/api/users/getUserInfo.js +402 -0
- package/src/api/users/getUserInfoV2.js +134 -0
- package/src/app/MessengerBot.js +209 -0
- package/src/app/MessengerContext.js +32 -0
- package/src/app/createFcaClient.js +136 -0
- package/src/app/threadInfoRealtimeSync.js +284 -0
- package/src/core/sendReqMqtt.js +96 -0
- package/src/database/helpers.js +53 -0
- package/src/database/models/index.js +88 -0
- package/src/database/models/thread.js +50 -0
- package/src/database/models/user.js +46 -0
- package/src/database/threadData.js +94 -0
- package/src/database/userData.js +98 -0
- package/src/remote/remoteClient.js +123 -0
- package/src/utils/broadcast.js +51 -0
- package/src/utils/client.js +10 -0
- package/src/utils/constants.js +23 -0
- package/src/utils/cookies.js +68 -0
- package/src/utils/format/attachment.js +357 -0
- package/src/utils/format/cookie.js +9 -0
- package/src/utils/format/date.js +50 -0
- package/src/utils/format/decode.js +44 -0
- package/src/utils/format/delta.js +194 -0
- package/src/utils/format/ids.js +64 -0
- package/src/utils/format/index.js +64 -0
- package/src/utils/format/message.js +88 -0
- package/src/utils/format/presence.js +132 -0
- package/src/utils/format/readTyp.js +44 -0
- package/src/utils/format/thread.js +42 -0
- package/src/utils/format/utils.js +141 -0
- package/src/utils/headers.js +115 -0
- package/src/utils/loginParser/autoLogin.js +125 -0
- package/src/utils/loginParser/helpers.js +43 -0
- package/src/utils/loginParser/index.js +10 -0
- package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
- package/src/utils/loginParser/textUtils.js +28 -0
- package/src/utils/nexca-logger.js +144 -0
- package/src/utils/nexca-utils.js +686 -0
- package/src/utils/request/client.js +26 -0
- package/src/utils/request/config.js +23 -0
- package/src/utils/request/defaults.js +46 -0
- package/src/utils/request/helpers.js +46 -0
- package/src/utils/request/index.js +17 -0
- package/src/utils/request/methods.js +163 -0
- package/src/utils/request/proxy.js +21 -0
- package/src/utils/request/retry.js +77 -0
- package/src/utils/request/sanitize.js +49 -0
- package/src/utils/versionCheck.js +47 -0
- package/src/vendor/fca-unofficial/.github/workflows/nodejs.yml +26 -0
- package/src/vendor/fca-unofficial/.github/workflows/npmpublish.yml +30 -0
- package/src/vendor/fca-unofficial/.travis.yml +6 -0
- package/src/vendor/fca-unofficial/DOCS.md +1731 -0
- package/src/vendor/fca-unofficial/LICENSE-MIT +21 -0
- package/src/vendor/fca-unofficial/README.md +225 -0
- package/src/vendor/fca-unofficial/index.js +619 -0
- package/src/vendor/fca-unofficial/package.json +76 -0
- package/src/vendor/fca-unofficial/src/addExternalModule.js +19 -0
- package/src/vendor/fca-unofficial/src/addUserToGroup.js +113 -0
- package/src/vendor/fca-unofficial/src/changeAdminStatus.js +79 -0
- package/src/vendor/fca-unofficial/src/changeArchivedStatus.js +55 -0
- package/src/vendor/fca-unofficial/src/changeBio.js +77 -0
- package/src/vendor/fca-unofficial/src/changeBlockedStatus.js +47 -0
- package/src/vendor/fca-unofficial/src/changeGroupImage.js +129 -0
- package/src/vendor/fca-unofficial/src/changeNickname.js +59 -0
- package/src/vendor/fca-unofficial/src/changeThreadColor.js +71 -0
- package/src/vendor/fca-unofficial/src/changeThreadEmoji.js +55 -0
- package/src/vendor/fca-unofficial/src/createNewGroup.js +86 -0
- package/src/vendor/fca-unofficial/src/createPoll.js +71 -0
- package/src/vendor/fca-unofficial/src/deleteMessage.js +56 -0
- package/src/vendor/fca-unofficial/src/deleteThread.js +56 -0
- package/src/vendor/fca-unofficial/src/forwardAttachment.js +60 -0
- package/src/vendor/fca-unofficial/src/getCurrentUserID.js +7 -0
- package/src/vendor/fca-unofficial/src/getEmojiUrl.js +29 -0
- package/src/vendor/fca-unofficial/src/getFriendsList.js +84 -0
- package/src/vendor/fca-unofficial/src/getThreadHistory.js +645 -0
- package/src/vendor/fca-unofficial/src/getThreadHistoryDeprecated.js +93 -0
- package/src/vendor/fca-unofficial/src/getThreadInfo.js +201 -0
- package/src/vendor/fca-unofficial/src/getThreadInfoDeprecated.js +80 -0
- package/src/vendor/fca-unofficial/src/getThreadList.js +238 -0
- package/src/vendor/fca-unofficial/src/getThreadListDeprecated.js +75 -0
- package/src/vendor/fca-unofficial/src/getThreadPictures.js +79 -0
- package/src/vendor/fca-unofficial/src/getUserID.js +66 -0
- package/src/vendor/fca-unofficial/src/getUserInfo.js +72 -0
- package/src/vendor/fca-unofficial/src/handleFriendRequest.js +61 -0
- package/src/vendor/fca-unofficial/src/handleMessageRequest.js +65 -0
- package/src/vendor/fca-unofficial/src/httpGet.js +52 -0
- package/src/vendor/fca-unofficial/src/httpPost.js +52 -0
- package/src/vendor/fca-unofficial/src/listenMqtt.js +788 -0
- package/src/vendor/fca-unofficial/src/logout.js +75 -0
- package/src/vendor/fca-unofficial/src/markAsDelivered.js +58 -0
- package/src/vendor/fca-unofficial/src/markAsRead.js +80 -0
- package/src/vendor/fca-unofficial/src/markAsReadAll.js +50 -0
- package/src/vendor/fca-unofficial/src/markAsSeen.js +59 -0
- package/src/vendor/fca-unofficial/src/muteThread.js +52 -0
- package/src/vendor/fca-unofficial/src/removeUserFromGroup.js +79 -0
- package/src/vendor/fca-unofficial/src/resolvePhotoUrl.js +45 -0
- package/src/vendor/fca-unofficial/src/searchForThread.js +53 -0
- package/src/vendor/fca-unofficial/src/sendMessage.js +459 -0
- package/src/vendor/fca-unofficial/src/sendTypingIndicator.js +103 -0
- package/src/vendor/fca-unofficial/src/setMessageReaction.js +117 -0
- package/src/vendor/fca-unofficial/src/setPostReaction.js +76 -0
- package/src/vendor/fca-unofficial/src/setTitle.js +86 -0
- package/src/vendor/fca-unofficial/src/threadColors.js +57 -0
- package/src/vendor/fca-unofficial/src/unfriend.js +52 -0
- package/src/vendor/fca-unofficial/src/unsendMessage.js +49 -0
- package/src/vendor/fca-unofficial/test/data/shareAttach.js +146 -0
- package/src/vendor/fca-unofficial/test/data/something.mov +0 -0
- package/src/vendor/fca-unofficial/test/data/test.png +0 -0
- package/src/vendor/fca-unofficial/test/data/test.txt +7 -0
- package/src/vendor/fca-unofficial/test/example-config.json +18 -0
- package/src/vendor/fca-unofficial/test/test-page.js +140 -0
- package/src/vendor/fca-unofficial/test/test.js +385 -0
- package/src/vendor/fca-unofficial/utils.js +1358 -0
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
var bluebird = require("bluebird");
|
|
6
|
+
|
|
7
|
+
var allowedProperties = {
|
|
8
|
+
attachment: true,
|
|
9
|
+
url: true,
|
|
10
|
+
sticker: true,
|
|
11
|
+
emoji: true,
|
|
12
|
+
emojiSize: true,
|
|
13
|
+
body: true,
|
|
14
|
+
mentions: true,
|
|
15
|
+
location: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
19
|
+
function uploadAttachment(attachments, callback) {
|
|
20
|
+
var uploads = [];
|
|
21
|
+
|
|
22
|
+
// create an array of promises
|
|
23
|
+
for (var i = 0; i < attachments.length; i++) {
|
|
24
|
+
if (!utils.isReadableStream(attachments[i])) {
|
|
25
|
+
throw {
|
|
26
|
+
error:
|
|
27
|
+
"Attachment should be a readable stream and not " +
|
|
28
|
+
utils.getType(attachments[i]) +
|
|
29
|
+
"."
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var form = {
|
|
34
|
+
upload_1024: attachments[i],
|
|
35
|
+
voice_clip: "true"
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
uploads.push(
|
|
39
|
+
defaultFuncs
|
|
40
|
+
.postFormData(
|
|
41
|
+
"https://upload.facebook.com/ajax/mercury/upload.php",
|
|
42
|
+
ctx.jar,
|
|
43
|
+
form,
|
|
44
|
+
{}
|
|
45
|
+
)
|
|
46
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
47
|
+
.then(function (resData) {
|
|
48
|
+
if (resData.error) {
|
|
49
|
+
throw resData;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// We have to return the data unformatted unless we want to change it
|
|
53
|
+
// back in sendMessage.
|
|
54
|
+
return resData.payload.metadata[0];
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// resolve all promises
|
|
60
|
+
bluebird
|
|
61
|
+
.all(uploads)
|
|
62
|
+
.then(function (resData) {
|
|
63
|
+
callback(null, resData);
|
|
64
|
+
})
|
|
65
|
+
.catch(function (err) {
|
|
66
|
+
log.error("uploadAttachment", err);
|
|
67
|
+
return callback(err);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getUrl(url, callback) {
|
|
72
|
+
var form = {
|
|
73
|
+
image_height: 960,
|
|
74
|
+
image_width: 960,
|
|
75
|
+
uri: url
|
|
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);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!resData.payload) {
|
|
91
|
+
return callback({ error: "Invalid url" });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
callback(null, resData.payload.share_data.share_params);
|
|
95
|
+
})
|
|
96
|
+
.catch(function (err) {
|
|
97
|
+
log.error("getUrl", err);
|
|
98
|
+
return callback(err);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
|
|
103
|
+
// There are three cases here:
|
|
104
|
+
// 1. threadID is of type array, where we're starting a new group chat with users
|
|
105
|
+
// specified in the array.
|
|
106
|
+
// 2. User is sending a message to a specific user.
|
|
107
|
+
// 3. No additional form params and the message goes to an existing group chat.
|
|
108
|
+
if (utils.getType(threadID) === "Array") {
|
|
109
|
+
for (var i = 0; i < threadID.length; i++) {
|
|
110
|
+
form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
|
111
|
+
}
|
|
112
|
+
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
|
113
|
+
form["client_thread_id"] = "root:" + messageAndOTID;
|
|
114
|
+
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
|
115
|
+
} else {
|
|
116
|
+
// This means that threadID is the id of a user, and the chat
|
|
117
|
+
// is a single person chat
|
|
118
|
+
if (isSingleUser) {
|
|
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;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
defaultFuncs
|
|
140
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
|
141
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
142
|
+
.then(function (resData) {
|
|
143
|
+
if (!resData) {
|
|
144
|
+
return callback({ error: "Send message failed." });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (resData.error) {
|
|
148
|
+
if (resData.error === 1545012) {
|
|
149
|
+
log.warn(
|
|
150
|
+
"sendMessage",
|
|
151
|
+
"Got error 1545012. This might mean that you're not part of the conversation " +
|
|
152
|
+
threadID
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return callback(resData);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var messageInfo = resData.payload.actions.reduce(function (p, v) {
|
|
159
|
+
return (
|
|
160
|
+
{
|
|
161
|
+
threadID: v.thread_fbid,
|
|
162
|
+
messageID: v.message_id,
|
|
163
|
+
timestamp: v.timestamp
|
|
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;
|
|
174
|
+
}
|
|
175
|
+
return callback(err);
|
|
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
|
+
}
|
|
202
|
+
}
|
|
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
|
+
|
|
213
|
+
form["shareable_attachment[share_params]"] = params;
|
|
214
|
+
cb();
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
cb();
|
|
218
|
+
}
|
|
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
|
+
|
|
227
|
+
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
|
228
|
+
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
|
229
|
+
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
cb();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function handleSticker(msg, form, callback, cb) {
|
|
236
|
+
if (msg.sticker) {
|
|
237
|
+
form["sticker_id"] = msg.sticker;
|
|
238
|
+
}
|
|
239
|
+
cb();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function handleEmoji(msg, form, callback, cb) {
|
|
243
|
+
if (msg.emojiSize != null && msg.emoji == null) {
|
|
244
|
+
return callback({ error: "emoji property is empty" });
|
|
245
|
+
}
|
|
246
|
+
if (msg.emoji) {
|
|
247
|
+
if (msg.emojiSize == null) {
|
|
248
|
+
msg.emojiSize = "medium";
|
|
249
|
+
}
|
|
250
|
+
if (
|
|
251
|
+
msg.emojiSize != "small" &&
|
|
252
|
+
msg.emojiSize != "medium" &&
|
|
253
|
+
msg.emojiSize != "large"
|
|
254
|
+
) {
|
|
255
|
+
return callback({ error: "emojiSize property is invalid" });
|
|
256
|
+
}
|
|
257
|
+
if (form["body"] != null && form["body"] != "") {
|
|
258
|
+
return callback({ error: "body is not empty" });
|
|
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);
|
|
281
|
+
}
|
|
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
|
+
cb();
|
|
289
|
+
});
|
|
290
|
+
} else {
|
|
291
|
+
cb();
|
|
292
|
+
}
|
|
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
|
+
|
|
300
|
+
const tag = mention.tag;
|
|
301
|
+
if (typeof tag !== "string") {
|
|
302
|
+
return callback({ error: "Mention tags must be strings." });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
|
306
|
+
|
|
307
|
+
if (offset < 0) {
|
|
308
|
+
log.warn(
|
|
309
|
+
"handleMention",
|
|
310
|
+
'Mention for "' + tag + '" not found in message string.'
|
|
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
|
+
}
|
|
344
|
+
|
|
345
|
+
var resolveFunc = function(){};
|
|
346
|
+
var rejectFunc = function(){};
|
|
347
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
348
|
+
resolveFunc = resolve;
|
|
349
|
+
rejectFunc = reject;
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
if (!callback) {
|
|
353
|
+
callback = function (err, friendList) {
|
|
354
|
+
if (err) {
|
|
355
|
+
return rejectFunc(err);
|
|
356
|
+
}
|
|
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
|
+
|
|
365
|
+
if (msgType !== "String" && msgType !== "Object") {
|
|
366
|
+
return callback({
|
|
367
|
+
error:
|
|
368
|
+
"Message should be of type string or object and not " + msgType + "."
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Changing this to accomodate an array of users
|
|
373
|
+
if (
|
|
374
|
+
threadIDType !== "Array" &&
|
|
375
|
+
threadIDType !== "Number" &&
|
|
376
|
+
threadIDType !== "String"
|
|
377
|
+
) {
|
|
378
|
+
return callback({
|
|
379
|
+
error:
|
|
380
|
+
"ThreadID should be of type number, string, or array and not " +
|
|
381
|
+
threadIDType +
|
|
382
|
+
"."
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (replyToMessage && messageIDType !== 'String') {
|
|
387
|
+
return callback({
|
|
388
|
+
error:
|
|
389
|
+
"MessageID should be of type string and not " +
|
|
390
|
+
threadIDType +
|
|
391
|
+
"."
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (msgType === "String") {
|
|
396
|
+
msg = { body: msg };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
var disallowedProperties = Object.keys(msg).filter(
|
|
400
|
+
prop => !allowedProperties[prop]
|
|
401
|
+
);
|
|
402
|
+
if (disallowedProperties.length > 0) {
|
|
403
|
+
return callback({
|
|
404
|
+
error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`"
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
|
409
|
+
|
|
410
|
+
var form = {
|
|
411
|
+
client: "mercury",
|
|
412
|
+
action_type: "ma-type:user-generated-message",
|
|
413
|
+
author: "fbid:" + ctx.userID,
|
|
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
|
+
};
|
|
442
|
+
|
|
443
|
+
handleLocation(msg, form, callback, () =>
|
|
444
|
+
handleSticker(msg, form, callback, () =>
|
|
445
|
+
handleAttachment(msg, form, callback, () =>
|
|
446
|
+
handleUrl(msg, form, callback, () =>
|
|
447
|
+
handleEmoji(msg, form, callback, () =>
|
|
448
|
+
handleMention(msg, form, callback, () =>
|
|
449
|
+
send(form, threadID, messageAndOTID, callback, isGroup)
|
|
450
|
+
)
|
|
451
|
+
)
|
|
452
|
+
)
|
|
453
|
+
)
|
|
454
|
+
)
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
return returnPromise;
|
|
458
|
+
};
|
|
459
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
function makeTypingIndicator(typ, threadID, callback, isGroup) {
|
|
8
|
+
var form = {
|
|
9
|
+
typ: +typ,
|
|
10
|
+
to: "",
|
|
11
|
+
source: "mercury-chat",
|
|
12
|
+
thread: threadID
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Check if thread is a single person chat or a group chat
|
|
16
|
+
// More info on this is in api.sendMessage
|
|
17
|
+
if (utils.getType(isGroup) == "Boolean") {
|
|
18
|
+
if (!isGroup) {
|
|
19
|
+
form.to = threadID;
|
|
20
|
+
}
|
|
21
|
+
defaultFuncs
|
|
22
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
|
23
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
24
|
+
.then(function (resData) {
|
|
25
|
+
if (resData.error) {
|
|
26
|
+
throw resData;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return callback();
|
|
30
|
+
})
|
|
31
|
+
.catch(function (err) {
|
|
32
|
+
log.error("sendTypingIndicator", err);
|
|
33
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in") {
|
|
34
|
+
ctx.loggedIn = false;
|
|
35
|
+
}
|
|
36
|
+
return callback(err);
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
api.getUserInfo(threadID, function (err, res) {
|
|
40
|
+
if (err) {
|
|
41
|
+
return callback(err);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// If id is single person chat
|
|
45
|
+
if (Object.keys(res).length > 0) {
|
|
46
|
+
form.to = threadID;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
defaultFuncs
|
|
50
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
|
51
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
52
|
+
.then(function (resData) {
|
|
53
|
+
if (resData.error) {
|
|
54
|
+
throw resData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return callback();
|
|
58
|
+
})
|
|
59
|
+
.catch(function (err) {
|
|
60
|
+
log.error("sendTypingIndicator", err);
|
|
61
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
|
62
|
+
ctx.loggedIn = false;
|
|
63
|
+
}
|
|
64
|
+
return callback(err);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return function sendTypingIndicator(threadID, callback, isGroup) {
|
|
71
|
+
if (
|
|
72
|
+
utils.getType(callback) !== "Function" &&
|
|
73
|
+
utils.getType(callback) !== "AsyncFunction"
|
|
74
|
+
) {
|
|
75
|
+
if (callback) {
|
|
76
|
+
log.warn(
|
|
77
|
+
"sendTypingIndicator",
|
|
78
|
+
"callback is not a function - ignoring."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
callback = () => { };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
makeTypingIndicator(true, threadID, callback, isGroup);
|
|
85
|
+
|
|
86
|
+
return function end(cb) {
|
|
87
|
+
if (
|
|
88
|
+
utils.getType(cb) !== "Function" &&
|
|
89
|
+
utils.getType(cb) !== "AsyncFunction"
|
|
90
|
+
) {
|
|
91
|
+
if (cb) {
|
|
92
|
+
log.warn(
|
|
93
|
+
"sendTypingIndicator",
|
|
94
|
+
"callback is not a function - ignoring."
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
cb = () => { };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
makeTypingIndicator(false, threadID, cb, isGroup);
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
7
|
+
return function setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
|
|
8
|
+
var resolveFunc = function(){};
|
|
9
|
+
var rejectFunc = function(){};
|
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!callback) {
|
|
16
|
+
callback = function (err, friendList) {
|
|
17
|
+
if (err) {
|
|
18
|
+
return rejectFunc(err);
|
|
19
|
+
}
|
|
20
|
+
resolveFunc(friendList);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
switch (reaction) {
|
|
25
|
+
case "\uD83D\uDE0D": //:heart_eyes:
|
|
26
|
+
case "\uD83D\uDE06": //:laughing:
|
|
27
|
+
case "\uD83D\uDE2E": //:open_mouth:
|
|
28
|
+
case "\uD83D\uDE22": //:cry:
|
|
29
|
+
case "\uD83D\uDE20": //:angry:
|
|
30
|
+
case "\uD83D\uDC4D": //:thumbsup:
|
|
31
|
+
case "\uD83D\uDC4E": //:thumbsdown:
|
|
32
|
+
case "\u2764": //:heart:
|
|
33
|
+
case "\uD83D\uDC97": //:glowingheart:
|
|
34
|
+
case "":
|
|
35
|
+
//valid
|
|
36
|
+
break;
|
|
37
|
+
case ":heart_eyes:":
|
|
38
|
+
case ":love:":
|
|
39
|
+
reaction = "\uD83D\uDE0D";
|
|
40
|
+
break;
|
|
41
|
+
case ":laughing:":
|
|
42
|
+
case ":haha:":
|
|
43
|
+
reaction = "\uD83D\uDE06";
|
|
44
|
+
break;
|
|
45
|
+
case ":open_mouth:":
|
|
46
|
+
case ":wow:":
|
|
47
|
+
reaction = "\uD83D\uDE2E";
|
|
48
|
+
break;
|
|
49
|
+
case ":cry:":
|
|
50
|
+
case ":sad:":
|
|
51
|
+
reaction = "\uD83D\uDE22";
|
|
52
|
+
break;
|
|
53
|
+
case ":angry:":
|
|
54
|
+
reaction = "\uD83D\uDE20";
|
|
55
|
+
break;
|
|
56
|
+
case ":thumbsup:":
|
|
57
|
+
case ":like:":
|
|
58
|
+
reaction = "\uD83D\uDC4D";
|
|
59
|
+
break;
|
|
60
|
+
case ":thumbsdown:":
|
|
61
|
+
case ":dislike:":
|
|
62
|
+
reaction = "\uD83D\uDC4E";
|
|
63
|
+
break;
|
|
64
|
+
case ":heart:":
|
|
65
|
+
reaction = "\u2764";
|
|
66
|
+
break;
|
|
67
|
+
case ":glowingheart:":
|
|
68
|
+
reaction = "\uD83D\uDC97";
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
if (forceCustomReaction) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
return callback({ error: "Reaction is not a valid emoji." });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var variables = {
|
|
78
|
+
data: {
|
|
79
|
+
client_mutation_id: ctx.clientMutationId++,
|
|
80
|
+
actor_id: ctx.userID,
|
|
81
|
+
action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
|
|
82
|
+
message_id: messageID,
|
|
83
|
+
reaction: reaction
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
var qs = {
|
|
88
|
+
doc_id: "1491398900900362",
|
|
89
|
+
variables: JSON.stringify(variables),
|
|
90
|
+
dpr: 1
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
defaultFuncs
|
|
94
|
+
.postFormData(
|
|
95
|
+
"https://www.facebook.com/webgraphql/mutation/",
|
|
96
|
+
ctx.jar,
|
|
97
|
+
{},
|
|
98
|
+
qs
|
|
99
|
+
)
|
|
100
|
+
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
|
101
|
+
.then(function(resData) {
|
|
102
|
+
if (!resData) {
|
|
103
|
+
throw { error: "setReaction returned empty object." };
|
|
104
|
+
}
|
|
105
|
+
if (resData.error) {
|
|
106
|
+
throw resData;
|
|
107
|
+
}
|
|
108
|
+
callback(null);
|
|
109
|
+
})
|
|
110
|
+
.catch(function(err) {
|
|
111
|
+
log.error("setReaction", err);
|
|
112
|
+
return callback(err);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return returnPromise;
|
|
116
|
+
};
|
|
117
|
+
};
|