@cexy/hoonfca 1.0.4 → 1.0.5

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 (135) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/DOCS.md +2636 -0
  3. package/LICENSE-MIT +21 -21
  4. package/README.md +632 -0
  5. package/func/checkUpdate.js +222 -0
  6. package/func/logger.js +48 -0
  7. package/index.d.ts +731 -605
  8. package/index.js +6 -774
  9. package/module/config.js +34 -0
  10. package/module/login.js +136 -0
  11. package/module/loginHelper.js +1034 -0
  12. package/module/options.js +45 -0
  13. package/package.json +54 -19
  14. package/src/api/action/addExternalModule.js +25 -0
  15. package/src/api/action/changeAvatar.js +137 -0
  16. package/src/{changeBio.js → api/action/changeBio.js} +75 -76
  17. package/src/api/action/enableAutoSaveAppState.js +73 -0
  18. package/src/{getCurrentUserID.js → api/action/getCurrentUserID.js} +7 -7
  19. package/src/{handleFriendRequest.js → api/action/handleFriendRequest.js} +57 -57
  20. package/src/api/action/logout.js +76 -0
  21. package/src/api/action/refreshFb_dtsg.js +48 -0
  22. package/src/api/action/setPostReaction.js +106 -0
  23. package/src/api/action/unfriend.js +54 -0
  24. package/src/api/http/httpGet.js +46 -0
  25. package/src/api/http/httpPost.js +52 -0
  26. package/src/api/http/postFormData.js +47 -0
  27. package/src/api/messaging/addUserToGroup.js +68 -0
  28. package/src/api/messaging/changeAdminStatus.js +122 -0
  29. package/src/api/messaging/changeArchivedStatus.js +55 -0
  30. package/src/api/messaging/changeBlockedStatus.js +48 -0
  31. package/src/api/messaging/changeGroupImage.js +90 -0
  32. package/src/api/messaging/changeNickname.js +70 -0
  33. package/src/api/messaging/changeThreadColor.js +79 -0
  34. package/src/api/messaging/changeThreadEmoji.js +106 -0
  35. package/src/{createNewGroup.js → api/messaging/createNewGroup.js} +88 -88
  36. package/src/api/messaging/createPoll.js +43 -0
  37. package/src/api/messaging/createThemeAI.js +98 -0
  38. package/src/{deleteMessage.js → api/messaging/deleteMessage.js} +56 -56
  39. package/src/{deleteThread.js → api/messaging/deleteThread.js} +56 -56
  40. package/src/api/messaging/editMessage.js +68 -0
  41. package/src/api/messaging/forwardAttachment.js +51 -0
  42. package/src/{getEmojiUrl.js → api/messaging/getEmojiUrl.js} +8 -8
  43. package/src/{getFriendsList.js → api/messaging/getFriendsList.js} +82 -84
  44. package/src/api/messaging/getMessage.js +829 -0
  45. package/src/api/messaging/getThemePictures.js +62 -0
  46. package/src/api/messaging/handleMessageRequest.js +65 -0
  47. package/src/{markAsDelivered.js → api/messaging/markAsDelivered.js} +57 -58
  48. package/src/{markAsRead.js → api/messaging/markAsRead.js} +88 -88
  49. package/src/{markAsReadAll.js → api/messaging/markAsReadAll.js} +49 -50
  50. package/src/api/messaging/markAsSeen.js +61 -0
  51. package/src/{muteThread.js → api/messaging/muteThread.js} +50 -52
  52. package/src/api/messaging/removeUserFromGroup.js +106 -0
  53. package/src/{resolvePhotoUrl.js → api/messaging/resolvePhotoUrl.js} +43 -45
  54. package/src/api/messaging/scheduler.js +264 -0
  55. package/src/{searchForThread.js → api/messaging/searchForThread.js} +52 -53
  56. package/src/api/messaging/sendMessage.js +272 -0
  57. package/src/api/messaging/sendTypingIndicator.js +67 -0
  58. package/src/api/messaging/setMessageReaction.js +76 -0
  59. package/src/api/messaging/setTitle.js +119 -0
  60. package/src/{shareContact.js → api/messaging/shareContact.js} +49 -53
  61. package/src/api/messaging/threadColors.js +128 -0
  62. package/src/api/messaging/unsendMessage.js +81 -0
  63. package/src/api/messaging/uploadAttachment.js +94 -0
  64. package/src/api/socket/core/connectMqtt.js +255 -0
  65. package/src/api/socket/core/emitAuth.js +106 -0
  66. package/src/api/socket/core/getSeqID.js +40 -0
  67. package/src/api/socket/core/getTaskResponseData.js +22 -0
  68. package/src/api/socket/core/markDelivery.js +12 -0
  69. package/src/api/socket/core/parseDelta.js +391 -0
  70. package/src/api/socket/detail/buildStream.js +208 -0
  71. package/src/api/socket/detail/constants.js +24 -0
  72. package/src/api/socket/listenMqtt.js +364 -0
  73. package/src/api/socket/middleware/index.js +216 -0
  74. package/src/{getThreadHistory.js → api/threads/getThreadHistory.js} +664 -647
  75. package/src/api/threads/getThreadInfo.js +438 -0
  76. package/src/{getThreadList.js → api/threads/getThreadList.js} +293 -292
  77. package/src/{getThreadPictures.js → api/threads/getThreadPictures.js} +78 -79
  78. package/src/{getUserID.js → api/users/getUserID.js} +65 -66
  79. package/src/api/users/getUserInfo.js +327 -0
  80. package/src/api/users/getUserInfoV2.js +134 -0
  81. package/src/core/sendReqMqtt.js +96 -0
  82. package/src/database/models/index.js +87 -0
  83. package/src/database/models/thread.js +45 -0
  84. package/src/database/models/user.js +46 -0
  85. package/src/database/threadData.js +98 -0
  86. package/src/database/userData.js +89 -0
  87. package/src/utils/client.js +320 -0
  88. package/src/utils/constants.js +23 -0
  89. package/{utils.js → src/utils/format.js} +1115 -1447
  90. package/src/utils/headers.js +115 -0
  91. package/src/utils/request.js +305 -0
  92. package/.travis.yml +0 -6
  93. package/src/addExternalModule.js +0 -23
  94. package/src/addUserToGroup.js +0 -113
  95. package/src/changeAdminStatus.js +0 -95
  96. package/src/changeApprovalMode.js +0 -79
  97. package/src/changeArchivedStatus.js +0 -55
  98. package/src/changeBlockedStatus.js +0 -47
  99. package/src/changeBlockedStatusMqtt.js +0 -86
  100. package/src/changeGroupImage.js +0 -133
  101. package/src/changeNickname.js +0 -59
  102. package/src/changeThreadColor.js +0 -71
  103. package/src/changeThreadEmoji.js +0 -55
  104. package/src/createPoll.js +0 -130
  105. package/src/editMessage.js +0 -63
  106. package/src/forwardAttachment.js +0 -60
  107. package/src/forwardMessage.js +0 -63
  108. package/src/getGroupsList.js +0 -83
  109. package/src/getMarketplace.js +0 -84
  110. package/src/getNotifications.js +0 -86
  111. package/src/getPagesList.js +0 -83
  112. package/src/getStories.js +0 -88
  113. package/src/getThreadInfo.js +0 -222
  114. package/src/getUserInfo.js +0 -128
  115. package/src/handleMessageRequest.js +0 -65
  116. package/src/httpGet.js +0 -58
  117. package/src/httpPost.js +0 -58
  118. package/src/listenMqtt.js +0 -1018
  119. package/src/logout.js +0 -75
  120. package/src/markAsSeen.js +0 -61
  121. package/src/pinMessage.js +0 -61
  122. package/src/removeUserFromGroup.js +0 -79
  123. package/src/searchUsers.js +0 -89
  124. package/src/sendComment.js +0 -161
  125. package/src/sendMessage.js +0 -457
  126. package/src/sendTypingIndicator.js +0 -179
  127. package/src/setBio.js +0 -86
  128. package/src/setMessageReaction.js +0 -186
  129. package/src/setPostReaction.js +0 -71
  130. package/src/setTheme.js +0 -313
  131. package/src/setTitle.js +0 -90
  132. package/src/shareLink.js +0 -62
  133. package/src/threadColors.js +0 -57
  134. package/src/unfriend.js +0 -53
  135. package/src/unsendMessage.js +0 -104
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { parseAndCheckLogin, saveCookies } = require("../../utils/client");
5
+ module.exports = function(defaultFuncs, api, ctx) {
6
+ return function changeBlockedStatus(userID, block, callback) {
7
+ let resolveFunc = function() {};
8
+ let rejectFunc = function() {};
9
+ const returnPromise = new Promise(function(resolve, reject) {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+
14
+ if (!callback) {
15
+ callback = function(err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ defaultFuncs
24
+ .post(
25
+ `https://www.facebook.com/messaging/${
26
+ block ? "" : "un"
27
+ }block_messages/`,
28
+ ctx.jar,
29
+ {
30
+ fbid: userID
31
+ }
32
+ )
33
+ .then(saveCookies(ctx.jar))
34
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
35
+ .then(function(resData) {
36
+ if (resData.error) {
37
+ throw resData;
38
+ }
39
+
40
+ return callback();
41
+ })
42
+ .catch(function(err) {
43
+ log.error("changeBlockedStatus", err);
44
+ return callback(err);
45
+ });
46
+ return returnPromise;
47
+ };
48
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID } = require("../../utils/format.js");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function handleUpload(image) {
8
+ const form = {
9
+ images_only: "true",
10
+ "attachment[]": image
11
+ };
12
+ return defaultFuncs
13
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
14
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
15
+ .then(resData => {
16
+ if (resData.error) throw resData;
17
+ return resData.payload.metadata[0];
18
+ });
19
+ }
20
+ return function changeGroupImage(image, threadID, callback) {
21
+ return new Promise((resolve, reject) => {
22
+ if (!ctx.mqttClient) {
23
+ const err = new Error("Not connected to MQTT");
24
+ callback?.(err);
25
+ return reject(err);
26
+ }
27
+ if (!threadID || typeof threadID !== "string") {
28
+ const err = new Error("Invalid threadID");
29
+ callback?.(err);
30
+ return reject(err);
31
+ }
32
+ const reqID = ++ctx.wsReqNumber;
33
+ const taskID = ++ctx.wsTaskNumber;
34
+ const onResponse = (topic, message) => {
35
+ if (topic !== "/ls_resp") return;
36
+ let jsonMsg;
37
+ try {
38
+ jsonMsg = JSON.parse(message.toString());
39
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
40
+ } catch (err) {
41
+ return;
42
+ }
43
+ if (jsonMsg.request_id !== reqID) return;
44
+ ctx.mqttClient.removeListener("message", onResponse);
45
+ callback?.(null, { success: true, response: jsonMsg.payload });
46
+ return resolve({ success: true, response: jsonMsg.payload });
47
+ };
48
+ ctx.mqttClient.on("message", onResponse);
49
+ handleUpload(image)
50
+ .then(payload => {
51
+ const imageID = payload.image_id;
52
+ const taskPayload = {
53
+ thread_key: threadID,
54
+ image_id: imageID,
55
+ sync_group: 1
56
+ };
57
+
58
+ const mqttPayload = {
59
+ epoch_id: generateOfflineThreadingID(),
60
+ tasks: [
61
+ {
62
+ failure_count: null,
63
+ label: "37",
64
+ payload: JSON.stringify(taskPayload),
65
+ queue_name: "thread_image",
66
+ task_id: taskID
67
+ }
68
+ ],
69
+ version_id: "8798795233522156"
70
+ };
71
+ const request = {
72
+ app_id: "2220391788200892",
73
+ payload: JSON.stringify(mqttPayload),
74
+ request_id: reqID,
75
+ type: 3
76
+ };
77
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(request), {
78
+ qos: 1,
79
+ retain: false
80
+ });
81
+ })
82
+ .catch(err => {
83
+ ctx.mqttClient.removeListener("message", onResponse);
84
+ log.error("changeGroupImageMqtt", err);
85
+ callback?.(err);
86
+ reject(err);
87
+ });
88
+ });
89
+ };
90
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID } = require("../../utils/format.js");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeNickname(nickname, threadID, participantID, callback) {
8
+ return new Promise((resolve, reject) => {
9
+ if (!ctx.mqttClient) {
10
+ const err = new Error("Not connected to MQTT");
11
+ callback?.(err);
12
+ return reject(err);
13
+ }
14
+ if (!threadID || !participantID) {
15
+ const err = new Error("Missing required parameters");
16
+ callback?.(err);
17
+ return reject(err);
18
+ }
19
+ const reqID = ++ctx.wsReqNumber;
20
+ const taskID = ++ctx.wsTaskNumber;
21
+ const payload = {
22
+ epoch_id: generateOfflineThreadingID(),
23
+ tasks: [
24
+ {
25
+ failure_count: null,
26
+ label: "44",
27
+ payload: JSON.stringify({
28
+ thread_key: threadID,
29
+ contact_id: participantID,
30
+ nickname: nickname || "",
31
+ sync_group: 1
32
+ }),
33
+ queue_name: "thread_participant_nickname",
34
+ task_id: taskID
35
+ }
36
+ ],
37
+ version_id: "8798795233522156"
38
+ };
39
+ const request = {
40
+ app_id: "2220391788200892",
41
+ payload: JSON.stringify(payload),
42
+ request_id: reqID,
43
+ type: 3
44
+ };
45
+ const onResponse = (topic, message) => {
46
+ if (topic !== "/ls_resp") return;
47
+ let jsonMsg;
48
+ try {
49
+ jsonMsg = JSON.parse(message.toString());
50
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
51
+ } catch (err) {
52
+ return;
53
+ }
54
+ if (jsonMsg.request_id !== reqID) return;
55
+ ctx.mqttClient.removeListener("message", onResponse);
56
+ callback?.(null, { success: true, response: jsonMsg.payload });
57
+ return resolve({ success: true, response: jsonMsg.payload });
58
+ };
59
+ ctx.mqttClient.on("message", onResponse);
60
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(request), { qos: 1, retain: false }, (err) => {
61
+ if (err) {
62
+ ctx.mqttClient.removeListener("message", onResponse);
63
+ log.error("changeNicknameMqtt", err);
64
+ callback?.(err);
65
+ return reject(err);
66
+ }
67
+ });
68
+ });
69
+ };
70
+ };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID } = require("../../utils/format.js");
4
+ module.exports = (defaultFuncs, api, ctx) => {
5
+ return async (color, threadID, callback) => {
6
+ let reqID = ++ctx.wsReqNumber;
7
+ let resolveFunc = () => { };
8
+ let rejectFunc = () => { };
9
+ const returnPromise = new Promise((resolve, reject) => {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+
14
+ if (!callback) {
15
+ callback = (err, data) => {
16
+ if (err) return rejectFunc(err);
17
+ resolveFunc(data);
18
+ };
19
+ }
20
+
21
+ const content = {
22
+ app_id: "2220391788200892",
23
+ payload: JSON.stringify({
24
+ data_trace_id: null,
25
+ epoch_id: parseInt(generateOfflineThreadingID()),
26
+ tasks: [
27
+ {
28
+ failure_count: null,
29
+ label: "43",
30
+ payload: JSON.stringify({
31
+ thread_key: threadID,
32
+ theme_fbid: color,
33
+ source: null,
34
+ sync_group: 1,
35
+ payload: null
36
+ }),
37
+ queue_name: "thread_theme",
38
+ task_id: ++ctx.wsTaskNumber
39
+ }
40
+ ],
41
+ version_id: "8798795233522156"
42
+ }),
43
+ request_id: reqID,
44
+ type: 3
45
+ };
46
+
47
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(content), {
48
+ qos: 1,
49
+ retain: false
50
+ });
51
+
52
+ const handleRes = (topic, message) => {
53
+ if (topic !== "/ls_resp") return;
54
+ let jsonMsg;
55
+ try {
56
+ jsonMsg = JSON.parse(message.toString());
57
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
58
+ } catch (err) {
59
+ return;
60
+ }
61
+ if (jsonMsg.request_id !== reqID) return;
62
+ ctx.mqttClient.removeListener("message", handleRes);
63
+ try {
64
+ const msgID = jsonMsg.payload.step[1][2][2][1][2];
65
+ const msgReplace = jsonMsg.payload.step[1][2][2][1][4];
66
+ const bodies = {
67
+ body: msgReplace,
68
+ messageID: msgID
69
+ };
70
+ return callback(null, bodies);
71
+ } catch (err) {
72
+ return callback(null, { success: true });
73
+ }
74
+ };
75
+
76
+ ctx.mqttClient.on("message", handleRes);
77
+ return returnPromise;
78
+ };
79
+ };
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID } = require("../../utils/format");
4
+ const log = require("npmlog");
5
+ const { parseAndCheckLogin } = require("../../utils/client");
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function changeThreadEmojiNoMqtt(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
+ if (!callback) {
15
+ callback = function (err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+ var form = {
23
+ emoji_choice: emoji,
24
+ thread_or_other_fbid: threadID,
25
+ };
26
+ defaultFuncs
27
+ .post(
28
+ "https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
29
+ ctx.jar,
30
+ form,
31
+ )
32
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
33
+ .then(function (resData) {
34
+ if (resData.error === 1357031) {
35
+ throw {
36
+ error:
37
+ "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.",
38
+ };
39
+ }
40
+ if (resData.error) {
41
+ throw resData;
42
+ }
43
+ return callback();
44
+ })
45
+ .catch(function (err) {
46
+ log.error("changeThreadEmoji", err);
47
+ return callback(err);
48
+ });
49
+ return returnPromise;
50
+ };
51
+ function changeThreadEmojiMqtt(emoji, threadID, callback) {
52
+ if (!ctx.mqttClient) {
53
+ throw new Error("Not connected to MQTT");
54
+ }
55
+ var resolveFunc = function () { };
56
+ var rejectFunc = function () { };
57
+ var returnPromise = new Promise(function (resolve, reject) {
58
+ resolveFunc = resolve;
59
+ rejectFunc = reject;
60
+ });
61
+ if (!callback) {
62
+ callback = function (err, data) {
63
+ if (err) return rejectFunc(err);
64
+ resolveFunc(data);
65
+ data
66
+ };
67
+ }
68
+ let count_req = 0
69
+ var form = JSON.stringify({
70
+ "app_id": "2220391788200892",
71
+ "payload": JSON.stringify({
72
+ epoch_id: generateOfflineThreadingID(),
73
+ tasks: [
74
+ {
75
+ failure_count: null,
76
+ label: '100003',
77
+ payload: JSON.stringify({
78
+ "thread_key": threadID,
79
+ "custom_emoji": emoji,
80
+ "avatar_sticker_instruction_key_id": null,
81
+ "sync_group": 1
82
+ }),
83
+ queue_name: 'thread_quick_reaction',
84
+ task_id: Math.random() * 1001 << 0
85
+ }
86
+ ],
87
+ version_id: '8798795233522156'
88
+ }),
89
+ "request_id": ++count_req,
90
+ "type": 3
91
+ });
92
+ mqttClient.publish('/ls_req', form);
93
+ return returnPromise;
94
+ };
95
+ return function changeThreadEmoji(emoji, threadID, callback) {
96
+ if (ctx.mqttClient) {
97
+ try {
98
+ changeThreadEmojiMqtt(emoji, threadID, callback);
99
+ } catch (e) {
100
+ changeThreadEmojiNoMqtt(emoji, threadID, callback);
101
+ }
102
+ } else {
103
+ changeThreadEmojiNoMqtt(emoji, threadID, callback);
104
+ }
105
+ };
106
+ };
@@ -1,88 +1,88 @@
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 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 {
19
- error: "createNewGroup: participantIDs should have at least 2 IDs.",
20
- };
21
- }
22
-
23
- var resolveFunc = function () {};
24
- var rejectFunc = function () {};
25
- var returnPromise = new Promise(function (resolve, reject) {
26
- resolveFunc = resolve;
27
- rejectFunc = reject;
28
- });
29
-
30
- if (!callback) {
31
- callback = function (err, threadID) {
32
- if (err) {
33
- return rejectFunc(err);
34
- }
35
- resolveFunc(threadID);
36
- };
37
- }
38
-
39
- var pids = [];
40
- for (var n in participantIDs) {
41
- pids.push({
42
- fbid: participantIDs[n],
43
- });
44
- }
45
- pids.push({ fbid: ctx.userID });
46
-
47
- var form = {
48
- fb_api_caller_class: "RelayModern",
49
- fb_api_req_friendly_name: "MessengerGroupCreateMutation",
50
- av: ctx.userID,
51
- //This doc_id is valid as of January 11th, 2020
52
- doc_id: "577041672419534",
53
- variables: JSON.stringify({
54
- input: {
55
- entry_point: "jewel_new_group",
56
- actor_id: ctx.userID,
57
- participants: pids,
58
- client_mutation_id: Math.round(Math.random() * 1024).toString(),
59
- thread_settings: {
60
- name: groupTitle,
61
- joinable_mode: "PRIVATE",
62
- thread_image_fbid: null,
63
- },
64
- },
65
- }),
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.errors) {
73
- throw resData;
74
- }
75
- return callback(
76
- null,
77
- resData.data.messenger_group_thread_create.thread.thread_key
78
- .thread_fbid,
79
- );
80
- })
81
- .catch(function (err) {
82
- log.error("createNewGroup", err);
83
- return callback(err);
84
- });
85
-
86
- return returnPromise;
87
- };
88
- };
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const { getType } = require("../../utils/format");
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
+ return function createNewGroup(participantIDs, groupTitle, callback) {
8
+ if (getType(groupTitle) == "Function") {
9
+ callback = groupTitle;
10
+ groupTitle = null;
11
+ }
12
+
13
+ if (getType(participantIDs) !== "Array") {
14
+ throw { error: "createNewGroup: participantIDs should be an array." };
15
+ }
16
+
17
+ if (participantIDs.length < 2) {
18
+ throw {
19
+ error: "createNewGroup: participantIDs should have at least 2 IDs."
20
+ };
21
+ }
22
+
23
+ let resolveFunc = function() {};
24
+ let rejectFunc = function() {};
25
+ const returnPromise = new Promise(function(resolve, reject) {
26
+ resolveFunc = resolve;
27
+ rejectFunc = reject;
28
+ });
29
+
30
+ if (!callback) {
31
+ callback = function(err, threadID) {
32
+ if (err) {
33
+ return rejectFunc(err);
34
+ }
35
+ resolveFunc(threadID);
36
+ };
37
+ }
38
+
39
+ const pids = [];
40
+ for (const n in participantIDs) {
41
+ pids.push({
42
+ fbid: participantIDs[n]
43
+ });
44
+ }
45
+ pids.push({ fbid: ctx.i_userID || ctx.userID });
46
+
47
+ const form = {
48
+ fb_api_caller_class: "RelayModern",
49
+ fb_api_req_friendly_name: "MessengerGroupCreateMutation",
50
+ av: ctx.i_userID || ctx.userID,
51
+ //This doc_id is valid as of January 11th, 2020
52
+ doc_id: "577041672419534",
53
+ variables: JSON.stringify({
54
+ input: {
55
+ entry_point: "jewel_new_group",
56
+ actor_id: ctx.i_userID || ctx.userID,
57
+ participants: pids,
58
+ client_mutation_id: Math.round(Math.random() * 1024).toString(),
59
+ thread_settings: {
60
+ name: groupTitle,
61
+ joinable_mode: "PRIVATE",
62
+ thread_image_fbid: null
63
+ }
64
+ }
65
+ })
66
+ };
67
+
68
+ defaultFuncs
69
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
70
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
71
+ .then(function(resData) {
72
+ if (resData.errors) {
73
+ throw resData;
74
+ }
75
+ return callback(
76
+ null,
77
+ resData.data.messenger_group_thread_create.thread.thread_key
78
+ .thread_fbid
79
+ );
80
+ })
81
+ .catch(function(err) {
82
+ log.error("createNewGroup", err);
83
+ return callback(err);
84
+ });
85
+
86
+ return returnPromise;
87
+ };
88
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID } = require("../../utils/format");
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return async function createPoll(threadID, questionText, options) {
7
+ let count_req = 0
8
+ return new Promise((resolve, reject) => {
9
+ const payload = {
10
+ epoch_id: generateOfflineThreadingID(),
11
+ tasks: [
12
+ {
13
+ failure_count: null,
14
+ label: "163",
15
+ payload: JSON.stringify({
16
+ question_text: questionText,
17
+ thread_key: threadID,
18
+ options: options,
19
+ sync_group: 1
20
+ }),
21
+ queue_name: "poll_creation",
22
+ task_id: Math.floor(Math.random() * 1001)
23
+ }
24
+ ],
25
+ version_id: "8768858626531631"
26
+ };
27
+
28
+ const form = JSON.stringify({
29
+ app_id: "772021112871879",
30
+ payload: JSON.stringify(payload),
31
+ request_id: ++count_req,
32
+ type: 3
33
+ });
34
+
35
+ try {
36
+ mqttClient.publish("/ls_req", form);
37
+ resolve();
38
+ } catch (err) {
39
+ reject(err);
40
+ }
41
+ });
42
+ };
43
+ };