rapido-fca 0.0.1 → 0.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.
Files changed (81) hide show
  1. package/index.js +415 -419
  2. package/package.json +1 -1
  3. package/readme.md +39 -237
  4. package/src/addExternalModule.js +23 -19
  5. package/src/addUserToGroup.js +97 -99
  6. package/src/changeAdminStatus.js +62 -86
  7. package/src/changeArchivedStatus.js +49 -49
  8. package/src/changeAvatar.js +108 -118
  9. package/src/changeBio.js +64 -63
  10. package/src/changeBlockedStatus.js +38 -40
  11. package/src/changeGroupImage.js +126 -129
  12. package/src/changeNickname.js +49 -49
  13. package/src/changeThreadColor.js +53 -53
  14. package/src/changeThreadEmoji.js +45 -45
  15. package/src/createNewGroup.js +72 -74
  16. package/src/createPoll.js +59 -59
  17. package/src/deleteMessage.js +50 -50
  18. package/src/deleteThread.js +50 -50
  19. package/src/editMessage.js +49 -51
  20. package/src/forwardAttachment.js +54 -54
  21. package/src/getCurrentUserID.js +3 -3
  22. package/src/getEmojiUrl.js +17 -17
  23. package/src/getFriendsList.js +67 -67
  24. package/src/getMessage.js +767 -806
  25. package/src/getThreadHistory.js +642 -656
  26. package/src/getThreadInfo.js +1 -1
  27. package/src/getThreadList.js +227 -199
  28. package/src/getThreadPictures.js +71 -51
  29. package/src/getUserID.js +58 -53
  30. package/src/getUserInfo.js +60 -52
  31. package/src/handleFriendRequest.js +65 -41
  32. package/src/handleMessageRequest.js +60 -42
  33. package/src/httpGet.js +57 -49
  34. package/src/httpPost.js +57 -48
  35. package/src/httpPostFormData.js +63 -0
  36. package/src/listenMqtt.js +895 -827
  37. package/src/logout.js +61 -61
  38. package/src/markAsDelivered.js +53 -42
  39. package/src/markAsRead.js +69 -59
  40. package/src/markAsReadAll.js +42 -32
  41. package/src/markAsSeen.js +54 -43
  42. package/src/muteThread.js +47 -40
  43. package/src/refreshFb_dtsg.js +69 -77
  44. package/src/removeUserFromGroup.js +67 -67
  45. package/src/resolvePhotoUrl.js +34 -34
  46. package/src/searchForThread.js +43 -43
  47. package/src/sendMessage.js +228 -80
  48. package/src/sendTypingIndicator.js +88 -86
  49. package/src/setMessageReaction.js +109 -110
  50. package/src/setPostReaction.js +87 -90
  51. package/src/setTitle.js +72 -76
  52. package/src/threadColors.js +121 -121
  53. package/src/unfriend.js +43 -43
  54. package/src/unsendMessage.js +38 -34
  55. package/src/uploadAttachment.js +81 -79
  56. package/utils.js +1401 -2732
  57. package/src/changeAvatarV2.js +0 -86
  58. package/src/changeAvt.js +0 -85
  59. package/src/changeBlockedStatusMqtt.js +0 -80
  60. package/src/changeCover.js +0 -72
  61. package/src/changeName.js +0 -79
  62. package/src/changeUsername.js +0 -59
  63. package/src/createCommentPost.js +0 -230
  64. package/src/createPost.js +0 -276
  65. package/src/editMessageOld.js +0 -67
  66. package/src/follow.js +0 -74
  67. package/src/getAccess.js +0 -112
  68. package/src/getAvatarUser.js +0 -78
  69. package/src/getRegion.js +0 -7
  70. package/src/getThreadHistoryDeprecated.js +0 -71
  71. package/src/getThreadInfoDeprecated.js +0 -56
  72. package/src/getThreadListDeprecated.js +0 -46
  73. package/src/getUID.js +0 -119
  74. package/src/searchStickers.js +0 -53
  75. package/src/sendMessageMqtt.js +0 -322
  76. package/src/sendTypingIndicatorV2.js +0 -28
  77. package/src/setMessageReactionMqtt.js +0 -62
  78. package/src/setStoryReaction.js +0 -64
  79. package/src/shareContact.js +0 -110
  80. package/src/shareLink.js +0 -59
  81. package/src/stopListenMqtt.js +0 -23
