alicezetion 1.0.9 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +558 -490
- package/leiamnash/addExternalModule.js +19 -0
- package/{src → leiamnash}/addUserToGroup.js +52 -16
- package/leiamnash/changeAdminStatus.js +79 -0
- package/leiamnash/changeArchivedStatus.js +55 -0
- package/{src → leiamnash}/changeBio.js +19 -6
- package/{src → leiamnash}/changeBlockedStatus.js +14 -3
- package/{src → leiamnash}/changeGroupImage.js +40 -16
- package/leiamnash/changeNickname.js +59 -0
- package/{src → leiamnash}/changeThreadColor.js +20 -10
- package/leiamnash/changeThreadEmoji.js +55 -0
- package/leiamnash/chat.js +459 -0
- package/{src → leiamnash}/createNewGroup.js +28 -12
- package/{src → leiamnash}/createPoll.js +25 -13
- package/leiamnash/deleteMessage.js +56 -0
- package/leiamnash/deleteThread.js +56 -0
- package/leiamnash/forwardAttachment.js +60 -0
- package/{src → leiamnash}/getCurrentUserID.js +1 -1
- package/{src → leiamnash}/getEmojiUrl.js +4 -2
- package/{src → leiamnash}/getFriendsList.js +21 -10
- package/{src → leiamnash}/getThreadHistory.js +166 -58
- package/{src → leiamnash}/getThreadHistoryDeprecated.js +42 -20
- package/{src → leiamnash}/getThreadInfo.js +60 -25
- package/leiamnash/getThreadInfoDeprecated.js +80 -0
- package/{src → leiamnash}/getThreadList.js +66 -41
- package/leiamnash/getThreadListDeprecated.js +75 -0
- package/leiamnash/getThreadPictures.js +79 -0
- package/{src → leiamnash}/getUserID.js +14 -9
- package/{src → leiamnash}/getUserInfo.js +18 -12
- package/leiamnash/handleFriendRequest.js +61 -0
- package/leiamnash/handleMessageRequest.js +65 -0
- package/{src → leiamnash}/httpGet.js +17 -12
- package/{src → leiamnash}/httpPost.js +17 -12
- package/leiamnash/listenMqtt.js +687 -0
- package/{src → leiamnash}/logout.js +20 -13
- package/{src → leiamnash}/markAsDelivered.js +22 -11
- package/{src → leiamnash}/markAsRead.js +21 -11
- package/{src → leiamnash}/markAsReadAll.js +20 -10
- package/{src → leiamnash}/markAsSeen.js +18 -7
- package/{src → leiamnash}/muteThread.js +18 -11
- package/leiamnash/removeUserFromGroup.js +79 -0
- package/{src → leiamnash}/resolvePhotoUrl.js +17 -8
- package/{src → leiamnash}/searchForThread.js +21 -10
- package/{src → leiamnash}/sendTypingIndicator.js +47 -14
- package/{src → leiamnash}/setMessageReaction.js +26 -12
- package/{src → leiamnash}/setPostReaction.js +26 -13
- package/{src → leiamnash}/setTitle.js +29 -13
- package/leiamnash/threadColors.js +57 -0
- package/{src → leiamnash}/unfriend.js +19 -9
- package/{src → leiamnash}/unsendMessage.js +19 -9
- package/package.json +9 -14
- package/replit.nix +0 -1
- package/utils.js +1193 -1023
- package/src/addExternalModule.js +0 -15
- package/src/changeAdminStatus.js +0 -47
- package/src/changeArchivedStatus.js +0 -41
- package/src/changeNickname.js +0 -43
- package/src/changeThreadEmoji.js +0 -41
- package/src/chat.js +0 -315
- package/src/deleteMessage.js +0 -44
- package/src/deleteThread.js +0 -42
- package/src/forwardAttachment.js +0 -47
- package/src/forwardMessage.js +0 -0
- package/src/getThreadInfoDeprecated.js +0 -56
- package/src/getThreadListDeprecated.js +0 -46
- package/src/getThreadPictures.js +0 -59
- package/src/handleFriendRequest.js +0 -46
- package/src/handleMessageRequest.js +0 -47
- package/src/listen.js +0 -553
- package/src/listenMqtt-Test.js +0 -687
- package/src/listenMqtt.js +0 -677
- package/src/removeUserFromGroup.js +0 -45
- package/src/threadColors.js +0 -41
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
6
|
+
return function addExternalModule(moduleObj) {
|
7
|
+
if (utils.getType(moduleObj) == "Object") {
|
8
|
+
for (let apiName in moduleObj) {
|
9
|
+
if (utils.getType(moduleObj[apiName]) == "Function") {
|
10
|
+
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
11
|
+
} else {
|
12
|
+
throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
} else {
|
16
|
+
throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
|
17
|
+
}
|
18
|
+
};
|
19
|
+
};
|
@@ -3,27 +3,47 @@
|
|
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 addUserToGroup(userID, threadID, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
10
|
var returnPromise = new Promise(function (resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
|
-
if (
|
15
|
+
if (
|
16
|
+
!callback &&
|
17
|
+
(utils.getType(threadID) === "Function" ||
|
18
|
+
utils.getType(threadID) === "AsyncFunction")
|
19
|
+
) {
|
20
|
+
throw { error: "please pass a threadID as a second argument." };
|
21
|
+
}
|
16
22
|
|
17
23
|
if (!callback) {
|
18
|
-
callback = function
|
19
|
-
if (err)
|
24
|
+
callback = function(err) {
|
25
|
+
if (err) {
|
26
|
+
return rejectFunc(err);
|
27
|
+
}
|
20
28
|
resolveFunc();
|
21
29
|
};
|
22
30
|
}
|
23
31
|
|
24
|
-
if (
|
32
|
+
if (
|
33
|
+
utils.getType(threadID) !== "Number" &&
|
34
|
+
utils.getType(threadID) !== "String"
|
35
|
+
) {
|
36
|
+
throw {
|
37
|
+
error:
|
38
|
+
"ThreadID should be of type Number or String and not " +
|
39
|
+
utils.getType(threadID) +
|
40
|
+
"."
|
41
|
+
};
|
42
|
+
}
|
25
43
|
|
26
|
-
if (utils.getType(userID) !== "Array")
|
44
|
+
if (utils.getType(userID) !== "Array") {
|
45
|
+
userID = [userID];
|
46
|
+
}
|
27
47
|
|
28
48
|
var messageAndOTID = utils.generateOfflineThreadingID();
|
29
49
|
var form = {
|
@@ -54,24 +74,40 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
54
74
|
};
|
55
75
|
|
56
76
|
for (var i = 0; i < userID.length; i++) {
|
57
|
-
if (
|
58
|
-
|
77
|
+
if (
|
78
|
+
utils.getType(userID[i]) !== "Number" &&
|
79
|
+
utils.getType(userID[i]) !== "String"
|
80
|
+
) {
|
81
|
+
throw {
|
82
|
+
error:
|
83
|
+
"Elements of userID should be of type Number or String and not " +
|
84
|
+
utils.getType(userID[i]) +
|
85
|
+
"."
|
86
|
+
};
|
87
|
+
}
|
88
|
+
|
89
|
+
form["log_message_data[added_participants][" + i + "]"] =
|
90
|
+
"fbid:" + userID[i];
|
59
91
|
}
|
60
92
|
|
61
93
|
defaultFuncs
|
62
94
|
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
63
95
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
64
|
-
.then(function
|
65
|
-
if (!resData)
|
66
|
-
|
96
|
+
.then(function(resData) {
|
97
|
+
if (!resData) {
|
98
|
+
throw { error: "Add to group failed." };
|
99
|
+
}
|
100
|
+
if (resData.error) {
|
101
|
+
throw resData;
|
102
|
+
}
|
67
103
|
|
68
104
|
return callback();
|
69
105
|
})
|
70
|
-
.catch(function
|
71
|
-
log.error("addUserToGroup",
|
106
|
+
.catch(function(err) {
|
107
|
+
log.error("addUserToGroup", err);
|
72
108
|
return callback(err);
|
73
109
|
});
|
74
|
-
|
110
|
+
|
75
111
|
return returnPromise;
|
76
112
|
};
|
77
113
|
};
|
@@ -0,0 +1,79 @@
|
|
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 changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
|
8
|
+
if (utils.getType(threadID) !== "String") {
|
9
|
+
throw {error: "changeAdminStatus: threadID must be a string"};
|
10
|
+
}
|
11
|
+
|
12
|
+
if (utils.getType(adminIDs) === "String") {
|
13
|
+
adminIDs = [adminIDs];
|
14
|
+
}
|
15
|
+
|
16
|
+
if (utils.getType(adminIDs) !== "Array") {
|
17
|
+
throw {error: "changeAdminStatus: adminIDs must be an array or string"};
|
18
|
+
}
|
19
|
+
|
20
|
+
if (utils.getType(adminStatus) !== "Boolean") {
|
21
|
+
throw {error: "changeAdminStatus: adminStatus must be a string"};
|
22
|
+
}
|
23
|
+
|
24
|
+
var resolveFunc = function(){};
|
25
|
+
var rejectFunc = function(){};
|
26
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
27
|
+
resolveFunc = resolve;
|
28
|
+
rejectFunc = reject;
|
29
|
+
});
|
30
|
+
|
31
|
+
if (!callback) {
|
32
|
+
callback = function (err) {
|
33
|
+
if (err) {
|
34
|
+
return rejectFunc(err);
|
35
|
+
}
|
36
|
+
resolveFunc();
|
37
|
+
};
|
38
|
+
}
|
39
|
+
|
40
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
41
|
+
throw {error: "changeAdminStatus: callback is not a function"};
|
42
|
+
}
|
43
|
+
|
44
|
+
let form = {
|
45
|
+
"thread_fbid": threadID,
|
46
|
+
};
|
47
|
+
|
48
|
+
let i = 0;
|
49
|
+
for (let u of adminIDs) {
|
50
|
+
form[`admin_ids[${i++}]`] = u;
|
51
|
+
}
|
52
|
+
form["add"] = adminStatus;
|
53
|
+
|
54
|
+
defaultFuncs
|
55
|
+
.post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
|
56
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
57
|
+
.then(function(resData) {
|
58
|
+
if (resData.error) {
|
59
|
+
switch (resData.error) {
|
60
|
+
case 1976004:
|
61
|
+
throw { error: "Cannot alter admin status: you are not an admin.", rawResponse: resData };
|
62
|
+
case 1357031:
|
63
|
+
throw { error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData };
|
64
|
+
default:
|
65
|
+
throw { error: "Cannot alter admin status: unknown error.", rawResponse: resData };
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
callback();
|
70
|
+
})
|
71
|
+
.catch(function(err) {
|
72
|
+
log.error("changeAdminStatus", err);
|
73
|
+
return callback(err);
|
74
|
+
});
|
75
|
+
|
76
|
+
return returnPromise;
|
77
|
+
};
|
78
|
+
};
|
79
|
+
|
@@ -0,0 +1,55 @@
|
|
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 changeArchivedStatus(threadOrThreads, archive, callback) {
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback) {
|
16
|
+
callback = function(err) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
20
|
+
resolveFunc();
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
var form = {};
|
25
|
+
|
26
|
+
if (utils.getType(threadOrThreads) === "Array") {
|
27
|
+
for (var i = 0; i < threadOrThreads.length; i++) {
|
28
|
+
form["ids[" + threadOrThreads[i] + "]"] = archive;
|
29
|
+
}
|
30
|
+
} else {
|
31
|
+
form["ids[" + threadOrThreads + "]"] = archive;
|
32
|
+
}
|
33
|
+
|
34
|
+
defaultFuncs
|
35
|
+
.post(
|
36
|
+
"https://www.facebook.com/ajax/mercury/change_archived_status.php",
|
37
|
+
ctx.jar,
|
38
|
+
form
|
39
|
+
)
|
40
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
41
|
+
.then(function(resData) {
|
42
|
+
if (resData.error) {
|
43
|
+
throw resData;
|
44
|
+
}
|
45
|
+
|
46
|
+
return callback();
|
47
|
+
})
|
48
|
+
.catch(function(err) {
|
49
|
+
log.error("changeArchivedStatus", err);
|
50
|
+
return callback(err);
|
51
|
+
});
|
52
|
+
|
53
|
+
return returnPromise;
|
54
|
+
};
|
55
|
+
};
|
@@ -13,16 +13,22 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction")
|
17
|
-
|
16
|
+
if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") {
|
17
|
+
callback = publish;
|
18
|
+
} else {
|
18
19
|
callback = function (err) {
|
19
|
-
if (err)
|
20
|
+
if (err) {
|
21
|
+
return rejectFunc(err);
|
22
|
+
}
|
20
23
|
resolveFunc();
|
21
24
|
};
|
22
25
|
}
|
23
26
|
}
|
24
27
|
|
25
|
-
if (utils.getType(publish) != "Boolean")
|
28
|
+
if (utils.getType(publish) != "Boolean") {
|
29
|
+
publish = false;
|
30
|
+
}
|
31
|
+
|
26
32
|
if (utils.getType(bio) != "String") {
|
27
33
|
bio = "";
|
28
34
|
publish = false;
|
@@ -48,10 +54,17 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
48
54
|
};
|
49
55
|
|
50
56
|
defaultFuncs
|
51
|
-
.post(
|
57
|
+
.post(
|
58
|
+
"https://www.facebook.com/api/graphql/",
|
59
|
+
ctx.jar,
|
60
|
+
form
|
61
|
+
)
|
52
62
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
53
63
|
.then(function (resData) {
|
54
|
-
if (resData.errors)
|
64
|
+
if (resData.errors) {
|
65
|
+
throw resData;
|
66
|
+
}
|
67
|
+
|
55
68
|
return callback();
|
56
69
|
})
|
57
70
|
.catch(function (err) {
|
@@ -14,17 +14,28 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
14
14
|
|
15
15
|
if (!callback) {
|
16
16
|
callback = function (err) {
|
17
|
-
if (err)
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
18
20
|
resolveFunc();
|
19
21
|
};
|
20
22
|
}
|
21
23
|
|
22
24
|
defaultFuncs
|
23
|
-
.post(
|
25
|
+
.post(
|
26
|
+
`https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`,
|
27
|
+
ctx.jar,
|
28
|
+
{
|
29
|
+
fbid: userID
|
30
|
+
}
|
31
|
+
)
|
24
32
|
.then(utils.saveCookies(ctx.jar))
|
25
33
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
26
34
|
.then(function (resData) {
|
27
|
-
if (resData.error)
|
35
|
+
if (resData.error) {
|
36
|
+
throw resData;
|
37
|
+
}
|
38
|
+
|
28
39
|
return callback();
|
29
40
|
})
|
30
41
|
.catch(function (err) {
|
@@ -4,7 +4,7 @@ var utils = require("../utils");
|
|
4
4
|
var log = require("npmlog");
|
5
5
|
var bluebird = require("bluebird");
|
6
6
|
|
7
|
-
module.exports = function
|
7
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
8
8
|
function handleUpload(image, callback) {
|
9
9
|
var uploads = [];
|
10
10
|
|
@@ -15,10 +15,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
15
15
|
|
16
16
|
uploads.push(
|
17
17
|
defaultFuncs
|
18
|
-
.postFormData(
|
18
|
+
.postFormData(
|
19
|
+
"https://upload.facebook.com/ajax/mercury/upload.php",
|
20
|
+
ctx.jar,
|
21
|
+
form,
|
22
|
+
{}
|
23
|
+
)
|
19
24
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
20
|
-
.then(function
|
21
|
-
if (resData.error)
|
25
|
+
.then(function(resData) {
|
26
|
+
if (resData.error) {
|
27
|
+
throw resData;
|
28
|
+
}
|
29
|
+
|
22
30
|
return resData.payload.metadata[0];
|
23
31
|
})
|
24
32
|
);
|
@@ -26,26 +34,36 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
26
34
|
// resolve all promises
|
27
35
|
bluebird
|
28
36
|
.all(uploads)
|
29
|
-
.then(
|
30
|
-
|
37
|
+
.then(function(resData) {
|
38
|
+
callback(null, resData);
|
39
|
+
})
|
40
|
+
.catch(function(err) {
|
31
41
|
log.error("handleUpload", err);
|
32
42
|
return callback(err);
|
33
43
|
});
|
34
44
|
}
|
35
45
|
|
36
46
|
return function changeGroupImage(image, threadID, callback) {
|
37
|
-
if (
|
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
|
+
}
|
38
54
|
|
39
|
-
var resolveFunc = function
|
40
|
-
var rejectFunc = function
|
55
|
+
var resolveFunc = function(){};
|
56
|
+
var rejectFunc = function(){};
|
41
57
|
var returnPromise = new Promise(function (resolve, reject) {
|
42
58
|
resolveFunc = resolve;
|
43
59
|
rejectFunc = reject;
|
44
60
|
});
|
45
61
|
|
46
62
|
if (!callback) {
|
47
|
-
callback = function
|
48
|
-
if (err)
|
63
|
+
callback = function(err) {
|
64
|
+
if (err) {
|
65
|
+
return rejectFunc(err);
|
66
|
+
}
|
49
67
|
resolveFunc();
|
50
68
|
};
|
51
69
|
}
|
@@ -80,8 +98,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
80
98
|
timestamp_time_passed: "0"
|
81
99
|
};
|
82
100
|
|
83
|
-
handleUpload(image, function
|
84
|
-
if (err)
|
101
|
+
handleUpload(image, function(err, payload) {
|
102
|
+
if (err) {
|
103
|
+
return callback(err);
|
104
|
+
}
|
85
105
|
|
86
106
|
form["thread_image_id"] = payload[0]["image_id"];
|
87
107
|
form["thread_id"] = threadID;
|
@@ -89,12 +109,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
89
109
|
defaultFuncs
|
90
110
|
.post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
|
91
111
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
92
|
-
.then(function
|
112
|
+
.then(function(resData) {
|
93
113
|
// check for errors here
|
94
|
-
|
114
|
+
|
115
|
+
if (resData.error) {
|
116
|
+
throw resData;
|
117
|
+
}
|
118
|
+
|
95
119
|
return callback();
|
96
120
|
})
|
97
|
-
.catch(function
|
121
|
+
.catch(function(err) {
|
98
122
|
log.error("changeGroupImage", err);
|
99
123
|
return callback(err);
|
100
124
|
});
|
@@ -0,0 +1,59 @@
|
|
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 changeNickname(nickname, threadID, participantID, callback) {
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
if (!callback) {
|
15
|
+
callback = function (err) {
|
16
|
+
if (err) {
|
17
|
+
return rejectFunc(err);
|
18
|
+
}
|
19
|
+
resolveFunc();
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
var 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
|
+
};
|
@@ -3,27 +3,34 @@
|
|
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 changeThreadColor(color, threadID, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
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
|
17
|
-
if (err)
|
16
|
+
callback = function(err) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
18
20
|
resolveFunc(err);
|
19
21
|
};
|
20
22
|
}
|
21
23
|
|
22
24
|
var validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
|
23
|
-
var colorList = Object.keys(api.threadColors).map(function
|
25
|
+
var colorList = Object.keys(api.threadColors).map(function(name) {
|
24
26
|
return api.threadColors[name];
|
25
27
|
});
|
26
|
-
if (!colorList.includes(validatedColor))
|
28
|
+
if (!colorList.includes(validatedColor)) {
|
29
|
+
throw {
|
30
|
+
error:
|
31
|
+
"The color you are trying to use is not a valid thread color. Use api.threadColors to find acceptable values."
|
32
|
+
};
|
33
|
+
}
|
27
34
|
|
28
35
|
var form = {
|
29
36
|
dpr: 1,
|
@@ -47,11 +54,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
47
54
|
defaultFuncs
|
48
55
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
49
56
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
50
|
-
.then(function
|
51
|
-
if (resData[resData.length - 1].error_results > 0)
|
57
|
+
.then(function(resData) {
|
58
|
+
if (resData[resData.length - 1].error_results > 0) {
|
59
|
+
throw resData[0].o0.errors;
|
60
|
+
}
|
61
|
+
|
52
62
|
return callback();
|
53
63
|
})
|
54
|
-
.catch(function
|
64
|
+
.catch(function(err) {
|
55
65
|
log.error("changeThreadColor", err);
|
56
66
|
return callback(err);
|
57
67
|
});
|
@@ -0,0 +1,55 @@
|
|
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 changeThreadEmoji(emoji, threadID, callback) {
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback) {
|
16
|
+
callback = function(err) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
20
|
+
resolveFunc();
|
21
|
+
};
|
22
|
+
}
|
23
|
+
var 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
|
+
};
|