nayan-remake-api 0.0.1-security → 2.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.
Potentially problematic release.
This version of nayan-remake-api might be problematic. Click here for more details.
- package/.cache/replit/__replit_disk_meta.json +1 -0
- package/.config/configstore/update-notifier-npm.json +4 -0
- package/.config/configstore/update-notifier-npm.json.1735545094 +4 -0
- package/.replit +80 -0
- package/CHANGELOG.md +2 -0
- package/DOCS.md +1947 -0
- package/LICENSE-MIT +21 -0
- package/README.md +198 -3
- package/index.js +641 -0
- package/package.json +69 -3
- package/replit.nix +8 -0
- package/src/addExternalModule.js +19 -0
- package/src/addUserToGroup.js +113 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/changeAvatar.js +127 -0
- package/src/changeBio.js +77 -0
- package/src/changeBlockedStatus.js +47 -0
- package/src/changeGroupImage.js +133 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +65 -0
- package/src/changeThreadEmoji.js +55 -0
- package/src/createNewGroup.js +86 -0
- package/src/createPoll.js +71 -0
- package/src/deleteMessage.js +56 -0
- package/src/deleteThread.js +56 -0
- package/src/forwardAttachment.js +60 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/getFriendsList.js +84 -0
- package/src/getMessage.js +716 -0
- package/src/getThreadHistory.js +666 -0
- package/src/getThreadInfo.js +232 -0
- package/src/getThreadList.js +237 -0
- package/src/getThreadPictures.js +79 -0
- package/src/getUserID.js +66 -0
- package/src/getUserInfo.js +74 -0
- package/src/handleFriendRequest.js +61 -0
- package/src/handleMessageRequest.js +65 -0
- package/src/httpGet.js +57 -0
- package/src/httpPost.js +57 -0
- package/src/httpPostFormData.js +59 -0
- package/src/listenMqtt.js +862 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +58 -0
- package/src/markAsRead.js +80 -0
- package/src/markAsReadAll.js +50 -0
- package/src/markAsSeen.js +59 -0
- package/src/muteThread.js +52 -0
- package/src/n +1 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/resolvePhotoUrl.js +45 -0
- package/src/searchForThread.js +53 -0
- package/src/sendMessage.js +449 -0
- package/src/sendTypingIndicator.js +103 -0
- package/src/setMessageReaction.js +117 -0
- package/src/setPostReaction.js +109 -0
- package/src/setTitle.js +86 -0
- package/src/threadColors.js +120 -0
- package/src/unfriend.js +52 -0
- package/src/unsendMessage.js +49 -0
- package/src/uploadAttachment.js +96 -0
- package/test/data/N +1 -0
- package/test/data/shareAttach.js +146 -0
- package/test/data/test.txt +7 -0
- package/test/example-config.json +18 -0
- package/test/n +1 -0
- package/test/test-page.js +140 -0
- package/test/test.js +387 -0
- package/utils.js +1451 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
const bluebird = require("bluebird");
|
|
6
|
+
|
|
7
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
8
|
+
function handleUpload(image, callback) {
|
|
9
|
+
const uploads = [];
|
|
10
|
+
|
|
11
|
+
const form = {
|
|
12
|
+
images_only: "true",
|
|
13
|
+
"attachment[]": image
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
uploads.push(
|
|
17
|
+
defaultFuncs
|
|
18
|
+
.postFormData(
|
|
19
|
+
"https://upload.facebook.com/ajax/mercury/upload.php",
|
|
20
|
+
ctx.jar,
|
|
21
|
+
form,
|
|
22
|
+
{}
|
|
23
|
+
)
|
|
24
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
25
|
+
.then(function (resData) {
|
|
26
|
+
if (resData.error) {
|
|
27
|
+
throw resData;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return resData.payload.metadata[0];
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// resolve all promises
|
|
35
|
+
bluebird
|
|
36
|
+
.all(uploads)
|
|
37
|
+
.then(function (resData) {
|
|
38
|
+
callback(null, resData);
|
|
39
|
+
})
|
|
40
|
+
.catch(function (err) {
|
|
41
|
+
log.error("handleUpload", err);
|
|
42
|
+
return callback(err);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return function changeGroupImage(image, threadID, callback) {
|
|
47
|
+
if (
|
|
48
|
+
!callback &&
|
|
49
|
+
(utils.getType(threadID) === "Function" ||
|
|
50
|
+
utils.getType(threadID) === "AsyncFunction")
|
|
51
|
+
) {
|
|
52
|
+
throw { error: "please pass a threadID as a second argument." };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!utils.isReadableStream(image)) {
|
|
56
|
+
throw { error: "please pass a readable stream as a first argument." };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let resolveFunc = function () { };
|
|
60
|
+
let rejectFunc = function () { };
|
|
61
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
62
|
+
resolveFunc = resolve;
|
|
63
|
+
rejectFunc = reject;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!callback) {
|
|
67
|
+
callback = function (err) {
|
|
68
|
+
if (err) {
|
|
69
|
+
return rejectFunc(err);
|
|
70
|
+
}
|
|
71
|
+
resolveFunc();
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const messageAndOTID = utils.generateOfflineThreadingID();
|
|
76
|
+
const form = {
|
|
77
|
+
client: "mercury",
|
|
78
|
+
action_type: "ma-type:log-message",
|
|
79
|
+
author: "fbid:" + (ctx.i_userID || ctx.userID),
|
|
80
|
+
author_email: "",
|
|
81
|
+
ephemeral_ttl_mode: "0",
|
|
82
|
+
is_filtered_content: false,
|
|
83
|
+
is_filtered_content_account: false,
|
|
84
|
+
is_filtered_content_bh: false,
|
|
85
|
+
is_filtered_content_invalid_app: false,
|
|
86
|
+
is_filtered_content_quasar: false,
|
|
87
|
+
is_forward: false,
|
|
88
|
+
is_spoof_warning: false,
|
|
89
|
+
is_unread: false,
|
|
90
|
+
log_message_type: "log:thread-image",
|
|
91
|
+
manual_retry_cnt: "0",
|
|
92
|
+
message_id: messageAndOTID,
|
|
93
|
+
offline_threading_id: messageAndOTID,
|
|
94
|
+
source: "source:chat:web",
|
|
95
|
+
"source_tags[0]": "source:chat",
|
|
96
|
+
status: "0",
|
|
97
|
+
thread_fbid: threadID,
|
|
98
|
+
thread_id: "",
|
|
99
|
+
timestamp: Date.now(),
|
|
100
|
+
timestamp_absolute: "Today",
|
|
101
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
|
102
|
+
timestamp_time_passed: "0"
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
handleUpload(image, function (err, payload) {
|
|
106
|
+
if (err) {
|
|
107
|
+
return callback(err);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
form["thread_image_id"] = payload[0]["image_id"];
|
|
111
|
+
form["thread_id"] = threadID;
|
|
112
|
+
|
|
113
|
+
defaultFuncs
|
|
114
|
+
.post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
|
|
115
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
116
|
+
.then(function (resData) {
|
|
117
|
+
// check for errors here
|
|
118
|
+
|
|
119
|
+
if (resData.error) {
|
|
120
|
+
throw resData;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return callback();
|
|
124
|
+
})
|
|
125
|
+
.catch(function (err) {
|
|
126
|
+
log.error("changeGroupImage", err);
|
|
127
|
+
return callback(err);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return returnPromise;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function changeNickname(nickname, threadID, participantID, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = function (err) {
|
|
16
|
+
if (err) {
|
|
17
|
+
return rejectFunc(err);
|
|
18
|
+
}
|
|
19
|
+
resolveFunc();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const form = {
|
|
24
|
+
nickname: nickname,
|
|
25
|
+
participant_id: participantID,
|
|
26
|
+
thread_or_other_fbid: threadID
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
defaultFuncs
|
|
30
|
+
.post(
|
|
31
|
+
"https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1",
|
|
32
|
+
ctx.jar,
|
|
33
|
+
form
|
|
34
|
+
)
|
|
35
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
36
|
+
.then(function (resData) {
|
|
37
|
+
if (resData.error === 1545014) {
|
|
38
|
+
throw { error: "Trying to change nickname of user isn't in thread" };
|
|
39
|
+
}
|
|
40
|
+
if (resData.error === 1357031) {
|
|
41
|
+
throw {
|
|
42
|
+
error:
|
|
43
|
+
"Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname."
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (resData.error) {
|
|
47
|
+
throw resData;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return callback();
|
|
51
|
+
})
|
|
52
|
+
.catch(function (err) {
|
|
53
|
+
log.error("changeNickname", err);
|
|
54
|
+
return callback(err);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return returnPromise;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function changeThreadColor(color, threadID, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!callback) {
|
|
16
|
+
callback = function (err) {
|
|
17
|
+
if (err) {
|
|
18
|
+
return rejectFunc(err);
|
|
19
|
+
}
|
|
20
|
+
resolveFunc(err);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!isNaN(color)) {
|
|
25
|
+
color = color.toString();
|
|
26
|
+
}
|
|
27
|
+
const validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
|
|
28
|
+
|
|
29
|
+
const form = {
|
|
30
|
+
dpr: 1,
|
|
31
|
+
queries: JSON.stringify({
|
|
32
|
+
o0: {
|
|
33
|
+
//This doc_id is valid as of January 31, 2020
|
|
34
|
+
doc_id: "1727493033983591",
|
|
35
|
+
query_params: {
|
|
36
|
+
data: {
|
|
37
|
+
actor_id: ctx.i_userID || ctx.userID,
|
|
38
|
+
client_mutation_id: "0",
|
|
39
|
+
source: "SETTINGS",
|
|
40
|
+
theme_id: validatedColor,
|
|
41
|
+
thread_id: threadID
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
defaultFuncs
|
|
49
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
|
50
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
51
|
+
.then(function (resData) {
|
|
52
|
+
if (resData[resData.length - 1].error_results > 0) {
|
|
53
|
+
throw resData[0].o0.errors;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return callback();
|
|
57
|
+
})
|
|
58
|
+
.catch(function (err) {
|
|
59
|
+
log.error("changeThreadColor", err);
|
|
60
|
+
return callback(err);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return returnPromise;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function changeThreadEmoji(emoji, threadID, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!callback) {
|
|
16
|
+
callback = function (err) {
|
|
17
|
+
if (err) {
|
|
18
|
+
return rejectFunc(err);
|
|
19
|
+
}
|
|
20
|
+
resolveFunc();
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const form = {
|
|
24
|
+
emoji_choice: emoji,
|
|
25
|
+
thread_or_other_fbid: threadID
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
defaultFuncs
|
|
29
|
+
.post(
|
|
30
|
+
"https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
|
|
31
|
+
ctx.jar,
|
|
32
|
+
form
|
|
33
|
+
)
|
|
34
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
35
|
+
.then(function (resData) {
|
|
36
|
+
if (resData.error === 1357031) {
|
|
37
|
+
throw {
|
|
38
|
+
error:
|
|
39
|
+
"Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji."
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (resData.error) {
|
|
43
|
+
throw resData;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return callback();
|
|
47
|
+
})
|
|
48
|
+
.catch(function (err) {
|
|
49
|
+
log.error("changeThreadEmoji", err);
|
|
50
|
+
return callback(err);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return returnPromise;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function createNewGroup(participantIDs, groupTitle, callback) {
|
|
8
|
+
if (utils.getType(groupTitle) == "Function") {
|
|
9
|
+
callback = groupTitle;
|
|
10
|
+
groupTitle = null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (utils.getType(participantIDs) !== "Array") {
|
|
14
|
+
throw { error: "createNewGroup: participantIDs should be an array." };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (participantIDs.length < 2) {
|
|
18
|
+
throw { error: "createNewGroup: participantIDs should have at least 2 IDs." };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let resolveFunc = function () { };
|
|
22
|
+
let rejectFunc = function () { };
|
|
23
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
24
|
+
resolveFunc = resolve;
|
|
25
|
+
rejectFunc = reject;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (!callback) {
|
|
29
|
+
callback = function (err, threadID) {
|
|
30
|
+
if (err) {
|
|
31
|
+
return rejectFunc(err);
|
|
32
|
+
}
|
|
33
|
+
resolveFunc(threadID);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const pids = [];
|
|
38
|
+
for (const n in participantIDs) {
|
|
39
|
+
pids.push({
|
|
40
|
+
fbid: participantIDs[n]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
pids.push({ fbid: ctx.i_userID || ctx.userID });
|
|
44
|
+
|
|
45
|
+
const form = {
|
|
46
|
+
fb_api_caller_class: "RelayModern",
|
|
47
|
+
fb_api_req_friendly_name: "MessengerGroupCreateMutation",
|
|
48
|
+
av: ctx.i_userID || ctx.userID,
|
|
49
|
+
//This doc_id is valid as of January 11th, 2020
|
|
50
|
+
doc_id: "577041672419534",
|
|
51
|
+
variables: JSON.stringify({
|
|
52
|
+
input: {
|
|
53
|
+
entry_point: "jewel_new_group",
|
|
54
|
+
actor_id: ctx.i_userID || ctx.userID,
|
|
55
|
+
participants: pids,
|
|
56
|
+
client_mutation_id: Math.round(Math.random() * 1024).toString(),
|
|
57
|
+
thread_settings: {
|
|
58
|
+
name: groupTitle,
|
|
59
|
+
joinable_mode: "PRIVATE",
|
|
60
|
+
thread_image_fbid: null
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
defaultFuncs
|
|
67
|
+
.post(
|
|
68
|
+
"https://www.facebook.com/api/graphql/",
|
|
69
|
+
ctx.jar,
|
|
70
|
+
form
|
|
71
|
+
)
|
|
72
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
73
|
+
.then(function (resData) {
|
|
74
|
+
if (resData.errors) {
|
|
75
|
+
throw resData;
|
|
76
|
+
}
|
|
77
|
+
return callback(null, resData.data.messenger_group_thread_create.thread.thread_key.thread_fbid);
|
|
78
|
+
})
|
|
79
|
+
.catch(function (err) {
|
|
80
|
+
log.error("createNewGroup", err);
|
|
81
|
+
return callback(err);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return returnPromise;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function createPoll(title, threadID, options, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!callback) {
|
|
16
|
+
if (utils.getType(options) == "Function") {
|
|
17
|
+
callback = options;
|
|
18
|
+
options = null;
|
|
19
|
+
} else {
|
|
20
|
+
callback = function (err) {
|
|
21
|
+
if (err) {
|
|
22
|
+
return rejectFunc(err);
|
|
23
|
+
}
|
|
24
|
+
resolveFunc();
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!options) {
|
|
29
|
+
options = {}; // Initial poll options are optional
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const form = {
|
|
33
|
+
target_id: threadID,
|
|
34
|
+
question_text: title
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Set fields for options (and whether they are selected initially by the posting user)
|
|
38
|
+
let ind = 0;
|
|
39
|
+
for (const opt in options) {
|
|
40
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
41
|
+
if (options.hasOwnProperty(opt)) {
|
|
42
|
+
form["option_text_array[" + ind + "]"] = opt;
|
|
43
|
+
form["option_is_selected_array[" + ind + "]"] = options[opt]
|
|
44
|
+
? "1"
|
|
45
|
+
: "0";
|
|
46
|
+
ind++;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
defaultFuncs
|
|
51
|
+
.post(
|
|
52
|
+
"https://www.facebook.com/messaging/group_polling/create_poll/?dpr=1",
|
|
53
|
+
ctx.jar,
|
|
54
|
+
form
|
|
55
|
+
)
|
|
56
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
57
|
+
.then(function (resData) {
|
|
58
|
+
if (resData.payload.status != "success") {
|
|
59
|
+
throw resData;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return callback();
|
|
63
|
+
})
|
|
64
|
+
.catch(function (err) {
|
|
65
|
+
log.error("createPoll", err);
|
|
66
|
+
return callback(err);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return returnPromise;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function deleteMessage(messageOrMessages, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = function (err) {
|
|
16
|
+
if (err) {
|
|
17
|
+
return rejectFunc(err);
|
|
18
|
+
}
|
|
19
|
+
resolveFunc();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const form = {
|
|
24
|
+
client: "mercury"
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (utils.getType(messageOrMessages) !== "Array") {
|
|
28
|
+
messageOrMessages = [messageOrMessages];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < messageOrMessages.length; i++) {
|
|
32
|
+
form["message_ids[" + i + "]"] = messageOrMessages[i];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
defaultFuncs
|
|
36
|
+
.post(
|
|
37
|
+
"https://www.facebook.com/ajax/mercury/delete_messages.php",
|
|
38
|
+
ctx.jar,
|
|
39
|
+
form
|
|
40
|
+
)
|
|
41
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
42
|
+
.then(function (resData) {
|
|
43
|
+
if (resData.error) {
|
|
44
|
+
throw resData;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return callback();
|
|
48
|
+
})
|
|
49
|
+
.catch(function (err) {
|
|
50
|
+
log.error("deleteMessage", err);
|
|
51
|
+
return callback(err);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return returnPromise;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function deleteThread(threadOrThreads, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = function (err) {
|
|
16
|
+
if (err) {
|
|
17
|
+
return rejectFunc(err);
|
|
18
|
+
}
|
|
19
|
+
resolveFunc();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const form = {
|
|
24
|
+
client: "mercury"
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (utils.getType(threadOrThreads) !== "Array") {
|
|
28
|
+
threadOrThreads = [threadOrThreads];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < threadOrThreads.length; i++) {
|
|
32
|
+
form["ids[" + i + "]"] = threadOrThreads[i];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
defaultFuncs
|
|
36
|
+
.post(
|
|
37
|
+
"https://www.facebook.com/ajax/mercury/delete_thread.php",
|
|
38
|
+
ctx.jar,
|
|
39
|
+
form
|
|
40
|
+
)
|
|
41
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
42
|
+
.then(function (resData) {
|
|
43
|
+
if (resData.error) {
|
|
44
|
+
throw resData;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return callback();
|
|
48
|
+
})
|
|
49
|
+
.catch(function (err) {
|
|
50
|
+
log.error("deleteThread", err);
|
|
51
|
+
return callback(err);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return returnPromise;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function forwardAttachment(attachmentID, userOrUsers, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = function (err) {
|
|
16
|
+
if (err) {
|
|
17
|
+
return rejectFunc(err);
|
|
18
|
+
}
|
|
19
|
+
resolveFunc();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const form = {
|
|
24
|
+
attachment_id: attachmentID
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (utils.getType(userOrUsers) !== "Array") {
|
|
28
|
+
userOrUsers = [userOrUsers];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < userOrUsers.length; i++) {
|
|
34
|
+
//That's good, the key of the array is really timestmap in seconds + index
|
|
35
|
+
//Probably time when the attachment will be sent?
|
|
36
|
+
form["recipient_map[" + (timestamp + i) + "]"] = userOrUsers[i];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
defaultFuncs
|
|
40
|
+
.post(
|
|
41
|
+
"https://www.facebook.com/mercury/attachments/forward/",
|
|
42
|
+
ctx.jar,
|
|
43
|
+
form
|
|
44
|
+
)
|
|
45
|
+
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
|
46
|
+
.then(function (resData) {
|
|
47
|
+
if (resData.error) {
|
|
48
|
+
throw resData;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return callback();
|
|
52
|
+
})
|
|
53
|
+
.catch(function (err) {
|
|
54
|
+
log.error("forwardAttachment", err);
|
|
55
|
+
return callback(err);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return returnPromise;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const util = require("util");
|
|
4
|
+
|
|
5
|
+
module.exports = function () {
|
|
6
|
+
return function getEmojiUrl(c, size, pixelRatio) {
|
|
7
|
+
/*
|
|
8
|
+
Resolves Facebook Messenger emoji image asset URL for an emoji character.
|
|
9
|
+
Supported sizes are 32, 64, and 128.
|
|
10
|
+
Supported pixel ratios are '1.0' and '1.5' (possibly more; haven't tested)
|
|
11
|
+
*/
|
|
12
|
+
const baseUrl = "https://static.xx.fbcdn.net/images/emoji.php/v8/z%s/%s";
|
|
13
|
+
pixelRatio = pixelRatio || "1.0";
|
|
14
|
+
|
|
15
|
+
const ending = util.format(
|
|
16
|
+
"%s/%s/%s.png",
|
|
17
|
+
pixelRatio,
|
|
18
|
+
size,
|
|
19
|
+
c.codePointAt(0).toString(16)
|
|
20
|
+
);
|
|
21
|
+
let base = 317426846;
|
|
22
|
+
for (let i = 0; i < ending.length; i++) {
|
|
23
|
+
base = (base << 5) - base + ending.charCodeAt(i);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const hashed = (base & 255).toString(16);
|
|
27
|
+
return util.format(baseUrl, hashed, ending);
|
|
28
|
+
};
|
|
29
|
+
};
|