@dongdev/fca-unofficial 1.0.20 → 2.0.1

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 (128) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +32 -29
  3. package/DOCS.md +727 -592
  4. package/README.md +94 -97
  5. package/func/logger.js +112 -0
  6. package/html.html +474 -0
  7. package/index.js +1 -379
  8. package/module/config.js +26 -0
  9. package/module/login.js +45 -0
  10. package/module/loginHelper.js +634 -0
  11. package/module/options.js +49 -0
  12. package/package.json +6 -39
  13. package/src/api/action/addExternalModule.js +25 -0
  14. package/src/api/action/changeAvatar.js +136 -0
  15. package/src/api/action/changeBio.js +76 -0
  16. package/src/api/action/getCurrentUserID.js +7 -0
  17. package/src/api/action/handleFriendRequest.js +57 -0
  18. package/src/api/action/logout.js +75 -0
  19. package/src/{refreshFb_dtsg.js → api/action/refreshFb_dtsg.js} +8 -8
  20. package/src/api/action/setPostReaction.js +107 -0
  21. package/src/api/action/unfriend.js +55 -0
  22. package/src/api/http/httpGet.js +65 -0
  23. package/src/api/http/httpPost.js +65 -0
  24. package/src/{postFormData.js → api/http/postFormData.js} +10 -10
  25. package/src/api/messaging/addUserToGroup.js +69 -0
  26. package/src/api/messaging/changeAdminStatus.js +103 -0
  27. package/src/api/messaging/changeArchivedStatus.js +55 -0
  28. package/src/api/messaging/changeBlockedStatus.js +49 -0
  29. package/src/api/messaging/changeGroupImage.js +135 -0
  30. package/src/api/messaging/changeNickname.js +59 -0
  31. package/src/api/messaging/changeThreadColor.js +65 -0
  32. package/src/api/messaging/createNewGroup.js +88 -0
  33. package/src/api/messaging/createPoll.js +70 -0
  34. package/src/api/messaging/deleteMessage.js +56 -0
  35. package/src/api/messaging/deleteThread.js +56 -0
  36. package/src/api/messaging/forwardAttachment.js +60 -0
  37. package/src/api/messaging/getEmojiUrl.js +29 -0
  38. package/src/api/messaging/getFriendsList.js +83 -0
  39. package/src/api/messaging/getMessage.js +834 -0
  40. package/src/api/messaging/getThreadHistory.js +681 -0
  41. package/src/api/messaging/handleMessageRequest.js +65 -0
  42. package/src/api/messaging/markAsDelivered.js +57 -0
  43. package/src/api/messaging/markAsRead.js +88 -0
  44. package/src/api/messaging/markAsReadAll.js +50 -0
  45. package/src/api/messaging/markAsSeen.js +61 -0
  46. package/src/api/messaging/muteThread.js +51 -0
  47. package/src/api/messaging/removeUserFromGroup.js +79 -0
  48. package/src/api/messaging/resolvePhotoUrl.js +44 -0
  49. package/src/api/messaging/searchForThread.js +53 -0
  50. package/src/api/messaging/sendMessage.js +306 -0
  51. package/src/api/messaging/sendMessageMqtt.js +321 -0
  52. package/src/api/messaging/sendTypingIndicator.js +110 -0
  53. package/src/{setMessageReaction.js → api/messaging/setMessageReaction.js} +20 -20
  54. package/src/api/messaging/setTitle.js +90 -0
  55. package/src/api/messaging/shareContact.js +51 -0
  56. package/src/api/messaging/threadColors.js +131 -0
  57. package/src/api/messaging/unsendMessage.js +44 -0
  58. package/src/api/messaging/uploadAttachment.js +93 -0
  59. package/src/api/socket/detail/buildStream.js +100 -0
  60. package/src/{listenMqtt.js → api/socket/listenMqtt.js} +122 -206
  61. package/src/api/threads/changeThreadEmoji.js +55 -0
  62. package/src/api/threads/getThreadInfo.js +572 -0
  63. package/src/{getThreadList.js → api/threads/getThreadList.js} +110 -54
  64. package/src/api/threads/getThreadPictures.js +79 -0
  65. package/src/api/users/getUserID.js +66 -0
  66. package/src/api/users/getUserInfo.js +88 -0
  67. package/src/core/sendReqMqtt.js +63 -0
  68. package/{lib → src}/database/models/index.js +12 -10
  69. package/{lib → src}/database/models/thread.js +5 -5
  70. package/{lib → src}/database/threadData.js +19 -14
  71. package/src/utils/client.js +159 -0
  72. package/src/utils/constants.js +13 -0
  73. package/src/utils/format.js +60 -0
  74. package/src/utils/headers.js +41 -0
  75. package/src/utils/index.js +1497 -0
  76. package/src/utils/request.js +147 -0
  77. package/lib/logger.js +0 -96
  78. package/src/addExternalModule.js +0 -19
  79. package/src/addUserToGroup.js +0 -113
  80. package/src/changeAdminStatus.js +0 -79
  81. package/src/changeArchivedStatus.js +0 -55
  82. package/src/changeAvatar.js +0 -126
  83. package/src/changeBio.js +0 -77
  84. package/src/changeBlockedStatus.js +0 -47
  85. package/src/changeGroupImage.js +0 -132
  86. package/src/changeNickname.js +0 -59
  87. package/src/changeThreadColor.js +0 -65
  88. package/src/changeThreadEmoji.js +0 -55
  89. package/src/createNewGroup.js +0 -86
  90. package/src/createPoll.js +0 -71
  91. package/src/deleteMessage.js +0 -56
  92. package/src/deleteThread.js +0 -56
  93. package/src/forwardAttachment.js +0 -60
  94. package/src/getCurrentUserID.js +0 -7
  95. package/src/getEmojiUrl.js +0 -29
  96. package/src/getFriendsList.js +0 -83
  97. package/src/getMessage.js +0 -796
  98. package/src/getThreadHistory.js +0 -666
  99. package/src/getThreadInfo.js +0 -535
  100. package/src/getThreadPictures.js +0 -79
  101. package/src/getUserID.js +0 -66
  102. package/src/getUserInfo.js +0 -80
  103. package/src/handleFriendRequest.js +0 -61
  104. package/src/handleMessageRequest.js +0 -65
  105. package/src/httpGet.js +0 -57
  106. package/src/httpPost.js +0 -57
  107. package/src/httpPostFormData.js +0 -63
  108. package/src/logout.js +0 -75
  109. package/src/markAsDelivered.js +0 -58
  110. package/src/markAsRead.js +0 -80
  111. package/src/markAsReadAll.js +0 -50
  112. package/src/markAsSeen.js +0 -59
  113. package/src/muteThread.js +0 -52
  114. package/src/removeUserFromGroup.js +0 -79
  115. package/src/resolvePhotoUrl.js +0 -45
  116. package/src/searchForThread.js +0 -53
  117. package/src/sendMessage.js +0 -328
  118. package/src/sendMessageMqtt.js +0 -316
  119. package/src/sendTypingIndicator.js +0 -103
  120. package/src/setPostReaction.js +0 -109
  121. package/src/setTitle.js +0 -86
  122. package/src/shareContact.js +0 -49
  123. package/src/threadColors.js +0 -131
  124. package/src/unfriend.js +0 -52
  125. package/src/unsendMessage.js +0 -49
  126. package/src/uploadAttachment.js +0 -95
  127. package/utils.js +0 -1387
  128. /package/{lib → func}/login.js +0 -0