@@ -1,86 +0,0 @@
1
-
2
- "use strict";
3
-
4
- var utils = require("../utils");
5
- // @NethWs3Dev
6
- /**
7
- * It posts an image to a Facebook profile
8
- * @param Api - The API object
9
- * @param BotID - The ID of the bot you want to post the image to.
10
- * @param form - The form data that you want to send.
11
- * @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
12
- * {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
13
- */
14
- async function postImage(Api, BotID, form) {
15
- var Data = await Api.httpPostFormData(`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`, form);
16
- return JSON.parse(Data.split("for (;;);")[1]);
17
- }
18
-
19
- module.exports = function(defaultFuncs, api, ctx) {
20
- /* Changing the profile picture of the bot. */
21
- return function changeAvt(link, caption, callback) {
22
- var resolveFunc = function() {};
23
- var rejectFunc = function() {};
24
- var returnPromise = new Promise(function(resolve, reject) {
25
- resolveFunc = resolve;
26
- rejectFunc = reject;
27
- });
28
-
29
- if (!callback) {
30
- callback = function(err, data) {
31
- if (err) return rejectFunc(err);
32
- resolveFunc(data);
33
- };
34
- }
35
- try {
36
- var Fetch = require('axios')
37
- Fetch.get(link, { responseType: "stream" }).then(data => {
38
- postImage(api, ctx.userID, { file: data.data }).then(data => {
39
- if (data.error) throw new Error({ error: data.error, des: data.error.errorDescription });
40
- var form = {
41
- av: ctx.userID,
42
- fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
43
- fb_api_caller_class: "RelayModern",
44
- doc_id: "5066134240065849",
45
- variables: JSON.stringify({
46
- input: {
47
- caption: (caption || ""),
48
- existing_photo_id: data.payload.fbid,
49
- expiration_time: null,
50
- profile_id: ctx.userID,
51
- profile_pic_method: "EXISTING",
52
- profile_pic_source: "TIMELINE",
53
- scaled_crop_rect: {
54
- height: 1,
55
- width: 1,
56
- x: 0,
57
- y: 0
58
- },
59
- skip_cropping: true,
60
- actor_id: ctx.userID,
61
- client_mutation_id: Math.round(Math.random() * 19).toString()
62
- },
63
- isPage: false,
64
- isProfile: true,
65
- scale: 3,
66
- })
67
- };
68
- defaultFuncs
69
- .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
70
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
71
- .then(function(resData) {
72
- if (resData.error) throw resData;
73
- else return callback(null,true)
74
- })
75
- .catch(function(err) {
76
- return callback(err);
77
- });
78
- })
79
- })
80
- }
81
- catch (e) {
82
- throw e;
83
- }
84
- return returnPromise;
85
- };
86
- };
package/src/changeAvt.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
- /**
6
- * It posts an image to a Facebook profile
7
- * @param Api - The API object
8
- * @param BotID - The ID of the bot you want to post the image to.
9
- * @param form - The form data that you want to send.
10
- * @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
11
- * {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
12
- */
13
- async function postImage(Api,BotID,form) {
14
- var Data = await Api.httpPostFormData(`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`, form);
15
- return JSON.parse(Data.split("for (;;);")[1]);
16
- }
17
-
18
- module.exports = function(defaultFuncs, api, ctx) {
19
- /* Changing the profile picture of the bot. */
20
- return function changeAvt(link, caption, callback) {
21
- var resolveFunc = function() {};
22
- var rejectFunc = function() {};
23
- var returnPromise = new Promise(function(resolve, reject) {
24
- resolveFunc = resolve;
25
- rejectFunc = reject;
26
- });
27
-
28
- if (!callback) {
29
- callback = function(err, data) {
30
- if (err) return rejectFunc(err);
31
- resolveFunc(data);
32
- };
33
- }
34
- try {
35
- var Fetch = require('axios')
36
- Fetch.get(link, { responseType: "stream" }).then(data => {
37
- postImage(api, ctx.userID, { file: data.data }).then(data => {
38
- if (data.error) throw new Error({ error: data.error, des: data.error.errorDescription });
39
- var form = {
40
- av: ctx.userID,
41
- fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
42
- fb_api_caller_class: "RelayModern",
43
- doc_id: "5066134240065849",
44
- variables: JSON.stringify({
45
- input: {
46
- caption: (caption || ""),
47
- existing_photo_id: data.payload.fbid,
48
- expiration_time: null,
49
- profile_id: ctx.userID,
50
- profile_pic_method: "EXISTING",
51
- profile_pic_source: "TIMELINE",
52
- scaled_crop_rect: {
53
- height: 1,
54
- width: 1,
55
- x: 0,
56
- y: 0
57
- },
58
- skip_cropping: true,
59
- actor_id: ctx.userID,
60
- client_mutation_id: Math.round(Math.random() * 19).toString()
61
- },
62
- isPage: false,
63
- isProfile: true,
64
- scale: 3,
65
- })
66
- };
67
- defaultFuncs
68
- .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
69
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
70
- .then(function(resData) {
71
- if (resData.error) throw resData;
72
- else return callback(null,true)
73
- })
74
- .catch(function(err) {
75
- return callback(err);
76
- });
77
- })
78
- })
79
- }
80
- catch (e) {
81
- throw e;
82
- }
83
- return returnPromise;
84
- };
85
- };
@@ -1,80 +0,0 @@
1
-
2
- 'use strict';
3
-
4
- const { generateOfflineThreadingID, getCurrentTimestamp, getGUID } = require('../utils.js');
5
-
6
- function isCallable(func) {
7
- try {
8
- Reflect.apply(func, null, []);
9
- return true;
10
- } catch (error) {
11
- return false;
12
- }
13
- }
14
-
15
- module.exports = function (defaultFuncs, api, ctx) {
16
- return function changeBlockedStatusMqtt(userID, status, type, callback) {
17
- if (!ctx.mqttClient) {
18
- throw new Error('Not connected to MQTT');
19
- }
20
-
21
- ctx.wsReqNumber += 1;
22
- ctx.wsTaskNumber += 1;
23
-
24
- const label = '334';
25
- let userBlockAction = 0;
26
-
27
- switch (type) {
28
- case 'messenger':
29
- if (status) {
30
- userBlockAction = 1; // Block
31
- } else {
32
- userBlockAction = 0; // Unblock
33
- }
34
- break;
35
- case 'facebook':
36
- if (status) {
37
- userBlockAction = 3; // Block
38
- } else {
39
- userBlockAction = 2; // Unblock
40
- }
41
- break;
42
- default:
43
- throw new Error('Invalid type');
44
- }
45
-
46
- const taskPayload = {
47
- blockee_id: userID,
48
- request_id: getGUID(),
49
- user_block_action: userBlockAction,
50
- };
51
-
52
- const payload = JSON.stringify(taskPayload);
53
- const version = '25393437286970779';
54
-
55
- const task = {
56
- failure_count: null,
57
- label: label,
58
- payload: payload,
59
- queue_name: 'native_sync_block',
60
- task_id: ctx.wsTaskNumber,
61
- };
62
-
63
- const content = {
64
- app_id: '2220391788200892',
65
- payload: JSON.stringify({
66
- tasks: [task],
67
- epoch_id: parseInt(generateOfflineThreadingID()),
68
- version_id: version,
69
- }),
70
- request_id: ctx.wsReqNumber,
71
- type: 3,
72
- };
73
-
74
- if (isCallable(callback)) {
75
- ctx.reqCallbacks[ctx.wsReqNumber] = callback;
76
- }
77
-
78
- ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
79
- };
80
- };
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('../utils');
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- return function changeCover(image, callback) {
7
- var cb;
8
- var rt = new Promise(function (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
- if (typeof callback == 'function') cb = callback;
17
- if (!utils.isReadableStream(image)) {
18
- var error = 'image should be a readable stream, not ' + utils.getType(image);
19
- console.error('changeCover', error);
20
- cb(error);
21
- }
22
- else {
23
- defaultFuncs
24
- .postFormData('https://www.facebook.com/profile/picture/upload/', ctx.jar, {
25
- profile_id: ctx.userID,
26
- photo_source: 57,
27
- av: ctx.userID,
28
- file: image
29
- })
30
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
31
- .then(function (res) {
32
- if (res.error || res.errors || !res.payload)
33
- throw res;
34
-
35
- var vari = {
36
- input: {
37
- attribution_id_v2: `ProfileCometCollectionRoot.react,comet.profile.collection.photos_by,unexpected,${Date.now()},770083,,;ProfileCometCollectionRoot.react,comet.profile.collection.photos_albums,unexpected,${Date.now()},470774,,;ProfileCometCollectionRoot.react,comet.profile.collection.photos,unexpected,${Date.now()},94740,,;ProfileCometCollectionRoot.react,comet.profile.collection.saved_reels_on_profile,unexpected,${Date.now()},89669,,;ProfileCometCollectionRoot.react,comet.profile.collection.reels_tab,unexpected,${Date.now()},152201,,`,
38
- cover_photo_id: res.payload.fbid,
39
- focus: {
40
- x: 0.5,
41
- y: 1
42
- },
43
- target_user_id: ctx.userID,
44
- actor_id: ctx.userID,
45
- client_mutation_id: Math.round(Math.random() * 19).toString()
46
- },
47
- scale: 1,
48
- contextualProfileContext: null
49
- }
50
- return defaultFuncs
51
- .post('https://www.facebook.com/api/graphql', ctx.jar, {
52
- doc_id: 8247793861913071,
53
- server_timestamps: true,
54
- fb_api_req_friendly_name: 'ProfileCometCoverPhotoUpdateMutation',
55
- variables: JSON.stringify(vari)
56
- })
57
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
58
- })
59
- .then(function (res) {
60
- if (res.errors)
61
- throw res;
62
- return cb(null, res.data.user_update_cover_photo.user.cover_photo.photo.url);
63
- })
64
- .catch(function (err) {
65
- console.error('changeCover', err);
66
- return cb(err);
67
- });
68
- }
69
-
70
- return rt;
71
- }
72
- }
package/src/changeName.js DELETED
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- var utils = require('./../utils.js');
4
- var log = require('npmlog');
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function changeName(input, format, callback) {
8
- var cb;
9
- var rt = new Promise(function (resolve, reject) {
10
- cb = error => error ? reject(error) : resolve();
11
- });
12
-
13
- if (typeof input == 'function') {
14
- callback = input;
15
- input = null;
16
- }
17
- if (typeof format == 'function') {
18
- callback = format;
19
- format = 'complete';
20
- }
21
- if (typeof callback == 'function') cb = callback;
22
- if (utils.getType(input) != 'Object') {
23
- var error = 'name must be an object, not ' + utils.getType(input);
24
- log('changeName', error);
25
- return cb(error);
26
- }
27
-
28
- var { first_name, middle_name, last_name } = input;
29
- if (!first_name || !last_name) {
30
- console.error('changeName', 'name is not be accepted');
31
- return cb('name is not be accepted');
32
- }
33
-
34
- middle_name = middle_name || '';
35
-
36
- var full_name =
37
- format == 'complete' ? last_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + first_name :
38
- format == 'standard' ? last_name + ' ' + first_name :
39
- format == 'reversed' ? first_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + last_name :
40
- last_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + first_name;
41
-
42
- var form = {
43
- fb_api_caller_class: 'RelayModern',
44
- fb_api_req_friendly_name: 'useFXIMUpdateNameMutation',
45
- variables: JSON.stringify({
46
- client_mutation_id: utils.getGUID(),
47
- family_device_id: "device_id_fetch_datr",
48
- identity_ids: [ctx.userID],
49
- full_name,
50
- first_name,
51
- middle_name,
52
- last_name,
53
- interface: 'FB_WEB'
54
- }),
55
- server_timestamps: true,
56
- doc_id: '5763510853763960'
57
- }
58
-
59
- defaultFuncs
60
- .post('https://accountscenter.facebook.com/api/graphql/', ctx.jar, form, null, null, {
61
- Origin: 'https://accountscenter.facebook.com',
62
- Referer: `https://accountscenter.facebook.com/profiles/${ctx.userID}/name`
63
- })
64
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
65
- .then(function (res) {
66
- if (res.errors)
67
- throw res;
68
- else if (res.data.fxim_update_identity_name.error)
69
- throw res.data.fxim_update_identity_name.error;
70
- return cb();
71
- })
72
- .catch(function (err) {
73
- console.error('changeName', err);
74
- return cb(err);
75
- });
76
-
77
- return rt;
78
- }
79
- }
@@ -1,59 +0,0 @@
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 changeUsername(username, callback) {
8
- var cb;
9
- var rt = new Promise(function (resolve, reject) {
10
- cb = (error, info) => info ? resolve(info) : reject(error);
11
- });
12
-
13
- if (typeof username == 'function') {
14
- var error = 'username must be a string, and not ' + utils.getType(username);
15
- console.error('changeUsername', error);
16
- return username(error);
17
- }
18
- if (typeof callback == 'function') cb = callback;
19
- if (typeof username != 'string') {
20
- var error = 'username must be a string, and not ' + utils.getType(username);
21
- console.error('changeUsername', error);
22
- return cb(error);
23
- }
24
-
25
- var form = {
26
- fb_api_caller_class: 'RelayModern',
27
- fb_api_req_friendly_name: 'useFXIMUpdateUsernameMutation',
28
- variables: JSON.stringify({
29
- client_mutation_id: utils.getGUID(),
30
- family_device_id: "device_id_fetch_datr",
31
- identity_ids: [ctx.userID],
32
- username,
33
- interface: "FB_WEB"
34
- }),
35
- server_timestamps: true,
36
- doc_id: 5737739449613305
37
- }
38
-
39
- defaultFuncs
40
- .post('https://accountscenter.facebook.com/api/graphql/', ctx.jar, form, null, null, {
41
- Origin: 'https://accountscenter.facebook.com',
42
- Referer: `https://accountscenter.facebook.com/profiles/${ctx.userID}/username/?entrypoint=fb_account_center`
43
- })
44
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
45
- .then(function (res) {
46
- if (res.errors)
47
- throw res;
48
- else if (res.data.fxim_update_identity_username.error)
49
- throw res.data.fxim_update_identity_username.error;
50
- return cb();
51
- })
52
- .catch(function (err) {
53
- console.error('changeUsername', err);
54
- return cb(err);
55
- });
56
-
57
- return rt;
58
- }
59
- }
@@ -1,230 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('../utils.js');
4
- var log = require('npmlog');
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- function handleUpload(msg, form) {
8
- var cb;
9
- var uploads = [];
10
- var returnPromise = new Promise(function (resolve, reject) {
11
- cb = error => error ? reject(error) : resolve();
12
- });
13
-
14
- for (let item of msg.attachments) {
15
- if (!utils.isReadableStream(item))
16
- return cb({ error: 'image should be a readable stream and not ' + utils.getType(image) });
17
-
18
- var httpData = defaultFuncs
19
- .postFormData('https://www.facebook.com/ajax/ufi/upload/', ctx.jar, {
20
- profile_id: ctx.userID,
21
- source: 19,
22
- target_id: ctx.userID,
23
- file: item
24
- })
25
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
26
- .then(function (res) {
27
- if (res.errors || res.error || !res.payload)
28
- throw res;
29
-
30
- return {
31
- media: {
32
- id: res.payload.fbid
33
- }
34
- }
35
- })
36
- .catch(cb);
37
-
38
- uploads.push(httpData);
39
- }
40
-
41
- Promise
42
- .all(uploads)
43
- .then(function (main) {
44
- main.forEach(item => form.input.attachments.push(item));
45
-
46
- return cb();
47
- })
48
- .catch(cb);
49
-
50
- return returnPromise;
51
- }
52
-
53
- function handleURL(msg, form) {
54
- if (typeof msg.url == 'string') {
55
- form.input.attachments = [
56
- {
57
- link: {
58
- external: {
59
- url: msg.url
60
- }
61
- }
62
- }
63
- ];
64
- }
65
- }
66
-
67
- function handleMentions(msg, form) {
68
- for (let item of msg.mentions) {
69
- var { tag, id, fromIndex } = item;
70
-
71
- if (typeof tag != 'string')
72
- throw 'Mention tag must be string';
73
- if (!id)
74
- throw 'id must be string';
75
- var offset = msg.body.indexOf(tag, fromIndex || 0);
76
- if (offset < 0)
77
- throw 'Mention for "' + tag + '" not found in message string.';
78
- form.input.message.ranges.push({
79
- entity: { id },
80
- length: tag.length,
81
- offset
82
- });
83
- }
84
- }
85
-
86
- function handleSticker(msg, form) {
87
- if (msg.sticker) {
88
- form.input.attachments = [
89
- {
90
- media: {
91
- id: msg.sticker
92
- }
93
- }
94
- ];
95
- }
96
- }
97
-
98
- function createContent(form) {
99
- var cb;
100
- var returnPromise = new Promise(function (resolve, reject) {
101
- cb = (error, info) => info ? resolve(info) : reject(error);
102
- });
103
-
104
- defaultFuncs
105
- .post('https://www.facebook.com/api/graphql/', ctx.jar, {
106
- fb_api_caller_class: 'RelayModern',
107
- fb_api_req_friendly_name: 'useCometUFICreateCommentMutation',
108
- variables: JSON.stringify(form),
109
- server_timestamps: !0,
110
- doc_id: 6993516810709754
111
- })
112
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
113
- .then(function (res) {
114
- if (res.errors)
115
- throw res;
116
-
117
- var res = res.data.comment_create;
118
- var info = {
119
- id: res.feedback_comment_edge.node.id,
120
- url: res.feedback_comment_edge.node.feedback.url,
121
- count: res.feedback.total_comment_count
122
- }
123
- return cb(null, info);
124
- })
125
- .catch(cb);
126
-
127
- return returnPromise;
128
- }
129
-
130
- return function createCommentPost(msg, postID, callback, replyCommentID) {
131
- var cb;
132
- var returnPromise = new Promise(function (resolve, reject) {
133
- cb = (error, info) => info ? resolve(info) : reject(error);
134
- });
135
-
136
- if (typeof msg == 'function') {
137
- var error = 'Message must be a string or object!!';
138
- console.error('createCommentPost', error);
139
- return msg(error);
140
- }
141
- if (typeof postID == 'function') {
142
- var error = 'postID must be a string!!';
143
- console.error('createCommentPost', error);
144
- return postID(error);
145
- }
146
- if (typeof callback == 'string') {
147
- replyCommentID = callback;
148
- callback = null;
149
- }
150
- if (typeof callback == 'function')
151
- cb = calback;
152
-
153
- var MessageType = utils.getType(msg);
154
-
155
- if (MessageType == 'String')
156
- msg = {
157
- body: msg,
158
- attachments: [],
159
- mentions: [],
160
- sticker: null,
161
- url: null
162
- }
163
- else if (MessageType == 'Object') {
164
- msg.mentions ? !Array.isArray(msg.mentions) ? msg.mentions = [msg.mentions] : null : msg.mentions = [];
165
- msg.attachments ? !Array.isArray(msg.attachments) ? msg.attachments = [msg.attachments] : null : msg.attachments = [];
166
- isNaN(msg.sticker) ? msg.sticker = null : null;
167
- msg.body ? typeof msg.body == 'object' ? msg.body = JSON.stringify(msg.body) : null : msg.body = '';
168
- } else {
169
- var error = 'Message must be a string or object!!';
170
- console.error('createCommentPost', error);
171
- return cb(error);
172
- }
173
- if (typeof postID != 'string') {
174
- var error = 'postID must be a string!!';
175
- console.error('createCommentPost', error);
176
- return cb(error);
177
- }
178
-
179
- if (typeof replyCommentID != 'string')
180
- replyCommentID = null;
181
-
182
- var form = {
183
- feedLocation: 'NEWSFEED',
184
- feedbackSource: 1,
185
- groupID: null,
186
- input: {
187
- client_mutation_id: Math.round(Math.random() * 19).toString(),
188
- actor_id: ctx.userID,
189
- attachments: [],
190
- feedback_id: Buffer.from('feedback:' + postID).toString('base64'),
191
- formatting_style: null,
192
- message: {
193
- ranges: [],
194
- text: msg.body
195
- },
196
- reply_comment_parent_fbid: replyCommentID ? isNaN(replyCommentID) ? replyCommentID : Buffer.from('comment:' + postID + '_' + replyCommentID).toString('base64') : null,
197
- reply_target_clicked: !!replyCommentID,
198
- attribution_id_v2:
199
- 'CometHomeRoot.react,comet.home,via_cold_start,'
200
- + Date.now()
201
- + ',156248,4748854339,,',
202
- vod_video_timestamp: null,
203
- feedback_referrer: '/',
204
- is_tracking_encrypted: !0,
205
- tracking: [],
206
- feedback_source: 'NEWS_FEED',
207
- idempotence_token: 'client:' + utils.getGUID(),
208
- session_id: utils.getGUID()
209
- },
210
- inviteShortLinkKey: null,
211
- renderLocation: null,
212
- scale: 1,
213
- useDefaultActor: !1,
214
- focusCommentID: null
215
- }
216
-
217
- handleUpload(msg, form)
218
- .then(_ => handleURL(msg, form))
219
- .then(_ => handleMentions(msg, form))
220
- .then(_ => handleSticker(msg, form))
221
- .then(_ => createContent(form))
222
- .then(info => cb(null, info))
223
- .catch(function (err) {
224
- console.error('createCommentPost', err);
225
- return cb(null, err);
226
- })
227
-
228
- return returnPromise;
229
- }
230
- }