@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/README.md
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
@cexy/hoonfca
|
|
2
|
-
|
|
3
|
-
A modern, fast, and actively maintained Facebook Chat API for Node.js.
|
|
4
|
-
Built for Messenger bots with improved stability, performance, and compatibility.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
📦 Installation
|
|
9
|
-
|
|
10
|
-
Install the package using npm:
|
|
11
|
-
|
|
12
|
-
npm install @cexy/rakibfca
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
🚀 Usage
|
|
17
|
-
|
|
18
|
-
const login = require("@cexy/rakibfca");
|
|
19
|
-
|
|
20
|
-
login(
|
|
21
|
-
{
|
|
22
|
-
appState: require("./appstate.json")
|
|
23
|
-
},
|
|
24
|
-
(err, api) => {
|
|
25
|
-
if (err) return console.error(err);
|
|
26
|
-
|
|
27
|
-
console.log("Logged in as:", api.getCurrentUserID());
|
|
28
|
-
|
|
29
|
-
api.listenMqtt((err, event) => {
|
|
30
|
-
if (err) return console.error(err);
|
|
31
|
-
|
|
32
|
-
console.log(event);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
✨ Features
|
|
40
|
-
|
|
41
|
-
- ⚡ Fast and lightweight
|
|
42
|
-
- 🔒 AppState login support
|
|
43
|
-
- 💬 Messenger API support
|
|
44
|
-
- 📩 MQTT listener
|
|
45
|
-
- 🛠️ Regular bug fixes
|
|
46
|
-
- 🚀 Performance improvements
|
|
47
|
-
- 📦 Easy integration with Node.js projects
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
📋 Requirements
|
|
52
|
-
|
|
53
|
-
- Node.js 20+
|
|
54
|
-
- npm 10+
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
📖 Installation Example
|
|
59
|
-
|
|
60
|
-
mkdir my-bot
|
|
61
|
-
cd my-bot
|
|
62
|
-
npm init -y
|
|
63
|
-
npm install @cexy/rakibfca
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
🤝 Contributing
|
|
68
|
-
|
|
69
|
-
Contributions, bug reports, and feature requests are always welcome.
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
📄 License
|
|
74
|
-
|
|
75
|
-
MIT License
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
👨💻 Author
|
|
80
|
-
|
|
81
|
-
Rakib Hasan
|
|
82
|
-
|
|
83
|
-
NPM: @cexy/hoonfca
|
package/replit.nix
DELETED
package/src/changeAvatar.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const utils = require("../utils");
|
|
4
|
-
const axios = require("axios"); // রিকোয়ার ওপরে নিয়ে আসা হলো পারফরম্যান্সের জন্য
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* It posts an image to a Facebook profile
|
|
8
|
-
*/
|
|
9
|
-
async function postImage(Api, BotID, form) {
|
|
10
|
-
const Data = await Api.httpPostFormData(
|
|
11
|
-
`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`,
|
|
12
|
-
form
|
|
13
|
-
);
|
|
14
|
-
return JSON.parse(Data.split("for (;;);")[1]);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
18
|
-
/* Changing the profile picture of the bot. */
|
|
19
|
-
return function changeAvt(link, caption, callback) {
|
|
20
|
-
let resolveFunc = () => {};
|
|
21
|
-
let rejectFunc = () => {};
|
|
22
|
-
const returnPromise = new Promise((resolve, reject) => {
|
|
23
|
-
resolveFunc = resolve;
|
|
24
|
-
rejectFunc = reject;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (!callback) {
|
|
28
|
-
callback = function(err, data) {
|
|
29
|
-
if (err) return rejectFunc(err);
|
|
30
|
-
resolveFunc(data);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// পুরো অ্যাসিনক্রোনাস ফ্লো-কে হ্যান্ডেল করার জন্য একটি IIFE async ফাংশন
|
|
35
|
-
(async () => {
|
|
36
|
-
try {
|
|
37
|
-
// ১. ইমেজ স্ট্রিম ফিচ করা
|
|
38
|
-
const response = await axios.get(link, { responseType: "stream" });
|
|
39
|
-
|
|
40
|
-
// ২. ফেসবুকে ইমেজ আপলোড করা
|
|
41
|
-
const uploadRes = await postImage(api, ctx.userID, { file: response.data });
|
|
42
|
-
if (uploadRes.error) {
|
|
43
|
-
throw new utils.CustomError({
|
|
44
|
-
error: uploadRes.error,
|
|
45
|
-
des: uploadRes.error.errorDescription
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ৩. গ্রাফকিউএল ফর্ম ডেটা রেডি করা
|
|
50
|
-
const form = {
|
|
51
|
-
av: ctx.userID,
|
|
52
|
-
fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
|
|
53
|
-
fb_api_caller_class: "RelayModern",
|
|
54
|
-
doc_id: "5066134240065849",
|
|
55
|
-
variables: JSON.stringify({
|
|
56
|
-
input: {
|
|
57
|
-
caption: caption || "",
|
|
58
|
-
existing_photo_id: uploadRes.payload.fbid,
|
|
59
|
-
expiration_time: null,
|
|
60
|
-
profile_id: ctx.userID,
|
|
61
|
-
profile_pic_method: "EXISTING",
|
|
62
|
-
profile_pic_source: "TIMELINE",
|
|
63
|
-
scaled_crop_rect: { height: 1, width: 1, x: 0, y: 0 },
|
|
64
|
-
skip_cropping: true,
|
|
65
|
-
actor_id: ctx.userID,
|
|
66
|
-
client_mutation_id: Math.round(Math.random() * 19).toString()
|
|
67
|
-
},
|
|
68
|
-
isPage: false,
|
|
69
|
-
isProfile: true,
|
|
70
|
-
scale: 3,
|
|
71
|
-
})
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// ৪. ফেসবুক মিউটেশন রিকোয়েস্ট পাঠানো
|
|
75
|
-
const resData = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form);
|
|
76
|
-
const checkedData = utils.parseAndCheckLogin(ctx, defaultFuncs)(resData);
|
|
77
|
-
|
|
78
|
-
if (checkedData.error) throw checkedData;
|
|
79
|
-
|
|
80
|
-
return callback(null, true);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
utils.error("changeAvt", err);
|
|
83
|
-
return callback(err);
|
|
84
|
-
}
|
|
85
|
-
})();
|
|
86
|
-
|
|
87
|
-
return returnPromise;
|
|
88
|
-
};
|
|
89
|
-
};
|
package/src/changeCover.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const utils = require("../utils");
|
|
4
|
-
|
|
5
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
return function changeCover(image, callback) {
|
|
7
|
-
let cb;
|
|
8
|
-
const rt = new Promise((resolve, reject) => {
|
|
9
|
-
cb = (error, url) => (error ? reject(error) : resolve(url));
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
if (typeof image === "function") {
|
|
13
|
-
callback = image;
|
|
14
|
-
image = null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (typeof callback === "function") {
|
|
18
|
-
cb = callback;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// ইমেজ রিডেবল স্ট্রিম কিনা তা চেক করা হচ্ছে
|
|
22
|
-
if (!utils.isReadableStream(image)) {
|
|
23
|
-
const error = "image should be a readable stream, not " + utils.getType(image);
|
|
24
|
-
utils.error("changeCover", error);
|
|
25
|
-
cb(error);
|
|
26
|
-
return rt;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// অ্যাসিনক্রোনাস কাজগুলো প্রপারলি হ্যান্ডেল করার জন্য IIFE async ফাংশন
|
|
30
|
-
(async () => {
|
|
31
|
-
try {
|
|
32
|
-
// ১. কভার ফটো ফেসবুকে আপলোড করা
|
|
33
|
-
const uploadRes = await defaultFuncs.postFormData(
|
|
34
|
-
"https://www.facebook.com/profile/picture/upload/",
|
|
35
|
-
ctx.jar,
|
|
36
|
-
{
|
|
37
|
-
profile_id: ctx.userID,
|
|
38
|
-
photo_source: 57,
|
|
39
|
-
av: ctx.userID,
|
|
40
|
-
file: image,
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const checkedUpload = utils.parseAndCheckLogin(ctx, defaultFuncs)(uploadRes);
|
|
45
|
-
if (checkedUpload.error || checkedUpload.errors || !checkedUpload.payload) {
|
|
46
|
-
throw checkedUpload;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ২. গ্রাফকিউএল মিউটেশন ভেরিয়েবল রেডি করা
|
|
50
|
-
const timestamp = Date.now();
|
|
51
|
-
const vari = {
|
|
52
|
-
input: {
|
|
53
|
-
attribution_id_v2: `ProfileCometCollectionRoot.react,comet.profile.collection.photos_by,unexpected,${timestamp},770083,,;ProfileCometCollectionRoot.react,comet.profile.collection.photos_albums,unexpected,${timestamp},470774,,;ProfileCometCollectionRoot.react,comet.profile.collection.photos,unexpected,${timestamp},94740,,;ProfileCometCollectionRoot.react,comet.profile.collection.saved_reels_on_profile,unexpected,${timestamp},89669,,;ProfileCometCollectionRoot.react,comet.profile.collection.reels_tab,unexpected,${timestamp},152201,,`,
|
|
54
|
-
cover_photo_id: checkedUpload.payload.fbid,
|
|
55
|
-
focus: { x: 0.5, y: 1 },
|
|
56
|
-
target_user_id: ctx.userID,
|
|
57
|
-
actor_id: ctx.userID,
|
|
58
|
-
client_mutation_id: Math.round(Math.random() * 19).toString(),
|
|
59
|
-
},
|
|
60
|
-
scale: 1,
|
|
61
|
-
contextualProfileContext: null,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// ৩. ফেসবুক গ্রাফকিউএল এন্ডপয়েন্টে কভার আপডেট রিকোয়েস্ট পাঠানো
|
|
65
|
-
const mutationRes = await defaultFuncs.post(
|
|
66
|
-
"https://www.facebook.com/api/graphql",
|
|
67
|
-
ctx.jar,
|
|
68
|
-
{
|
|
69
|
-
doc_id: 8247793861913071,
|
|
70
|
-
server_timestamps: true,
|
|
71
|
-
fb_api_req_friendly_name: "ProfileCometCoverPhotoUpdateMutation",
|
|
72
|
-
variables: JSON.stringify(vari),
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
const checkedMutation = utils.parseAndCheckLogin(ctx, defaultFuncs)(mutationRes);
|
|
77
|
-
if (checkedMutation.errors) {
|
|
78
|
-
throw checkedMutation;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// সফল হলে নতুন কভার ফটোর URL রিটার্ন করা হচ্ছে
|
|
82
|
-
const coverUrl = checkedMutation.data.user_update_cover_photo.user.cover_photo.photo.url;
|
|
83
|
-
return cb(null, coverUrl);
|
|
84
|
-
} catch (err) {
|
|
85
|
-
utils.error("changeCover", err);
|
|
86
|
-
return cb(err);
|
|
87
|
-
}
|
|
88
|
-
})();
|
|
89
|
-
|
|
90
|
-
return rt;
|
|
91
|
-
};
|
|
92
|
-
};
|
package/src/changeName.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const utils = require("../utils");
|
|
4
|
-
|
|
5
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
return function changeName(input, format, callback) {
|
|
7
|
-
let cb;
|
|
8
|
-
const rt = new Promise((resolve, reject) => {
|
|
9
|
-
cb = (error) => (error ? reject(error) : resolve());
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
// ইনপুট ওভারলোড হ্যান্ডেল করা হচ্ছে
|
|
13
|
-
if (typeof input === "function") {
|
|
14
|
-
callback = input;
|
|
15
|
-
input = null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (typeof format === "function") {
|
|
19
|
-
callback = format;
|
|
20
|
-
format = "complete";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (typeof callback === "function") {
|
|
24
|
-
cb = callback;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// টাইপ ভ্যালিডেশন
|
|
28
|
-
if (utils.getType(input) !== "Object") {
|
|
29
|
-
const error = "name must be an object, not " + utils.getType(input);
|
|
30
|
-
utils.error("changeName", error); // এখানে ওল্ড কোডের log বাগটি ফিক্স করা হয়েছে
|
|
31
|
-
cb(error);
|
|
32
|
-
return rt;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { first_name, middle_name = "", last_name } = input;
|
|
36
|
-
|
|
37
|
-
if (!first_name || !last_name) {
|
|
38
|
-
utils.error("changeName", "name is not be accepted");
|
|
39
|
-
cb("name is not be accepted");
|
|
40
|
-
return rt;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// ফরম্যাট অনুযায়ী ফুল নেম জেনারেট করা
|
|
44
|
-
const middlePart = middle_name !== "" ? middle_name + " " : "";
|
|
45
|
-
let full_name = "";
|
|
46
|
-
|
|
47
|
-
if (format === "complete") {
|
|
48
|
-
full_name = `${last_name} ${middlePart}${first_name}`;
|
|
49
|
-
} else if (format === "standard") {
|
|
50
|
-
full_name = `${last_name} ${first_name}`;
|
|
51
|
-
} else if (format === "reversed") {
|
|
52
|
-
full_name = `${first_name} ${middlePart}${last_name}`;
|
|
53
|
-
} else {
|
|
54
|
-
full_name = `${last_name} ${middlePart}${first_name}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const form = {
|
|
58
|
-
fb_api_caller_class: "RelayModern",
|
|
59
|
-
fb_api_req_friendly_name: "useFXIMUpdateNameMutation",
|
|
60
|
-
variables: JSON.stringify({
|
|
61
|
-
client_mutation_id: utils.getGUID(),
|
|
62
|
-
family_device_id: "device_id_fetch_datr",
|
|
63
|
-
identity_ids: [ctx.userID],
|
|
64
|
-
full_name,
|
|
65
|
-
first_name,
|
|
66
|
-
middle_name,
|
|
67
|
-
last_name,
|
|
68
|
-
interface: "FB_WEB",
|
|
69
|
-
}),
|
|
70
|
-
server_timestamps: true,
|
|
71
|
-
doc_id: "5763510853763960",
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// অ্যাসিনক্রোনাস রিকোয়েস্ট হ্যান্ডেল করার জন্য IIFE async ফাংশন
|
|
75
|
-
(async () => {
|
|
76
|
-
try {
|
|
77
|
-
const res = await defaultFuncs.post(
|
|
78
|
-
"https://accountscenter.facebook.com/api/graphql/",
|
|
79
|
-
ctx.jar,
|
|
80
|
-
form,
|
|
81
|
-
null,
|
|
82
|
-
null,
|
|
83
|
-
{
|
|
84
|
-
Origin: "https://accountscenter.facebook.com",
|
|
85
|
-
Referer: `https://accountscenter.facebook.com/profiles/${ctx.userID}/name`,
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const checkedData = utils.parseAndCheckLogin(ctx, defaultFuncs)(res);
|
|
90
|
-
|
|
91
|
-
if (checkedData.errors) {
|
|
92
|
-
throw checkedData;
|
|
93
|
-
} else if (checkedData.data?.fxim_update_identity_name?.error) {
|
|
94
|
-
throw checkedData.data.fxim_update_identity_name.error;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return cb();
|
|
98
|
-
} catch (err) {
|
|
99
|
-
utils.error("changeName", err);
|
|
100
|
-
return cb(err);
|
|
101
|
-
}
|
|
102
|
-
})();
|
|
103
|
-
|
|
104
|
-
return rt;
|
|
105
|
-
};
|
|
106
|
-
};
|
package/src/changeUsername.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var utils = require('../utils');
|
|
4
|
-
|
|
5
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
return function changeUsername(username, callback) {
|
|
7
|
-
var resolveFunc = function () {};
|
|
8
|
-
var rejectFunc = function () {};
|
|
9
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
|
10
|
-
resolveFunc = resolve;
|
|
11
|
-
rejectFunc = reject;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// কলব্যাক ডিফাইন করা না থাকলে প্রমিজ হ্যান্ডলার সেট করা হচ্ছে
|
|
15
|
-
if (typeof callback !== 'function') {
|
|
16
|
-
callback = function (err, data) {
|
|
17
|
-
if (err) {
|
|
18
|
-
return rejectFunc(err);
|
|
19
|
-
}
|
|
20
|
-
resolveFunc(data);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// প্রথম প্যারামিটার হিসেবে ভুলবশত ফাংশন পাস করলে তা হ্যান্ডেল করা
|
|
25
|
-
if (typeof username === 'function') {
|
|
26
|
-
var errorMsg = 'username must be a string, and not ' + utils.getType(username);
|
|
27
|
-
utils.error('changeUsername', errorMsg);
|
|
28
|
-
return username({ error: errorMsg });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (typeof username !== 'string') {
|
|
32
|
-
var errorMsg = 'username must be a string, and not ' + utils.getType(username);
|
|
33
|
-
utils.error('changeUsername', errorMsg);
|
|
34
|
-
return callback({ error: errorMsg });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var form = {
|
|
38
|
-
fb_api_caller_class: 'RelayModern',
|
|
39
|
-
fb_api_req_friendly_name: 'useFXIMUpdateUsernameMutation',
|
|
40
|
-
variables: JSON.stringify({
|
|
41
|
-
client_mutation_id: utils.getGUID(),
|
|
42
|
-
family_device_id: "device_id_fetch_datr",
|
|
43
|
-
identity_ids: [ctx.userID.toString()],
|
|
44
|
-
username: username,
|
|
45
|
-
interface: "FB_WEB"
|
|
46
|
-
}),
|
|
47
|
-
server_timestamps: true,
|
|
48
|
-
doc_id: "5737739449613305" // doc_id সাধারণত স্ট্রিং হিসেবে নিরাপদ
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
defaultFuncs
|
|
52
|
-
.post('https://accountscenter.facebook.com/api/graphql/', ctx.jar, form, null, null, {
|
|
53
|
-
Origin: 'https://accountscenter.facebook.com',
|
|
54
|
-
Referer: `https://accountscenter.facebook.com/profiles/${ctx.userID}/username/?entrypoint=fb_account_center`
|
|
55
|
-
})
|
|
56
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
57
|
-
.then(function (res) {
|
|
58
|
-
if (!res) {
|
|
59
|
-
throw { error: "changeUsername returned empty response." };
|
|
60
|
-
}
|
|
61
|
-
if (res.errors) {
|
|
62
|
-
throw res;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// রেসপন্স ডাটার ভেতরের এরর অবজেক্ট সেফলি চেক করা
|
|
66
|
-
var updateResult = res.data && res.data.fxim_update_identity_username;
|
|
67
|
-
if (updateResult && updateResult.error) {
|
|
68
|
-
throw updateResult.error;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return callback(null, res);
|
|
72
|
-
})
|
|
73
|
-
.catch(function (err) {
|
|
74
|
-
utils.error('changeUsername', err);
|
|
75
|
-
return callback(err);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return returnPromise;
|
|
79
|
-
};
|
|
80
|
-
};
|
package/src/createCommentPost.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const utils = require("../utils.js");
|
|
4
|
-
|
|
5
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
|
|
7
|
-
// অ্যাটাচমেন্ট আপলোড করার ফাংশন
|
|
8
|
-
function handleUpload(msg, form) {
|
|
9
|
-
if (!msg.attachments || msg.attachments.length === 0) return Promise.resolve();
|
|
10
|
-
|
|
11
|
-
const uploads = msg.attachments.map(item => {
|
|
12
|
-
if (!utils.isReadableStream(item)) {
|
|
13
|
-
return Promise.reject({ error: "image should be a readable stream and not " + utils.getType(item) });
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return defaultFuncs
|
|
17
|
-
.postFormData("https://www.facebook.com/ajax/ufi/upload/", ctx.jar, {
|
|
18
|
-
profile_id: ctx.userID,
|
|
19
|
-
source: 19,
|
|
20
|
-
target_id: ctx.userID,
|
|
21
|
-
file: item
|
|
22
|
-
})
|
|
23
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
24
|
-
.then(res => {
|
|
25
|
-
if (res.errors || res.error || !res.payload) throw res;
|
|
26
|
-
return { media: { id: res.payload.fbid } };
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return Promise.all(uploads).then(results => {
|
|
31
|
-
results.forEach(item => form.input.attachments.push(item));
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function handleURL(msg, form) {
|
|
36
|
-
if (typeof msg.url === "string") {
|
|
37
|
-
form.input.attachments = [{ link: { external: { url: msg.url } } }];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function handleMentions(msg, form) {
|
|
42
|
-
if (!msg.mentions) return;
|
|
43
|
-
for (const item of msg.mentions) {
|
|
44
|
-
const { tag, id, fromIndex } = item;
|
|
45
|
-
|
|
46
|
-
if (typeof tag !== "string") throw new Error("Mention tag must be string");
|
|
47
|
-
if (!id) throw new Error("id must be string");
|
|
48
|
-
|
|
49
|
-
const offset = msg.body.indexOf(tag, fromIndex || 0);
|
|
50
|
-
if (offset < 0) throw new Error(`Mention for "${tag}" not found in message string.`);
|
|
51
|
-
|
|
52
|
-
form.input.message.ranges.push({
|
|
53
|
-
entity: { id },
|
|
54
|
-
length: tag.length,
|
|
55
|
-
offset
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function handleSticker(msg, form) {
|
|
61
|
-
if (msg.sticker) {
|
|
62
|
-
form.input.attachments = [{ media: { id: msg.sticker } }];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// গ্রাফকিউএল রিকোয়েস্ট সাবমিট করার ফাংশন
|
|
67
|
-
function createContent(form) {
|
|
68
|
-
return defaultFuncs
|
|
69
|
-
.post("https://www.facebook.com/api/graphql/", ctx.jar, {
|
|
70
|
-
fb_api_caller_class: "RelayModern",
|
|
71
|
-
fb_api_req_friendly_name: "useCometUFICreateCommentMutation",
|
|
72
|
-
variables: JSON.stringify(form),
|
|
73
|
-
server_timestamps: true,
|
|
74
|
-
doc_id: 6993516810709754
|
|
75
|
-
})
|
|
76
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
77
|
-
.then(res => {
|
|
78
|
-
if (res.errors) throw res;
|
|
79
|
-
const node = res.data.comment_create;
|
|
80
|
-
return {
|
|
81
|
-
id: node.feedback_comment_edge.node.id,
|
|
82
|
-
url: node.feedback_comment_edge.node.feedback.url,
|
|
83
|
-
count: node.feedback.total_comment_count
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return function createCommentPost(msg, postID, callback, replyCommentID) {
|
|
89
|
-
let cb;
|
|
90
|
-
const returnPromise = new Promise((resolve, reject) => {
|
|
91
|
-
cb = (error, info) => (info ? resolve(info) : reject(error));
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// ইনপুট ভ্যালিডেশন
|
|
95
|
-
if (typeof msg === "function") {
|
|
96
|
-
const error = "Message must be a string or object!!";
|
|
97
|
-
utils.error("createCommentPost", error);
|
|
98
|
-
msg(error);
|
|
99
|
-
return returnPromise;
|
|
100
|
-
}
|
|
101
|
-
if (typeof postID === "function") {
|
|
102
|
-
const error = "postID must be a string!!";
|
|
103
|
-
utils.error("createCommentPost", error);
|
|
104
|
-
postID(error);
|
|
105
|
-
return returnPromise;
|
|
106
|
-
}
|
|
107
|
-
if (typeof callback === "string") {
|
|
108
|
-
replyCommentID = callback;
|
|
109
|
-
callback = null;
|
|
110
|
-
}
|
|
111
|
-
if (typeof callback === "function") {
|
|
112
|
-
cb = callback;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const messageType = utils.getType(msg);
|
|
116
|
-
|
|
117
|
-
if (messageType === "String") {
|
|
118
|
-
msg = {
|
|
119
|
-
body: msg,
|
|
120
|
-
attachments: [],
|
|
121
|
-
mentions: [],
|
|
122
|
-
sticker: null,
|
|
123
|
-
url: null
|
|
124
|
-
};
|
|
125
|
-
} else if (messageType === "Object") {
|
|
126
|
-
msg.mentions = msg.mentions ? (Array.isArray(msg.mentions) ? msg.mentions : [msg.mentions]) : [];
|
|
127
|
-
msg.attachments = msg.attachments ? (Array.isArray(msg.attachments) ? msg.attachments : [msg.attachments]) : [];
|
|
128
|
-
if (isNaN(msg.sticker)) msg.sticker = null;
|
|
129
|
-
if (msg.body && typeof msg.body === "object") msg.body = JSON.stringify(msg.body);
|
|
130
|
-
if (!msg.body) msg.body = "";
|
|
131
|
-
} else {
|
|
132
|
-
const error = "Message must be a string or object!!";
|
|
133
|
-
utils.error("createCommentPost", error);
|
|
134
|
-
cb(error);
|
|
135
|
-
return returnPromise;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (typeof postID !== "string") {
|
|
139
|
-
const error = "postID must be a string!!";
|
|
140
|
-
utils.error("createCommentPost", error);
|
|
141
|
-
cb(error);
|
|
142
|
-
return returnPromise;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (typeof replyCommentID !== "string") replyCommentID = null;
|
|
146
|
-
|
|
147
|
-
// ফর্ম অবজেক্ট ডিক্লেয়ারেশন
|
|
148
|
-
const form = {
|
|
149
|
-
feedLocation: "NEWSFEED",
|
|
150
|
-
feedbackSource: 1,
|
|
151
|
-
groupID: null,
|
|
152
|
-
input: {
|
|
153
|
-
client_mutation_id: Math.round(Math.random() * 19).toString(),
|
|
154
|
-
actor_id: ctx.userID,
|
|
155
|
-
attachments: [],
|
|
156
|
-
feedback_id: Buffer.from("feedback:" + postID).toString("base64"),
|
|
157
|
-
formatting_style: null,
|
|
158
|
-
message: {
|
|
159
|
-
ranges: [],
|
|
160
|
-
text: msg.body
|
|
161
|
-
},
|
|
162
|
-
reply_comment_parent_fbid: replyCommentID
|
|
163
|
-
? (isNaN(replyCommentID) ? replyCommentID : Buffer.from("comment:" + postID + "_" + replyCommentID).toString("base64"))
|
|
164
|
-
: null,
|
|
165
|
-
reply_target_clicked: !!replyCommentID,
|
|
166
|
-
attribution_id_v2: "CometHomeRoot.react,comet.home,via_cold_start," + Date.now() + ",156248,4748854339,,",
|
|
167
|
-
vod_video_timestamp: null,
|
|
168
|
-
feedback_referrer: "/",
|
|
169
|
-
is_tracking_encrypted: true,
|
|
170
|
-
tracking: [],
|
|
171
|
-
feedback_source: "NEWS_FEED",
|
|
172
|
-
idempotence_token: "client:" + utils.getGUID(),
|
|
173
|
-
session_id: utils.getGUID()
|
|
174
|
-
},
|
|
175
|
-
inviteShortLinkKey: null,
|
|
176
|
-
renderLocation: null,
|
|
177
|
-
scale: 1,
|
|
178
|
-
useDefaultActor: false,
|
|
179
|
-
focusCommentID: null
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// প্রমিজ চেইন এক্সিকিউশন
|
|
183
|
-
handleUpload(msg, form)
|
|
184
|
-
.then(() => handleURL(msg, form))
|
|
185
|
-
.then(() => handleMentions(msg, form))
|
|
186
|
-
.then(() => handleSticker(msg, form))
|
|
187
|
-
.then(() => createContent(form))
|
|
188
|
-
.then(info => cb(null, info))
|
|
189
|
-
.catch(err => {
|
|
190
|
-
utils.error("createCommentPost", err);
|
|
191
|
-
return cb(err); // বাগ ফিক্স করা হয়েছে
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
return returnPromise;
|
|
195
|
-
};
|
|
196
|
-
};
|