@@ -1,316 +0,0 @@
1
- var utils = require("../utils");
2
- var log = require("npmlog");
3
- var bluebird = require("bluebird");
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- function uploadAttachment(attachments, callback) {
7
- callback = callback || function () { };
8
- var uploads = [];
9
-
10
- // create an array of promises
11
- for (var i = 0; i < attachments.length; i++) {
12
- if (!utils.isReadableStream(attachments[i])) {
13
- throw {
14
- error:
15
- "Attachment should be a readable stream and not " +
16
- utils.getType(attachments[i]) +
17
- "."
18
- };
19
- }
20
-
21
- var form = {
22
- upload_1024: attachments[i],
23
- voice_clip: "true"
24
- };
25
-
26
- uploads.push(
27
- defaultFuncs
28
- .postFormData(
29
- "https://upload.facebook.com/ajax/mercury/upload.php",
30
- ctx.jar,
31
- form,
32
- {}
33
- )
34
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
- .then(function (resData) {
36
- if (resData.error) {
37
- throw resData;
38
- }
39
-
40
- // We have to return the data unformatted unless we want to change it
41
- // back in sendMessage.
42
- return resData.payload.metadata[0];
43
- })
44
- );
45
- }
46
-
47
- // resolve all promises
48
- bluebird
49
- .all(uploads)
50
- .then(function (resData) {
51
- callback(null, resData);
52
- })
53
- .catch(function (err) {
54
- log.error("uploadAttachment", err);
55
- return callback(err);
56
- });
57
- }
58
-
59
- let variance = 0;
60
- const epoch_id = () => Math.floor(Date.now() * (4194304 + (variance = (variance + 0.1) % 5)));
61
- const emojiSizes = {
62
- small: 1,
63
- medium: 2,
64
- large: 3
65
- };
66
-
67
- function handleEmoji(msg, form, callback, cb) {
68
- if (msg.emojiSize != null && msg.emoji == null) {
69
- return callback({ error: "emoji property is empty" });
70
- }
71
- if (msg.emoji) {
72
- if (!msg.emojiSize) {
73
- msg.emojiSize = "small";
74
- }
75
- if (
76
- msg.emojiSize !== "small" &&
77
- msg.emojiSize !== "medium" &&
78
- msg.emojiSize !== "large" &&
79
- (isNaN(msg.emojiSize) || msg.emojiSize < 1 || msg.emojiSize > 3)
80
- ) {
81
- return callback({ error: "emojiSize property is invalid" });
82
- }
83
-
84
- form.payload.tasks[0].payload.send_type = 1;
85
- form.payload.tasks[0].payload.text = msg.emoji;
86
- form.payload.tasks[0].payload.hot_emoji_size = !isNaN(msg.emojiSize) ? msg.emojiSize : emojiSizes[msg.emojiSize];
87
- }
88
- cb();
89
- }
90
-
91
- function handleSticker(msg, form, callback, cb) {
92
- if (msg.sticker) {
93
- form.payload.tasks[0].payload.send_type = 2;
94
- form.payload.tasks[0].payload.sticker_id = msg.sticker;
95
- }
96
- cb();
97
- }
98
-
99
- function handleAttachment(msg, form, callback, cb) {
100
- if (msg.attachment) {
101
- form.payload.tasks[0].payload.send_type = 3;
102
- form.payload.tasks[0].payload.attachment_fbids = [];
103
- if (form.payload.tasks[0].payload.text == "")
104
- form.payload.tasks[0].payload.text = null;
105
- if (utils.getType(msg.attachment) !== "Array") {
106
- msg.attachment = [msg.attachment];
107
- }
108
-
109
- uploadAttachment(msg.attachment, function (err, files) {
110
- if (err) {
111
- return callback(err);
112
- }
113
-
114
- files.forEach(function (file) {
115
- var key = Object.keys(file);
116
- var type = key[0]; // image_id, file_id, etc
117
- form.payload.tasks[0].payload.attachment_fbids.push(file[type]); // push the id
118
- });
119
- cb();
120
- });
121
- } else {
122
- cb();
123
- }
124
- }
125
-
126
-
127
- function handleMention(msg, form, callback, cb) {
128
- if (msg.mentions) {
129
- form.payload.tasks[0].payload.send_type = 1;
130
-
131
- const arrayIds = [];
132
- const arrayOffsets = [];
133
- const arrayLengths = [];
134
- const mention_types = [];
135
-
136
- for (let i = 0; i < msg.mentions.length; i++) {
137
- const mention = msg.mentions[i];
138
-
139
- const tag = mention.tag;
140
- if (typeof tag !== "string") {
141
- return callback({ error: "Mention tags must be strings." });
142
- }
143
-
144
- const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
145
-
146
- if (offset < 0) {
147
- log.warn(
148
- "handleMention",
149
- 'Mention for "' + tag + '" not found in message string.'
150
- );
151
- }
152
-
153
- if (mention.id == null) {
154
- log.warn("handleMention", "Mention id should be non-null.");
155
- }
156
-
157
- const id = mention.id || 0;
158
- arrayIds.push(id);
159
- arrayOffsets.push(offset);
160
- arrayLengths.push(tag.length);
161
- mention_types.push("p");
162
- }
163
-
164
- form.payload.tasks[0].payload.mention_data = {
165
- mention_ids: arrayIds.join(","),
166
- mention_offsets: arrayOffsets.join(","),
167
- mention_lengths: arrayLengths.join(","),
168
- mention_types: mention_types.join(",")
169
- };
170
- }
171
- cb();
172
- }
173
-
174
- function handleLocation(msg, form, callback, cb) {
175
- // this is not working yet
176
- if (msg.location) {
177
- if (msg.location.latitude == null || msg.location.longitude == null) {
178
- return callback({ error: "location property needs both latitude and longitude" });
179
- }
180
-
181
- form.payload.tasks[0].payload.send_type = 1;
182
- form.payload.tasks[0].payload.location_data = {
183
- coordinates: {
184
- latitude: msg.location.latitude,
185
- longitude: msg.location.longitude
186
- },
187
- is_current_location: !!msg.location.current,
188
- is_live_location: !!msg.location.live
189
- };
190
- }
191
-
192
- cb();
193
- }
194
-
195
- function send(form, threadID, callback, replyToMessage) {
196
- if (replyToMessage) {
197
- form.payload.tasks[0].payload.reply_metadata = {
198
- reply_source_id: replyToMessage,
199
- reply_source_type: 1,
200
- reply_type: 0
201
- };
202
- }
203
- const mqttClient = ctx.mqttClient;
204
- form.payload.tasks.forEach((task) => {
205
- task.payload = JSON.stringify(task.payload);
206
- });
207
- form.payload = JSON.stringify(form.payload);
208
- console.log(global.jsonStringifyColor(form, null, 2));
209
-
210
- return mqttClient.publish("/ls_req", JSON.stringify(form), function (err, data) {
211
- if (err) {
212
- console.error('Error publishing message: ', err);
213
- callback(err);
214
- } else {
215
- console.log('Message published successfully with data: ', data);
216
- callback(null, data);
217
- }
218
- });
219
- }
220
-
221
- return function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
222
- if (
223
- !callback &&
224
- (utils.getType(threadID) === "Function" ||
225
- utils.getType(threadID) === "AsyncFunction")
226
- ) {
227
- return threadID({ error: "Pass a threadID as a second argument." });
228
- }
229
- if (
230
- !replyToMessage &&
231
- utils.getType(callback) === "String"
232
- ) {
233
- replyToMessage = callback;
234
- callback = function () { };
235
- }
236
-
237
-
238
- if (!callback) {
239
- callback = function (err, friendList) {
240
- };
241
- }
242
-
243
- var msgType = utils.getType(msg);
244
- var threadIDType = utils.getType(threadID);
245
- var messageIDType = utils.getType(replyToMessage);
246
-
247
- if (msgType !== "String" && msgType !== "Object") {
248
- return callback({
249
- error:
250
- "Message should be of type string or object and not " + msgType + "."
251
- });
252
- }
253
-
254
- if (msgType === "String") {
255
- msg = { body: msg };
256
- }
257
-
258
- const timestamp = Date.now();
259
- // get full date time
260
- const epoch = timestamp << 22;
261
- //const otid = epoch + 0; // TODO replace with randomInt(0, 2**22)
262
- const otid = epoch + Math.floor(Math.random() * 4194304);
263
-
264
- const form = {
265
- app_id: "2220391788200892",
266
- payload: {
267
- tasks: [
268
- {
269
- label: "46",
270
- payload: {
271
- thread_id: threadID.toString(),
272
- otid: otid.toString(),
273
- source: 0,
274
- send_type: 1,
275
- sync_group: 1,
276
- text: msg.body != null && msg.body != undefined ? msg.body.toString() : "",
277
- initiating_source: 1,
278
- skip_url_preview_gen: 0
279
- },
280
- queue_name: threadID.toString(),
281
- task_id: 0,
282
- failure_count: null
283
- },
284
- {
285
- label: "21",
286
- payload: {
287
- thread_id: threadID.toString(),
288
- last_read_watermark_ts: Date.now(),
289
- sync_group: 1
290
- },
291
- queue_name: threadID.toString(),
292
- task_id: 1,
293
- failure_count: null
294
- }
295
- ],
296
- epoch_id: epoch_id(),
297
- version_id: "6120284488008082",
298
- data_trace_id: null
299
- },
300
- request_id: 1,
301
- type: 3
302
- };
303
-
304
- handleEmoji(msg, form, callback, function () {
305
- handleLocation(msg, form, callback, function () {
306
- handleMention(msg, form, callback, function () {
307
- handleSticker(msg, form, callback, function () {
308
- handleAttachment(msg, form, callback, function () {
309
- send(form, threadID, callback, replyToMessage);
310
- });
311
- });
312
- });
313
- });
314
- });
315
- };
316
- };
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- function makeTypingIndicator(typ, threadID, callback, isGroup) {
8
- const form = {
9
- typ: +typ,
10
- to: "",
11
- source: "mercury-chat",
12
- thread: threadID
13
- };
14
-
15
- // Check if thread is a single person chat or a group chat
16
- // More info on this is in api.sendMessage
17
- if (utils.getType(isGroup) == "Boolean") {
18
- if (!isGroup) {
19
- form.to = threadID;
20
- }
21
- defaultFuncs
22
- .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
23
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
24
- .then(function (resData) {
25
- if (resData.error) {
26
- throw resData;
27
- }
28
-
29
- return callback();
30
- })
31
- .catch(function (err) {
32
- log.error("sendTypingIndicator", err);
33
- if (utils.getType(err) == "Object" && err.error === "Not logged in") {
34
- ctx.loggedIn = false;
35
- }
36
- return callback(err);
37
- });
38
- } else {
39
- api.getUserInfo(threadID, function (err, res) {
40
- if (err) {
41
- return callback(err);
42
- }
43
-
44
- // If id is single person chat
45
- if (Object.keys(res).length > 0) {
46
- form.to = threadID;
47
- }
48
-
49
- defaultFuncs
50
- .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
51
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
52
- .then(function (resData) {
53
- if (resData.error) {
54
- throw resData;
55
- }
56
-
57
- return callback();
58
- })
59
- .catch(function (err) {
60
- log.error("sendTypingIndicator", err);
61
- if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
62
- ctx.loggedIn = false;
63
- }
64
- return callback(err);
65
- });
66
- });
67
- }
68
- }
69
-
70
- return function sendTypingIndicator(threadID, callback, isGroup) {
71
- if (
72
- utils.getType(callback) !== "Function" &&
73
- utils.getType(callback) !== "AsyncFunction"
74
- ) {
75
- if (callback) {
76
- log.warn(
77
- "sendTypingIndicator",
78
- "callback is not a function - ignoring."
79
- );
80
- }
81
- callback = () => { };
82
- }
83
-
84
- makeTypingIndicator(true, threadID, callback, isGroup);
85
-
86
- return function end(cb) {
87
- if (
88
- utils.getType(cb) !== "Function" &&
89
- utils.getType(cb) !== "AsyncFunction"
90
- ) {
91
- if (cb) {
92
- log.warn(
93
- "sendTypingIndicator",
94
- "callback is not a function - ignoring."
95
- );
96
- }
97
- cb = () => { };
98
- }
99
-
100
- makeTypingIndicator(false, threadID, cb, isGroup);
101
- };
102
- };
103
- };
@@ -1,109 +0,0 @@
1
- /**
2
- * @fix by NTKhang
3
- * update as Thursday, 10 February 2022
4
- * do not remove the author name to get more updates
5
- */
6
-
7
- "use strict";
8
-
9
- const utils = require("../utils");
10
- const log = require("npmlog");
11
-
12
- function formatData(resData) {
13
- return {
14
- viewer_feedback_reaction_info: resData.feedback_react.feedback.viewer_feedback_reaction_info,
15
- supported_reactions: resData.feedback_react.feedback.supported_reactions,
16
- top_reactions: resData.feedback_react.feedback.top_reactions.edges,
17
- reaction_count: resData.feedback_react.feedback.reaction_count
18
- };
19
- }
20
-
21
- module.exports = function (defaultFuncs, api, ctx) {
22
- return function setPostReaction(postID, type, callback) {
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
- if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
32
- callback = type;
33
- type = 0;
34
- }
35
- else {
36
- callback = function (err, data) {
37
- if (err) {
38
- return rejectFunc(err);
39
- }
40
- resolveFunc(data);
41
- };
42
- }
43
- }
44
-
45
- const map = {
46
- unlike: 0,
47
- like: 1,
48
- heart: 2,
49
- love: 16,
50
- haha: 4,
51
- wow: 3,
52
- sad: 7,
53
- angry: 8
54
- };
55
-
56
- if (utils.getType(type) !== "Number" && utils.getType(type) === "String") {
57
- type = map[type.toLowerCase()];
58
- }
59
-
60
- if (utils.getType(type) !== "Number" && utils.getType(type) !== "String") {
61
- throw {
62
- error: "setPostReaction: Invalid reaction type"
63
- };
64
- }
65
-
66
- if (type != 0 && !type) {
67
- throw {
68
- error: "setPostReaction: Invalid reaction type"
69
- };
70
- }
71
-
72
- const form = {
73
- av: ctx.i_userID || ctx.userID,
74
- fb_api_caller_class: "RelayModern",
75
- fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
76
- doc_id: "4769042373179384",
77
- variables: JSON.stringify({
78
- input: {
79
- actor_id: ctx.i_userID || ctx.userID,
80
- feedback_id: (new Buffer("feedback:" + postID)).toString("base64"),
81
- feedback_reaction: type,
82
- feedback_source: "OBJECT",
83
- is_tracking_encrypted: true,
84
- tracking: [],
85
- session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
86
- client_mutation_id: Math.round(Math.random() * 19).toString()
87
- },
88
- useDefaultActor: false,
89
- scale: 3
90
- })
91
- };
92
-
93
- defaultFuncs
94
- .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
95
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
96
- .then(function (resData) {
97
- if (resData.errors) {
98
- throw resData;
99
- }
100
- return callback(null, formatData(resData.data));
101
- })
102
- .catch(function (err) {
103
- log.error("setPostReaction", err);
104
- return callback(err);
105
- });
106
-
107
- return returnPromise;
108
- };
109
- };
package/src/setTitle.js DELETED
@@ -1,86 +0,0 @@
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 setTitle(newTitle, threadID, callback) {
8
- if (
9
- !callback &&
10
- (utils.getType(threadID) === "Function" ||
11
- utils.getType(threadID) === "AsyncFunction")
12
- ) {
13
- throw { error: "please pass a threadID as a second argument." };
14
- }
15
-
16
- let resolveFunc = function () { };
17
- let rejectFunc = function () { };
18
- const returnPromise = new Promise(function (resolve, reject) {
19
- resolveFunc = resolve;
20
- rejectFunc = reject;
21
- });
22
-
23
- if (!callback) {
24
- callback = function (err, friendList) {
25
- if (err) {
26
- return rejectFunc(err);
27
- }
28
- resolveFunc(friendList);
29
- };
30
- }
31
-
32
- const messageAndOTID = utils.generateOfflineThreadingID();
33
- const form = {
34
- client: "mercury",
35
- action_type: "ma-type:log-message",
36
- author: "fbid:" + (ctx.i_userID || ctx.userID),
37
- author_email: "",
38
- coordinates: "",
39
- timestamp: Date.now(),
40
- timestamp_absolute: "Today",
41
- timestamp_relative: utils.generateTimestampRelative(),
42
- timestamp_time_passed: "0",
43
- is_unread: false,
44
- is_cleared: false,
45
- is_forward: false,
46
- is_filtered_content: false,
47
- is_spoof_warning: false,
48
- source: "source:chat:web",
49
- "source_tags[0]": "source:chat",
50
- status: "0",
51
- offline_threading_id: messageAndOTID,
52
- message_id: messageAndOTID,
53
- threading_id: utils.generateThreadingID(ctx.clientID),
54
- manual_retry_cnt: "0",
55
- thread_fbid: threadID,
56
- thread_name: newTitle,
57
- thread_id: threadID,
58
- log_message_type: "log:thread-name"
59
- };
60
-
61
- defaultFuncs
62
- .post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
63
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
64
- .then(function (resData) {
65
- if (resData.error && resData.error === 1545012) {
66
- throw { error: "Cannot change chat title: Not member of chat." };
67
- }
68
-
69
- if (resData.error && resData.error === 1545003) {
70
- throw { error: "Cannot set title of single-user chat." };
71
- }
72
-
73
- if (resData.error) {
74
- throw resData;
75
- }
76
-
77
- return callback();
78
- })
79
- .catch(function (err) {
80
- log.error("setTitle", err);
81
- return callback(err);
82
- });
83
-
84
- return returnPromise;
85
- };
86
- };
@@ -1,49 +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 shareContact(text, senderID, threadID, callback) {
8
- if (!text) {
9
- text = "";
10
- }
11
- var resolveFunc = function () { };
12
- var rejectFunc = function () { };
13
- var returnPromise = new Promise(function (resolve, reject) {
14
- resolveFunc = resolve;
15
- rejectFunc = reject;
16
- });
17
- if (!callback) {
18
- callback = function (err, data) {
19
- if (err) return rejectFunc(err);
20
- resolveFunc(data);
21
- data
22
- };
23
- }
24
- let count_req = 0
25
- var form = JSON.stringify({
26
- "app_id": "2220391788200892",
27
- "payload": JSON.stringify({
28
- tasks: [{
29
- label: '359',
30
- payload: JSON.stringify({
31
- "contact_id": senderID,
32
- "sync_group": 1,
33
- "text": text || "",
34
- "thread_id": threadID
35
- }),
36
- queue_name: 'messenger_contact_sharing',
37
- task_id: Math.random() * 1001 << 0,
38
- failure_count: null,
39
- }],
40
- epoch_id: utils.generateOfflineThreadingID(),
41
- version_id: '7214102258676893',
42
- }),
43
- "request_id": ++count_req,
44
- "type": 3
45
- });
46
- mqttClient.publish('/ls_req', form);
47
- return returnPromise;
48
- };
49
- };