node-ainzfb-new 1.6.1-test → 1.6.32-stable
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +1 -1
- package/package.json +2 -3
- package/src/addExternalModule.js +13 -6
- package/src/addUserToGroup.js +35 -12
- package/src/changeAdminStatus.js +32 -16
- package/src/changeArchivedStatus.js +15 -9
- package/src/changeAvt.js +91 -0
- package/src/changeBio.js +12 -8
- package/src/changeBlockedStatus.js +14 -8
- package/src/changeGroupImage.js +27 -13
- package/src/changeNickname.js +19 -10
- package/src/changeThreadColor.js +15 -10
- package/src/changeThreadEmoji.js +17 -9
- package/src/createNewGroup.js +18 -10
- package/src/createPoll.js +16 -11
- package/src/deleteMessage.js +16 -10
- package/src/deleteThread.js +16 -10
- package/src/forwardAttachment.js +14 -9
- package/src/getCurrentUserID.js +1 -1
- package/src/getEmojiUrl.js +3 -2
- package/src/getFriendsList.js +18 -10
- package/src/getMessage.js +52 -48
- package/src/getThreadHistory.js +156 -59
- package/src/getThreadHistoryDeprecated.js +26 -15
- package/src/getThreadInfoDeprecated.js +25 -13
- package/src/getThreadList.js +112 -53
- package/src/getThreadListDeprecated.js +30 -12
- package/src/getThreadPictures.js +25 -13
- package/src/getUserID.js +8 -7
- package/src/getUserInfo.js +12 -9
- package/src/handleFriendRequest.js +10 -9
- package/src/handleMessageRequest.js +16 -10
- package/src/httpGet.js +18 -13
- package/src/httpPost.js +18 -13
- package/src/httpPostFormData.js +14 -9
- package/src/listenMqtt.js +1218 -571
- package/src/logout.js +18 -13
- package/src/markAsDelivered.js +16 -10
- package/src/markAsRead.js +36 -24
- package/src/markAsReadAll.js +14 -10
- package/src/markAsSeen.js +18 -11
- package/src/muteThread.js +12 -8
- package/src/removeUserFromGroup.js +33 -10
- package/src/resolvePhotoUrl.js +8 -6
- package/src/searchForThread.js +13 -8
- package/src/sendMessage.js +172 -78
- package/src/sendTypingIndicator.js +29 -14
- package/src/setMessageReaction.js +13 -8
- package/src/setPostReaction.js +97 -95
- package/src/setTitle.js +18 -12
- package/src/threadColors.js +17 -17
- package/src/unfriend.js +14 -9
- package/src/unsendMessage.js +7 -7
- package/utils.js +18 -19
package/src/getThreadList.js
CHANGED
@@ -5,11 +5,13 @@ const log = require("npmlog");
|
|
5
5
|
|
6
6
|
function createProfileUrl(url, username, id) {
|
7
7
|
if (url) return url;
|
8
|
-
return
|
8
|
+
return (
|
9
|
+
"https://www.facebook.com/" + (username || utils.formatID(id.toString()))
|
10
|
+
);
|
9
11
|
}
|
10
12
|
|
11
13
|
function formatParticipants(participants) {
|
12
|
-
return participants.edges.map(
|
14
|
+
return participants.edges.map(p => {
|
13
15
|
p = p.node.messaging_actor;
|
14
16
|
switch (p["__typename"]) {
|
15
17
|
case "User":
|
@@ -21,7 +23,7 @@ function formatParticipants(participants) {
|
|
21
23
|
gender: p.gender,
|
22
24
|
url: p.url, // how about making it profileURL
|
23
25
|
profilePicture: p.big_image_src.uri,
|
24
|
-
username:
|
26
|
+
username: p.username || null,
|
25
27
|
// TODO: maybe better names for these?
|
26
28
|
isViewerFriend: p.is_viewer_friend, // true/false
|
27
29
|
isMessengerUser: p.is_messenger_user, // true/false
|
@@ -37,13 +39,13 @@ function formatParticipants(participants) {
|
|
37
39
|
name: p.name,
|
38
40
|
url: p.url,
|
39
41
|
profilePicture: p.big_image_src.uri,
|
40
|
-
username:
|
42
|
+
username: p.username || null,
|
41
43
|
// uhm... better names maybe?
|
42
44
|
acceptsMessengerUserFeedback: p.accepts_messenger_user_feedback, // true/false
|
43
45
|
isMessengerUser: p.is_messenger_user, // true/false
|
44
46
|
isVerified: p.is_verified, // true/false
|
45
47
|
isMessengerPlatformBot: p.is_messenger_platform_bot, // true/false
|
46
|
-
isMessageBlockedByViewer: p.is_message_blocked_by_viewer
|
48
|
+
isMessageBlockedByViewer: p.is_message_blocked_by_viewer // true/false
|
47
49
|
};
|
48
50
|
case "ReducedMessagingActor":
|
49
51
|
case "UnavailableMessagingActor":
|
@@ -53,15 +55,19 @@ function formatParticipants(participants) {
|
|
53
55
|
name: p.name,
|
54
56
|
url: createProfileUrl(p.url, p.username, p.id), // in this case p.url is null all the time
|
55
57
|
profilePicture: p.big_image_src.uri, // in this case it is default facebook photo, we could determine gender using it
|
56
|
-
username:
|
57
|
-
isMessageBlockedByViewer: p.is_message_blocked_by_viewer
|
58
|
+
username: p.username || null, // maybe we could use it to generate profile URL?
|
59
|
+
isMessageBlockedByViewer: p.is_message_blocked_by_viewer // true/false
|
58
60
|
};
|
59
61
|
default:
|
60
|
-
log.warn(
|
62
|
+
log.warn(
|
63
|
+
"getThreadList",
|
64
|
+
"Found participant with unsupported typename. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues\n" +
|
65
|
+
JSON.stringify(p, null, 2)
|
66
|
+
);
|
61
67
|
return {
|
62
68
|
accountType: p["__typename"],
|
63
69
|
userID: utils.formatID(p.id.toString()),
|
64
|
-
name: p.name || `[unknown ${p["__typename"]}]
|
70
|
+
name: p.name || `[unknown ${p["__typename"]}]` // probably it will always be something... but fallback to [unknown], just in case
|
65
71
|
};
|
66
72
|
}
|
67
73
|
});
|
@@ -78,30 +84,40 @@ function getThreadName(t) {
|
|
78
84
|
|
79
85
|
for (let po of t.all_participants.edges) {
|
80
86
|
let p = po.node;
|
81
|
-
if (p.messaging_actor.id === t.thread_key.other_user_id)
|
87
|
+
if (p.messaging_actor.id === t.thread_key.other_user_id)
|
88
|
+
return p.messaging_actor.name;
|
82
89
|
}
|
83
90
|
}
|
84
91
|
|
85
92
|
function mapNicknames(customizationInfo) {
|
86
|
-
return
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
93
|
+
return customizationInfo && customizationInfo.participant_customizations
|
94
|
+
? customizationInfo.participant_customizations.map(u => {
|
95
|
+
return {
|
96
|
+
userID: u.participant_id,
|
97
|
+
nickname: u.nickname
|
98
|
+
};
|
99
|
+
})
|
100
|
+
: [];
|
92
101
|
}
|
93
102
|
|
94
103
|
function formatThreadList(data) {
|
95
104
|
return data.map(t => {
|
96
|
-
let lastMessageNode =
|
105
|
+
let lastMessageNode =
|
106
|
+
t.last_message && t.last_message.nodes && t.last_message.nodes.length > 0
|
107
|
+
? t.last_message.nodes[0]
|
108
|
+
: null;
|
97
109
|
return {
|
98
|
-
threadID: t.thread_key
|
110
|
+
threadID: t.thread_key
|
111
|
+
? utils.formatID(t.thread_key.thread_fbid || t.thread_key.other_user_id)
|
112
|
+
: null, // shall never be null
|
99
113
|
name: getThreadName(t),
|
100
114
|
unreadCount: t.unread_count,
|
101
115
|
messageCount: t.messages_count,
|
102
116
|
imageSrc: t.image ? t.image.uri : null,
|
103
117
|
emoji: t.customization_info ? t.customization_info.emoji : null,
|
104
|
-
color: formatColor(
|
118
|
+
color: formatColor(
|
119
|
+
t.customization_info ? t.customization_info.outgoing_bubble_color : null
|
120
|
+
),
|
105
121
|
nicknames: mapNicknames(t.customization_info),
|
106
122
|
muteUntil: t.mute_until,
|
107
123
|
participants: formatParticipants(t.all_participants),
|
@@ -112,7 +128,9 @@ function formatThreadList(data) {
|
|
112
128
|
// isPinProtected: t.is_pin_protected, // feature from future? always false (2018-04-04)
|
113
129
|
customizationEnabled: t.customization_enabled, // false for ONE_TO_ONE with Page or ReducedMessagingActor
|
114
130
|
participantAddMode: t.participant_add_mode_as_string, // "ADD" if "GROUP" and null if "ONE_TO_ONE"
|
115
|
-
montageThread: t.montage_thread
|
131
|
+
montageThread: t.montage_thread
|
132
|
+
? Buffer.from(t.montage_thread.id, "base64").toString()
|
133
|
+
: null, // base64 encoded string "message_thread:0000000000000000"
|
116
134
|
// it is not userID nor any other ID known to me...
|
117
135
|
// can somebody inspect it? where is it used?
|
118
136
|
// probably Messenger Day uses it
|
@@ -124,74 +142,109 @@ function formatThreadList(data) {
|
|
124
142
|
// isCanonicalUser: t.is_canonical_neo_user, // is it always false?
|
125
143
|
// TODO: how about putting snippet in another object? current implementation does not handle every possibile message type etc.
|
126
144
|
snippet: lastMessageNode ? lastMessageNode.snippet : null,
|
127
|
-
snippetAttachments: lastMessageNode
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
? (
|
145
|
+
snippetAttachments: lastMessageNode
|
146
|
+
? lastMessageNode.extensible_attachment
|
147
|
+
: null, // TODO: not sure if it works
|
148
|
+
snippetSender: lastMessageNode
|
149
|
+
? utils.formatID(
|
150
|
+
(lastMessageNode.message_sender.messaging_actor.id || "").toString()
|
151
|
+
)
|
152
|
+
: null,
|
153
|
+
lastMessageTimestamp: lastMessageNode
|
154
|
+
? lastMessageNode.timestamp_precise
|
132
155
|
: null, // timestamp in miliseconds
|
156
|
+
lastReadTimestamp:
|
157
|
+
t.last_read_receipt && t.last_read_receipt.nodes.length > 0
|
158
|
+
? t.last_read_receipt.nodes[0]
|
159
|
+
? t.last_read_receipt.nodes[0].timestamp_precise
|
160
|
+
: null
|
161
|
+
: null, // timestamp in miliseconds
|
133
162
|
cannotReplyReason: t.cannot_reply_reason, // TODO: inspect possible values
|
134
163
|
approvalMode: Boolean(t.approval_mode),
|
135
164
|
|
136
165
|
// @Legacy
|
137
|
-
participantIDs: formatParticipants(t.all_participants).map(
|
166
|
+
participantIDs: formatParticipants(t.all_participants).map(
|
167
|
+
participant => participant.userID
|
168
|
+
),
|
138
169
|
threadType: t.thread_type === "GROUP" ? 2 : 1 // "GROUP" or "ONE_TO_ONE"
|
139
170
|
};
|
140
171
|
});
|
141
172
|
}
|
142
173
|
|
143
|
-
module.exports = function
|
174
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
144
175
|
return function getThreadList(limit, timestamp, tags, callback) {
|
145
|
-
if (
|
176
|
+
if (
|
177
|
+
!callback &&
|
178
|
+
(utils.getType(tags) === "Function" ||
|
179
|
+
utils.getType(tags) === "AsyncFunction")
|
180
|
+
) {
|
146
181
|
callback = tags;
|
147
182
|
tags = [""];
|
148
183
|
}
|
149
|
-
if (
|
184
|
+
if (
|
185
|
+
utils.getType(limit) !== "Number" ||
|
186
|
+
!Number.isInteger(limit) ||
|
187
|
+
limit <= 0
|
188
|
+
)
|
189
|
+
throw { error: "getThreadList: limit must be a positive integer" };
|
150
190
|
|
151
|
-
if (
|
191
|
+
if (
|
192
|
+
utils.getType(timestamp) !== "Null" &&
|
193
|
+
(utils.getType(timestamp) !== "Number" || !Number.isInteger(timestamp))
|
194
|
+
)
|
195
|
+
throw { error: "getThreadList: timestamp must be an integer or null" };
|
152
196
|
|
153
197
|
if (utils.getType(tags) === "String") tags = [tags];
|
154
|
-
if (utils.getType(tags) !== "Array")
|
198
|
+
if (utils.getType(tags) !== "Array")
|
199
|
+
throw { error: "getThreadList: tags must be an array" };
|
155
200
|
|
156
|
-
var resolveFunc = function
|
157
|
-
var rejectFunc = function
|
158
|
-
var returnPromise = new Promise(function
|
201
|
+
var resolveFunc = function() {};
|
202
|
+
var rejectFunc = function() {};
|
203
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
159
204
|
resolveFunc = resolve;
|
160
205
|
rejectFunc = reject;
|
161
206
|
});
|
162
207
|
|
163
|
-
if (
|
164
|
-
callback
|
208
|
+
if (
|
209
|
+
utils.getType(callback) !== "Function" &&
|
210
|
+
utils.getType(callback) !== "AsyncFunction"
|
211
|
+
) {
|
212
|
+
callback = function(err, data) {
|
165
213
|
if (err) return rejectFunc(err);
|
166
214
|
resolveFunc(data);
|
167
215
|
};
|
168
216
|
}
|
169
217
|
|
170
218
|
const form = {
|
171
|
-
|
172
|
-
|
173
|
-
|
219
|
+
av: ctx.globalOptions.pageID,
|
220
|
+
queries: JSON.stringify({
|
221
|
+
o0: {
|
174
222
|
// This doc_id was valid on 2020-07-20
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
223
|
+
doc_id: "3336396659757871",
|
224
|
+
query_params: {
|
225
|
+
limit: limit + (timestamp ? 1 : 0),
|
226
|
+
before: timestamp,
|
227
|
+
tags: tags,
|
228
|
+
includeDeliveryReceipts: true,
|
229
|
+
includeSeqID: false
|
182
230
|
}
|
183
231
|
}
|
184
232
|
}),
|
185
|
-
|
233
|
+
batch_name: "MessengerGraphQLThreadlistFetcher"
|
186
234
|
};
|
187
235
|
|
188
236
|
defaultFuncs
|
189
237
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
190
238
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
191
|
-
.then(
|
192
|
-
if (resData[resData.length - 1].error_results > 0)
|
239
|
+
.then(resData => {
|
240
|
+
if (resData[resData.length - 1].error_results > 0)
|
241
|
+
throw resData[0].o0.errors;
|
193
242
|
|
194
|
-
if (resData[resData.length - 1].successful_results === 0)
|
243
|
+
if (resData[resData.length - 1].successful_results === 0)
|
244
|
+
throw {
|
245
|
+
error: "getThreadList: there was no successful_results",
|
246
|
+
res: resData
|
247
|
+
};
|
195
248
|
|
196
249
|
// When we ask for threads using timestamp from the previous request,
|
197
250
|
// we are getting the last thread repeated as the first thread in this response.
|
@@ -201,10 +254,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
201
254
|
// but after removing the duplicated one, it is again 10
|
202
255
|
if (timestamp) resData[0].o0.data.viewer.message_threads.nodes.shift();
|
203
256
|
|
204
|
-
callback(
|
257
|
+
callback(
|
258
|
+
null,
|
259
|
+
formatThreadList(resData[0].o0.data.viewer.message_threads.nodes)
|
260
|
+
);
|
205
261
|
})
|
206
|
-
.catch(
|
207
|
-
log.error(
|
262
|
+
.catch(err => {
|
263
|
+
log.error(
|
264
|
+
"getThreadList",
|
265
|
+
"Lỗi: getThreadList Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !"
|
266
|
+
);
|
208
267
|
return callback(err);
|
209
268
|
});
|
210
269
|
|
@@ -3,21 +3,31 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function getThreadList(start, end, type, callback) {
|
8
8
|
if (utils.getType(callback) === "Undefined") {
|
9
|
-
if (utils.getType(end) !== "Number")
|
10
|
-
|
9
|
+
if (utils.getType(end) !== "Number")
|
10
|
+
throw { error: "Please pass a number as a second argument." };
|
11
|
+
else if (
|
12
|
+
utils.getType(type) === "Function" ||
|
13
|
+
utils.getType(type) === "AsyncFunction"
|
14
|
+
) {
|
11
15
|
callback = type;
|
12
16
|
type = "inbox"; //default to inbox
|
13
|
-
}
|
14
|
-
|
17
|
+
} else if (utils.getType(type) !== "String")
|
18
|
+
throw {
|
19
|
+
error:
|
20
|
+
"Please pass a String as a third argument. Your options are: inbox, pending, and archived"
|
21
|
+
};
|
15
22
|
else throw { error: "getThreadList: need callback" };
|
16
23
|
}
|
17
24
|
|
18
25
|
if (type === "archived") type = "action:archived";
|
19
|
-
else if (type !== "inbox" && type !== "pending" && type !== "other")
|
20
|
-
|
26
|
+
else if (type !== "inbox" && type !== "pending" && type !== "other")
|
27
|
+
throw {
|
28
|
+
error:
|
29
|
+
"type can only be one of the following: inbox, pending, archived, other"
|
30
|
+
};
|
21
31
|
|
22
32
|
if (end <= start) end = start + 20;
|
23
33
|
|
@@ -28,17 +38,25 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
28
38
|
form[type + "[offset]"] = start;
|
29
39
|
form[type + "[limit]"] = end - start;
|
30
40
|
|
31
|
-
if (ctx.globalOptions.pageID)
|
41
|
+
if (ctx.globalOptions.pageID)
|
42
|
+
form.request_user_id = ctx.globalOptions.pageID;
|
32
43
|
|
33
44
|
defaultFuncs
|
34
|
-
.post(
|
45
|
+
.post(
|
46
|
+
"https://www.facebook.com/ajax/mercury/threadlist_info.php",
|
47
|
+
ctx.jar,
|
48
|
+
form
|
49
|
+
)
|
35
50
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
-
.then(function
|
51
|
+
.then(function(resData) {
|
37
52
|
if (resData.error) throw resData;
|
38
53
|
log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
|
39
|
-
return callback(
|
54
|
+
return callback(
|
55
|
+
null,
|
56
|
+
(resData.payload.threads || []).map(utils.formatThread)
|
57
|
+
);
|
40
58
|
})
|
41
|
-
.catch(function
|
59
|
+
.catch(function(err) {
|
42
60
|
log.error("getThreadList", err);
|
43
61
|
return callback(err);
|
44
62
|
});
|
package/src/getThreadPictures.js
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function getThreadPictures(threadID, offset, limit, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
callback = function
|
16
|
+
callback = function(err, data) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
resolveFunc(data);
|
19
19
|
};
|
@@ -26,31 +26,43 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
26
26
|
};
|
27
27
|
|
28
28
|
defaultFuncs
|
29
|
-
.post(
|
29
|
+
.post(
|
30
|
+
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
31
|
+
ctx.jar,
|
32
|
+
form
|
33
|
+
)
|
30
34
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
31
|
-
.then(function
|
35
|
+
.then(function(resData) {
|
32
36
|
if (resData.error) throw resData;
|
33
37
|
return Promise.all(
|
34
|
-
resData.payload.imagesData.map(function
|
38
|
+
resData.payload.imagesData.map(function(image) {
|
35
39
|
form = {
|
36
40
|
thread_id: threadID,
|
37
41
|
image_id: image.fbid
|
38
42
|
};
|
39
43
|
return defaultFuncs
|
40
|
-
.post(
|
44
|
+
.post(
|
45
|
+
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
46
|
+
ctx.jar,
|
47
|
+
form
|
48
|
+
)
|
41
49
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
42
|
-
.then(function
|
50
|
+
.then(function(resData) {
|
43
51
|
if (resData.error) throw resData;
|
44
52
|
// the response is pretty messy
|
45
|
-
var queryThreadID =
|
46
|
-
|
53
|
+
var queryThreadID =
|
54
|
+
resData.jsmods.require[0][3][1].query_metadata.query_path[0]
|
55
|
+
.message_thread;
|
56
|
+
var imageData =
|
57
|
+
resData.jsmods.require[0][3][1].query_results[queryThreadID]
|
58
|
+
.message_images.edges[0].node.image2;
|
47
59
|
return imageData;
|
48
60
|
});
|
49
61
|
})
|
50
62
|
);
|
51
63
|
})
|
52
64
|
.then(resData => callback(null, resData))
|
53
|
-
.catch(function
|
65
|
+
.catch(function(err) {
|
54
66
|
log.error("Error in getThreadPictures", err);
|
55
67
|
callback(err);
|
56
68
|
});
|
package/src/getUserID.js
CHANGED
@@ -17,17 +17,17 @@ function formatData(data) {
|
|
17
17
|
};
|
18
18
|
}
|
19
19
|
|
20
|
-
module.exports = function
|
20
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
21
21
|
return function getUserID(name, callback) {
|
22
|
-
var resolveFunc = function
|
23
|
-
var rejectFunc = function
|
24
|
-
var returnPromise = new Promise(function
|
22
|
+
var resolveFunc = function() {};
|
23
|
+
var rejectFunc = function() {};
|
24
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
25
25
|
resolveFunc = resolve;
|
26
26
|
rejectFunc = reject;
|
27
27
|
});
|
28
28
|
|
29
29
|
if (!callback) {
|
30
|
-
callback = function
|
30
|
+
callback = function(err, data) {
|
31
31
|
if (err) return rejectFunc(err);
|
32
32
|
resolveFunc(data);
|
33
33
|
};
|
@@ -45,15 +45,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
45
45
|
defaultFuncs
|
46
46
|
.get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
|
47
47
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
48
|
-
.then(function
|
48
|
+
.then(function(resData) {
|
49
49
|
if (resData.error) throw resData;
|
50
50
|
|
51
51
|
var data = resData.payload.entries;
|
52
52
|
|
53
53
|
callback(null, data.map(formatData));
|
54
54
|
})
|
55
|
-
.catch(function
|
55
|
+
.catch(function(err) {
|
56
56
|
log.error("getUserID", err);
|
57
|
+
console.log(err);
|
57
58
|
return callback(err);
|
58
59
|
});
|
59
60
|
|
package/src/getUserInfo.js
CHANGED
@@ -27,17 +27,17 @@ function formatData(data) {
|
|
27
27
|
return retObj;
|
28
28
|
}
|
29
29
|
|
30
|
-
module.exports = function
|
30
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
31
31
|
return function getUserInfo(id, callback) {
|
32
|
-
var resolveFunc = function
|
33
|
-
var rejectFunc = function
|
34
|
-
var returnPromise = new Promise(function
|
32
|
+
var resolveFunc = function() {};
|
33
|
+
var rejectFunc = function() {};
|
34
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
35
35
|
resolveFunc = resolve;
|
36
36
|
rejectFunc = reject;
|
37
37
|
});
|
38
38
|
|
39
39
|
if (!callback) {
|
40
|
-
callback = function
|
40
|
+
callback = function(err, userInfo) {
|
41
41
|
if (err) return rejectFunc(err);
|
42
42
|
resolveFunc(userInfo);
|
43
43
|
};
|
@@ -46,18 +46,21 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
46
46
|
if (utils.getType(id) !== "Array") id = [id];
|
47
47
|
|
48
48
|
var form = {};
|
49
|
-
id.map(function
|
49
|
+
id.map(function(v, i) {
|
50
50
|
form["ids[" + i + "]"] = v;
|
51
51
|
});
|
52
52
|
defaultFuncs
|
53
53
|
.post("https://www.facebook.com/chat/user_info/", ctx.jar, form)
|
54
54
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
55
|
-
.then(function
|
55
|
+
.then(function(resData) {
|
56
56
|
if (resData.error) throw resData;
|
57
57
|
return callback(null, formatData(resData.payload.profiles));
|
58
58
|
})
|
59
|
-
.catch(function
|
60
|
-
log.error(
|
59
|
+
.catch(function(err) {
|
60
|
+
log.error(
|
61
|
+
"getUserInfo",
|
62
|
+
"Lỗi: getUserInfo Có Thể Do Bạn Spam Quá Nhiều !,Hãy Thử Lại !"
|
63
|
+
);
|
61
64
|
return callback(err);
|
62
65
|
});
|
63
66
|
return returnPromise;
|
@@ -3,19 +3,20 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function handleFriendRequest(userID, accept, callback) {
|
8
|
-
if (utils.getType(accept) !== "Boolean")
|
8
|
+
if (utils.getType(accept) !== "Boolean")
|
9
|
+
throw { error: "Please pass a boolean as a second argument." };
|
9
10
|
|
10
|
-
var resolveFunc = function
|
11
|
-
var rejectFunc = function
|
12
|
-
var returnPromise = new Promise(function
|
11
|
+
var resolveFunc = function() {};
|
12
|
+
var rejectFunc = function() {};
|
13
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
13
14
|
resolveFunc = resolve;
|
14
15
|
rejectFunc = reject;
|
15
16
|
});
|
16
17
|
|
17
18
|
if (!callback) {
|
18
|
-
callback = function
|
19
|
+
callback = function(err, data) {
|
19
20
|
if (err) return rejectFunc(err);
|
20
21
|
resolveFunc(data);
|
21
22
|
};
|
@@ -26,17 +27,17 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
26
27
|
"frefs[0]": "jwl",
|
27
28
|
floc: "friend_center_requests",
|
28
29
|
ref: "/reqs.php",
|
29
|
-
action:
|
30
|
+
action: accept ? "confirm" : "reject"
|
30
31
|
};
|
31
32
|
|
32
33
|
defaultFuncs
|
33
34
|
.post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
|
34
35
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
35
|
-
.then(function
|
36
|
+
.then(function(resData) {
|
36
37
|
if (resData.payload.err) throw { err: resData.payload.err };
|
37
38
|
return callback();
|
38
39
|
})
|
39
|
-
.catch(function
|
40
|
+
.catch(function(err) {
|
40
41
|
log.error("handleFriendRequest", err);
|
41
42
|
return callback(err);
|
42
43
|
});
|
@@ -3,19 +3,20 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function handleMessageRequest(threadID, accept, callback) {
|
8
|
-
if (utils.getType(accept) !== "Boolean")
|
8
|
+
if (utils.getType(accept) !== "Boolean")
|
9
|
+
throw { error: "Please pass a boolean as a second argument." };
|
9
10
|
|
10
|
-
var resolveFunc = function
|
11
|
-
var rejectFunc = function
|
12
|
-
var returnPromise = new Promise(function
|
11
|
+
var resolveFunc = function() {};
|
12
|
+
var rejectFunc = function() {};
|
13
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
13
14
|
resolveFunc = resolve;
|
14
15
|
rejectFunc = reject;
|
15
16
|
});
|
16
17
|
|
17
18
|
if (!callback) {
|
18
|
-
callback = function
|
19
|
+
callback = function(err, data) {
|
19
20
|
if (err) return rejectFunc(err);
|
20
21
|
resolveFunc(data);
|
21
22
|
};
|
@@ -29,17 +30,22 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
29
30
|
|
30
31
|
var messageBox = accept ? "inbox" : "other";
|
31
32
|
|
32
|
-
for (var i = 0; i < threadID.length; i++)
|
33
|
+
for (var i = 0; i < threadID.length; i++)
|
34
|
+
form[messageBox + "[" + i + "]"] = threadID[i];
|
33
35
|
|
34
36
|
defaultFuncs
|
35
|
-
.post(
|
37
|
+
.post(
|
38
|
+
"https://www.facebook.com/ajax/mercury/move_thread.php",
|
39
|
+
ctx.jar,
|
40
|
+
form
|
41
|
+
)
|
36
42
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
37
|
-
.then(function
|
43
|
+
.then(function(resData) {
|
38
44
|
if (resData.error) throw resData;
|
39
45
|
|
40
46
|
return callback();
|
41
47
|
})
|
42
|
-
.catch(function
|
48
|
+
.catch(function(err) {
|
43
49
|
log.error("handleMessageRequest", err);
|
44
50
|
return callback(err);
|
45
51
|
});
|