@cexy/hoonfca 1.0.0 → 1.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/.travis.yml +6 -0
- package/LICENSE-MIT +21 -0
- package/index.d.ts +620 -0
- package/index.js +745 -433
- package/package.json +45 -6
- package/src/addExternalModule.js +14 -16
- package/src/addUserToGroup.js +45 -30
- package/src/changeAdminStatus.js +39 -42
- package/src/changeApprovalMode.js +79 -0
- package/src/changeArchivedStatus.js +19 -15
- package/src/changeBio.js +18 -16
- package/src/changeBlockedStatus.js +14 -12
- package/src/changeBlockedStatusMqtt.js +38 -17
- package/src/changeGroupImage.js +100 -77
- package/src/changeNickname.js +12 -11
- package/src/changeThreadColor.js +25 -16
- package/src/changeThreadEmoji.js +11 -10
- package/src/createNewGroup.js +21 -14
- package/src/createPoll.js +87 -21
- package/src/deleteMessage.js +18 -17
- package/src/deleteThread.js +18 -17
- package/src/editMessage.js +28 -31
- package/src/forwardAttachment.js +22 -19
- package/src/forwardMessage.js +63 -0
- package/src/getCurrentUserID.js +4 -2
- package/src/getEmojiUrl.js +20 -9
- package/src/getFriendsList.js +21 -18
- package/src/getGroupsList.js +83 -0
- package/src/getMarketplace.js +84 -0
- package/src/getNotifications.js +86 -0
- package/src/getPagesList.js +83 -0
- package/src/getStories.js +88 -0
- package/src/getThreadHistory.js +277 -126
- package/src/getThreadInfo.js +143 -115
- package/src/getThreadList.js +216 -143
- package/src/getThreadPictures.js +26 -32
- package/src/getUserID.js +13 -14
- package/src/getUserInfo.js +107 -68
- package/src/handleFriendRequest.js +16 -15
- package/src/handleMessageRequest.js +15 -15
- package/src/httpGet.js +36 -31
- package/src/httpPost.js +36 -31
- package/src/listenMqtt.js +705 -370
- package/src/logout.js +26 -28
- package/src/markAsDelivered.js +22 -17
- package/src/markAsRead.js +63 -49
- package/src/markAsReadAll.js +17 -13
- package/src/markAsSeen.js +23 -19
- package/src/muteThread.js +17 -14
- package/src/pinMessage.js +23 -22
- package/src/removeUserFromGroup.js +42 -22
- package/src/resolvePhotoUrl.js +15 -17
- package/src/searchForThread.js +18 -20
- package/src/searchUsers.js +89 -0
- package/src/sendComment.js +161 -0
- package/src/sendMessage.js +65 -52
- package/src/sendTypingIndicator.js +173 -48
- package/src/setBio.js +86 -0
- package/src/setMessageReaction.js +76 -16
- package/src/setPostReaction.js +29 -61
- package/src/setTheme.js +313 -0
- package/src/setTitle.js +27 -37
- package/src/shareContact.js +34 -82
- package/src/shareLink.js +56 -99
- package/src/threadColors.js +35 -97
- package/src/unfriend.js +15 -20
- package/src/unsendMessage.js +71 -18
- package/utils.js +1000 -472
- package/README.md +0 -83
- package/replit.nix +0 -3
- package/src/changeAvatar.js +0 -89
- package/src/changeCover.js +0 -92
- package/src/changeName.js +0 -106
- package/src/changeUsername.js +0 -80
- package/src/createCommentPost.js +0 -196
- package/src/createPost.js +0 -285
- package/src/data/getThreadInfo.json +0 -1
- package/src/follow.js +0 -71
- package/src/getAccess.js +0 -130
- package/src/getAvatarUser.js +0 -88
- package/src/getBotInitialData.js +0 -59
- package/src/getCtx.js +0 -5
- package/src/getMessage.js +0 -827
- package/src/getOptions.js +0 -5
- package/src/getRegion.js +0 -7
- package/src/getThreadHistoryDeprecated.js +0 -95
- package/src/getThreadInfoDeprecated.js +0 -77
- package/src/getThreadListDeprecated.js +0 -86
- package/src/httpPostFormData.js +0 -58
- package/src/listenNotification.js +0 -96
- package/src/refreshFb_dtsg.js +0 -75
- package/src/searchStickers.js +0 -59
- package/src/sendMessageMqtt.js +0 -326
- package/src/setMessageReactionMqtt.js +0 -74
- package/src/setProfileGuard.js +0 -66
- package/src/setStoryReaction.js +0 -97
- package/src/stopListenMqtt.js +0 -47
- package/src/uploadAttachment.js +0 -98
package/src/resolvePhotoUrl.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
4
5
|
|
|
5
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
7
|
return function resolvePhotoUrl(photoID, callback) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var resolveFunc = function () {};
|
|
9
|
+
var rejectFunc = function () {};
|
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
10
11
|
resolveFunc = resolve;
|
|
11
12
|
rejectFunc = reject;
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
if (!callback) {
|
|
15
|
-
callback = (err,
|
|
16
|
-
if (err)
|
|
17
|
-
|
|
16
|
+
callback = function (err, friendList) {
|
|
17
|
+
if (err) {
|
|
18
|
+
return rejectFunc(err);
|
|
19
|
+
}
|
|
20
|
+
resolveFunc(friendList);
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -23,22 +26,17 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
23
26
|
photo_id: photoID,
|
|
24
27
|
})
|
|
25
28
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
26
|
-
.then(resData => {
|
|
27
|
-
if (resData
|
|
29
|
+
.then((resData) => {
|
|
30
|
+
if (resData.error) {
|
|
28
31
|
throw resData;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
const photoUrl = resData?.jsmods?.require?.[0]?.[3]?.[0];
|
|
33
|
-
|
|
34
|
-
if (!photoUrl) {
|
|
35
|
-
throw { error: "Could not resolve photo URL. The structure might have changed." };
|
|
36
|
-
}
|
|
34
|
+
var photoUrl = resData.jsmods.require[0][3][0];
|
|
37
35
|
|
|
38
36
|
return callback(null, photoUrl);
|
|
39
37
|
})
|
|
40
|
-
.catch(err => {
|
|
41
|
-
|
|
38
|
+
.catch((err) => {
|
|
39
|
+
log.error("resolvePhotoUrl", err);
|
|
42
40
|
return callback(err);
|
|
43
41
|
});
|
|
44
42
|
|
package/src/searchForThread.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var utils = require("../utils");
|
|
4
4
|
|
|
5
5
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
6
|
return function searchForThread(name, callback) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
var resolveFunc = function () {};
|
|
8
|
+
var rejectFunc = function () {};
|
|
9
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
10
10
|
resolveFunc = resolve;
|
|
11
11
|
rejectFunc = reject;
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
if (!callback) {
|
|
15
|
-
callback = (err,
|
|
16
|
-
if (err)
|
|
17
|
-
|
|
15
|
+
callback = function (err, friendList) {
|
|
16
|
+
if (err) {
|
|
17
|
+
return rejectFunc(err);
|
|
18
|
+
}
|
|
19
|
+
resolveFunc(friendList);
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
var tmpForm = {
|
|
22
24
|
client: "web_messenger",
|
|
23
25
|
query: name,
|
|
24
26
|
offset: 0,
|
|
@@ -33,21 +35,17 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
33
35
|
tmpForm,
|
|
34
36
|
)
|
|
35
37
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
36
|
-
.then(resData
|
|
37
|
-
if (resData
|
|
38
|
+
.then(function (resData) {
|
|
39
|
+
if (resData.error) {
|
|
38
40
|
throw resData;
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!threads || threads.length === 0) {
|
|
43
|
-
return callback({ error: `Could not find thread named: ${name}` });
|
|
42
|
+
if (!resData.payload.mercury_payload.threads) {
|
|
43
|
+
return callback({ error: "Could not find thread `" + name + "`." });
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
utils.error("searchForThread", err);
|
|
50
|
-
return callback(err);
|
|
45
|
+
return callback(
|
|
46
|
+
null,
|
|
47
|
+
resData.payload.mercury_payload.threads.map(utils.formatThread),
|
|
48
|
+
);
|
|
51
49
|
});
|
|
52
50
|
|
|
53
51
|
return returnPromise;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
/**
|
|
8
|
+
* Search for users by name
|
|
9
|
+
* @param {string} query - Search query
|
|
10
|
+
* @param {number} limit - Number of results to return
|
|
11
|
+
* @param {function} callback - Callback function
|
|
12
|
+
*/
|
|
13
|
+
return function searchUsers(query, limit, callback) {
|
|
14
|
+
var resolveFunc = function () {};
|
|
15
|
+
var rejectFunc = function () {};
|
|
16
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
17
|
+
resolveFunc = resolve;
|
|
18
|
+
rejectFunc = reject;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (!callback) {
|
|
22
|
+
if (utils.getType(limit) == "Function") {
|
|
23
|
+
callback = limit;
|
|
24
|
+
limit = 10;
|
|
25
|
+
} else {
|
|
26
|
+
callback = function (err, data) {
|
|
27
|
+
if (err) {
|
|
28
|
+
return rejectFunc(err);
|
|
29
|
+
}
|
|
30
|
+
resolveFunc(data);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (utils.getType(limit) != "Number") {
|
|
36
|
+
limit = 10;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (utils.getType(query) != "String") {
|
|
40
|
+
return callback({ error: "Query must be a string" });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var form = {
|
|
44
|
+
av: ctx.userID,
|
|
45
|
+
fb_api_caller_class: "RelayModern",
|
|
46
|
+
fb_api_req_friendly_name: "SearchTypeaheadQuery",
|
|
47
|
+
doc_id: "24585299697835063",
|
|
48
|
+
variables: JSON.stringify({
|
|
49
|
+
query: query,
|
|
50
|
+
first: limit,
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
defaultFuncs
|
|
55
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
56
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
57
|
+
.then(function (resData) {
|
|
58
|
+
if (resData.errors) {
|
|
59
|
+
throw resData;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var users = [];
|
|
63
|
+
if (
|
|
64
|
+
resData.data &&
|
|
65
|
+
resData.data.users &&
|
|
66
|
+
resData.data.users.edges
|
|
67
|
+
) {
|
|
68
|
+
users = resData.data.users.edges.map(function (edge) {
|
|
69
|
+
return {
|
|
70
|
+
id: edge.node.id,
|
|
71
|
+
name: edge.node.name,
|
|
72
|
+
profileUrl: edge.node.profile_url,
|
|
73
|
+
thumbSrc: edge.node.thumb_src,
|
|
74
|
+
isFriend: edge.node.is_friend,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
log.info("searchUsers", "Found " + users.length + " users");
|
|
80
|
+
return callback(null, users);
|
|
81
|
+
})
|
|
82
|
+
.catch(function (err) {
|
|
83
|
+
log.error("searchUsers", err);
|
|
84
|
+
return callback(err);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return returnPromise;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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
|
+
|
|
61
|
+
// We have to return the data unformatted unless we want to change it
|
|
62
|
+
// back in sendMessage.
|
|
63
|
+
return resData.payload;
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// resolve all promises
|
|
68
|
+
bluebird
|
|
69
|
+
.all(uploads)
|
|
70
|
+
.then(function (resData) {
|
|
71
|
+
callback(null, resData);
|
|
72
|
+
})
|
|
73
|
+
.catch(function (err) {
|
|
74
|
+
log.error("uploadAttachment", err);
|
|
75
|
+
return callback(err);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function sendCommentToFb(postId, text, fileID) {
|
|
80
|
+
const feedback_id = Buffer.from("feedback:" + postId).toString("base64");
|
|
81
|
+
|
|
82
|
+
const ss1 = getGUID();
|
|
83
|
+
const ss2 = getGUID();
|
|
84
|
+
|
|
85
|
+
const form = {
|
|
86
|
+
av: api.getCurrentUserID(),
|
|
87
|
+
fb_api_req_friendly_name: "CometUFICreateCommentMutation",
|
|
88
|
+
fb_api_caller_class: "RelayModern",
|
|
89
|
+
doc_id: "4744517358977326",
|
|
90
|
+
variables: JSON.stringify({
|
|
91
|
+
displayCommentsFeedbackContext: null,
|
|
92
|
+
displayCommentsContextEnableComment: null,
|
|
93
|
+
displayCommentsContextIsAdPreview: null,
|
|
94
|
+
displayCommentsContextIsAggregatedShare: null,
|
|
95
|
+
displayCommentsContextIsStorySet: null,
|
|
96
|
+
feedLocation: "TIMELINE",
|
|
97
|
+
feedbackSource: 0,
|
|
98
|
+
focusCommentID: null,
|
|
99
|
+
includeNestedComments: false,
|
|
100
|
+
input: {
|
|
101
|
+
attachments: fileID ? [{ media: { id: fileID } }] : null,
|
|
102
|
+
feedback_id: feedback_id,
|
|
103
|
+
formatting_style: null,
|
|
104
|
+
message: {
|
|
105
|
+
ranges: [],
|
|
106
|
+
text: text,
|
|
107
|
+
},
|
|
108
|
+
is_tracking_encrypted: true,
|
|
109
|
+
tracking: [],
|
|
110
|
+
feedback_source: "PROFILE",
|
|
111
|
+
idempotence_token: "client:" + ss1,
|
|
112
|
+
session_id: ss2,
|
|
113
|
+
actor_id: api.getCurrentUserID(),
|
|
114
|
+
client_mutation_id: Math.round(Math.random() * 19),
|
|
115
|
+
},
|
|
116
|
+
scale: 3,
|
|
117
|
+
useDefaultActor: false,
|
|
118
|
+
UFI2CommentsProvider_commentsKey: "ProfileCometTimelineRoute",
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const res = JSON.parse(
|
|
123
|
+
await api.httpPost("https://www.facebook.com/api/graphql/", form),
|
|
124
|
+
);
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return async function sendComment(content, postId, callback) {
|
|
129
|
+
if (typeof content === "object") {
|
|
130
|
+
var text = content.body || "";
|
|
131
|
+
if (content.attachment) {
|
|
132
|
+
if (!utils.isReadableStream(content.attachment)) {
|
|
133
|
+
throw new Error("Attachment must be a ReadableStream");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
uploadAttachment(content.attachment, async function (err, files) {
|
|
137
|
+
if (err) {
|
|
138
|
+
return callback(err);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
await sendCommentToFb(postId, text, files[0].fbid)
|
|
142
|
+
.then((res) => {
|
|
143
|
+
return callback(null, res);
|
|
144
|
+
})
|
|
145
|
+
.catch((err) => {
|
|
146
|
+
return callback(err);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
} else if (typeof content === "string") {
|
|
151
|
+
var text = content;
|
|
152
|
+
await sendCommentToFb(postId, text, null)
|
|
153
|
+
.then((res) => {
|
|
154
|
+
return callback(null, res);
|
|
155
|
+
})
|
|
156
|
+
.catch((err) => {
|
|
157
|
+
return callback(err);
|
|
158
|
+
});
|
|
159
|
+
} else throw new Error("Invalid content");
|
|
160
|
+
};
|
|
161
|
+
};
|
package/src/sendMessage.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
1
|
"use strict";
|
|
3
2
|
|
|
4
3
|
var utils = require("../utils");
|
|
5
|
-
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
var bluebird = require("bluebird");
|
|
6
6
|
|
|
7
7
|
var allowedProperties = {
|
|
8
8
|
attachment: true,
|
|
@@ -26,13 +26,13 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
26
26
|
error:
|
|
27
27
|
"Attachment should be a readable stream and not " +
|
|
28
28
|
utils.getType(attachments[i]) +
|
|
29
|
-
"."
|
|
29
|
+
".",
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
var form = {
|
|
34
34
|
upload_1024: attachments[i],
|
|
35
|
-
voice_clip: "true"
|
|
35
|
+
voice_clip: "true",
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
uploads.push(
|
|
@@ -41,7 +41,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
41
41
|
"https://upload.facebook.com/ajax/mercury/upload.php",
|
|
42
42
|
ctx.jar,
|
|
43
43
|
form,
|
|
44
|
-
{}
|
|
44
|
+
{},
|
|
45
45
|
)
|
|
46
46
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
47
47
|
.then(function (resData) {
|
|
@@ -52,17 +52,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
52
52
|
// We have to return the data unformatted unless we want to change it
|
|
53
53
|
// back in sendMessage.
|
|
54
54
|
return resData.payload.metadata[0];
|
|
55
|
-
})
|
|
55
|
+
}),
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// resolve all promises
|
|
60
|
-
|
|
60
|
+
bluebird
|
|
61
|
+
.all(uploads)
|
|
61
62
|
.then(function (resData) {
|
|
62
63
|
callback(null, resData);
|
|
63
64
|
})
|
|
64
65
|
.catch(function (err) {
|
|
65
|
-
|
|
66
|
+
log.error("uploadAttachment", err);
|
|
66
67
|
return callback(err);
|
|
67
68
|
});
|
|
68
69
|
}
|
|
@@ -71,14 +72,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
71
72
|
var form = {
|
|
72
73
|
image_height: 960,
|
|
73
74
|
image_width: 960,
|
|
74
|
-
uri: url
|
|
75
|
+
uri: url,
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
defaultFuncs
|
|
78
79
|
.post(
|
|
79
80
|
"https://www.facebook.com/message_share_attachment/fromURI/",
|
|
80
81
|
ctx.jar,
|
|
81
|
-
form
|
|
82
|
+
form,
|
|
82
83
|
)
|
|
83
84
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
84
85
|
.then(function (resData) {
|
|
@@ -93,7 +94,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
93
94
|
callback(null, resData.payload.share_data.share_params);
|
|
94
95
|
})
|
|
95
96
|
.catch(function (err) {
|
|
96
|
-
|
|
97
|
+
log.error("getUrl", err);
|
|
97
98
|
return callback(err);
|
|
98
99
|
});
|
|
99
100
|
}
|
|
@@ -110,7 +111,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
110
111
|
}
|
|
111
112
|
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
|
112
113
|
form["client_thread_id"] = "root:" + messageAndOTID;
|
|
113
|
-
|
|
114
|
+
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
|
114
115
|
} else {
|
|
115
116
|
// This means that threadID is the id of a user, and the chat
|
|
116
117
|
// is a single person chat
|
|
@@ -145,10 +146,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
145
146
|
|
|
146
147
|
if (resData.error) {
|
|
147
148
|
if (resData.error === 1545012) {
|
|
148
|
-
|
|
149
|
+
log.warn(
|
|
149
150
|
"sendMessage",
|
|
150
151
|
"Got error 1545012. This might mean that you're not part of the conversation " +
|
|
151
|
-
|
|
152
|
+
threadID,
|
|
152
153
|
);
|
|
153
154
|
}
|
|
154
155
|
return callback(resData);
|
|
@@ -159,7 +160,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
159
160
|
{
|
|
160
161
|
threadID: v.thread_fbid,
|
|
161
162
|
messageID: v.message_id,
|
|
162
|
-
timestamp: v.timestamp
|
|
163
|
+
timestamp: v.timestamp,
|
|
163
164
|
} || p
|
|
164
165
|
);
|
|
165
166
|
}, null);
|
|
@@ -167,7 +168,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
167
168
|
return callback(null, messageInfo);
|
|
168
169
|
})
|
|
169
170
|
.catch(function (err) {
|
|
170
|
-
|
|
171
|
+
log.error("sendMessage", err);
|
|
172
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
|
173
|
+
ctx.loggedIn = false;
|
|
174
|
+
}
|
|
171
175
|
return callback(err);
|
|
172
176
|
});
|
|
173
177
|
}
|
|
@@ -180,9 +184,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
180
184
|
sendContent(form, threadID, false, messageAndOTID, callback);
|
|
181
185
|
} else {
|
|
182
186
|
if (utils.getType(isGroup) != "Boolean")
|
|
183
|
-
sendContent(
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
sendContent(
|
|
188
|
+
form,
|
|
189
|
+
threadID,
|
|
190
|
+
threadID.length <= 15,
|
|
191
|
+
messageAndOTID,
|
|
192
|
+
callback,
|
|
193
|
+
);
|
|
194
|
+
else sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
|
186
195
|
}
|
|
187
196
|
}
|
|
188
197
|
|
|
@@ -205,11 +214,15 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
205
214
|
function handleLocation(msg, form, callback, cb) {
|
|
206
215
|
if (msg.location) {
|
|
207
216
|
if (msg.location.latitude == null || msg.location.longitude == null) {
|
|
208
|
-
return callback({
|
|
217
|
+
return callback({
|
|
218
|
+
error: "location property needs both latitude and longitude",
|
|
219
|
+
});
|
|
209
220
|
}
|
|
210
221
|
|
|
211
|
-
form["location_attachment[coordinates][latitude]"] =
|
|
212
|
-
|
|
222
|
+
form["location_attachment[coordinates][latitude]"] =
|
|
223
|
+
msg.location.latitude;
|
|
224
|
+
form["location_attachment[coordinates][longitude]"] =
|
|
225
|
+
msg.location.longitude;
|
|
213
226
|
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
|
214
227
|
}
|
|
215
228
|
|
|
@@ -278,7 +291,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
278
291
|
|
|
279
292
|
function handleMention(msg, form, callback, cb) {
|
|
280
293
|
if (msg.mentions) {
|
|
281
|
-
var bodyText = msg.body ? msg.body.toString() : "";
|
|
282
294
|
for (let i = 0; i < msg.mentions.length; i++) {
|
|
283
295
|
const mention = msg.mentions[i];
|
|
284
296
|
|
|
@@ -287,22 +299,22 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
287
299
|
return callback({ error: "Mention tags must be strings." });
|
|
288
300
|
}
|
|
289
301
|
|
|
290
|
-
const offset =
|
|
302
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
|
291
303
|
|
|
292
304
|
if (offset < 0) {
|
|
293
|
-
|
|
305
|
+
log.warn(
|
|
294
306
|
"handleMention",
|
|
295
|
-
'Mention for "' + tag + '" not found in message string.'
|
|
307
|
+
'Mention for "' + tag + '" not found in message string.',
|
|
296
308
|
);
|
|
297
309
|
}
|
|
298
310
|
|
|
299
311
|
if (mention.id == null) {
|
|
300
|
-
|
|
312
|
+
log.warn("handleMention", "Mention id should be non-null.");
|
|
301
313
|
}
|
|
302
314
|
|
|
303
315
|
const id = mention.id || 0;
|
|
304
|
-
const emptyChar =
|
|
305
|
-
form["body"] = emptyChar +
|
|
316
|
+
const emptyChar = "\u200E";
|
|
317
|
+
form["body"] = emptyChar + msg.body;
|
|
306
318
|
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
|
307
319
|
form["profile_xmd[" + i + "][length]"] = tag.length;
|
|
308
320
|
form["profile_xmd[" + i + "][id]"] = id;
|
|
@@ -312,8 +324,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
312
324
|
cb();
|
|
313
325
|
}
|
|
314
326
|
|
|
315
|
-
return function sendMessage(
|
|
316
|
-
|
|
327
|
+
return function sendMessage(
|
|
328
|
+
msg,
|
|
329
|
+
threadID,
|
|
330
|
+
callback,
|
|
331
|
+
replyToMessage,
|
|
332
|
+
isGroup,
|
|
333
|
+
) {
|
|
334
|
+
typeof isGroup == "undefined" ? (isGroup = null) : "";
|
|
317
335
|
if (
|
|
318
336
|
!callback &&
|
|
319
337
|
(utils.getType(threadID) === "Function" ||
|
|
@@ -321,16 +339,13 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
321
339
|
) {
|
|
322
340
|
return threadID({ error: "Pass a threadID as a second argument." });
|
|
323
341
|
}
|
|
324
|
-
if (
|
|
325
|
-
!replyToMessage &&
|
|
326
|
-
utils.getType(callback) === "String"
|
|
327
|
-
) {
|
|
342
|
+
if (!replyToMessage && utils.getType(callback) === "String") {
|
|
328
343
|
replyToMessage = callback;
|
|
329
344
|
callback = undefined;
|
|
330
345
|
}
|
|
331
346
|
|
|
332
|
-
var resolveFunc = function () {
|
|
333
|
-
var rejectFunc = function () {
|
|
347
|
+
var resolveFunc = function () {};
|
|
348
|
+
var rejectFunc = function () {};
|
|
334
349
|
var returnPromise = new Promise(function (resolve, reject) {
|
|
335
350
|
resolveFunc = resolve;
|
|
336
351
|
rejectFunc = reject;
|
|
@@ -350,7 +365,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
350
365
|
if (msgType !== "String" && msgType !== "Object") {
|
|
351
366
|
return callback({
|
|
352
367
|
error:
|
|
353
|
-
"Message should be of type string or object and not " + msgType + "."
|
|
368
|
+
"Message should be of type string or object and not " + msgType + ".",
|
|
354
369
|
});
|
|
355
370
|
}
|
|
356
371
|
|
|
@@ -364,16 +379,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
364
379
|
error:
|
|
365
380
|
"ThreadID should be of type number, string, or array and not " +
|
|
366
381
|
threadIDType +
|
|
367
|
-
"."
|
|
382
|
+
".",
|
|
368
383
|
});
|
|
369
384
|
}
|
|
370
385
|
|
|
371
|
-
if (replyToMessage && messageIDType !==
|
|
386
|
+
if (replyToMessage && messageIDType !== "String") {
|
|
372
387
|
return callback({
|
|
373
388
|
error:
|
|
374
|
-
"MessageID should be of type string and not " +
|
|
375
|
-
messageIDType +
|
|
376
|
-
"."
|
|
389
|
+
"MessageID should be of type string and not " + threadIDType + ".",
|
|
377
390
|
});
|
|
378
391
|
}
|
|
379
392
|
|
|
@@ -382,11 +395,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
382
395
|
}
|
|
383
396
|
|
|
384
397
|
var disallowedProperties = Object.keys(msg).filter(
|
|
385
|
-
prop => !allowedProperties[prop]
|
|
398
|
+
(prop) => !allowedProperties[prop],
|
|
386
399
|
);
|
|
387
400
|
if (disallowedProperties.length > 0) {
|
|
388
401
|
return callback({
|
|
389
|
-
error: "
|
|
402
|
+
error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`",
|
|
390
403
|
});
|
|
391
404
|
}
|
|
392
405
|
|
|
@@ -422,7 +435,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
422
435
|
manual_retry_cnt: "0",
|
|
423
436
|
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
|
424
437
|
signatureID: utils.getSignatureID(),
|
|
425
|
-
replied_to_message_id: replyToMessage
|
|
438
|
+
replied_to_message_id: replyToMessage,
|
|
426
439
|
};
|
|
427
440
|
|
|
428
441
|
handleLocation(msg, form, callback, () =>
|
|
@@ -431,12 +444,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
431
444
|
handleUrl(msg, form, callback, () =>
|
|
432
445
|
handleEmoji(msg, form, callback, () =>
|
|
433
446
|
handleMention(msg, form, callback, () =>
|
|
434
|
-
send(form, threadID, messageAndOTID, callback, isGroup)
|
|
435
|
-
)
|
|
436
|
-
)
|
|
437
|
-
)
|
|
438
|
-
)
|
|
439
|
-
)
|
|
447
|
+
send(form, threadID, messageAndOTID, callback, isGroup),
|
|
448
|
+
),
|
|
449
|
+
),
|
|
450
|
+
),
|
|
451
|
+
),
|
|
452
|
+
),
|
|
440
453
|
);
|
|
441
454
|
|
|
442
455
|
return returnPromise;
|