raza-fca-pkg 1.0.4 → 1.0.6

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 (111) hide show
  1. package/RazaFca.json +2 -2
  2. package/index.js +100 -198
  3. package/main.js +26 -56
  4. package/package.json +2 -1
  5. package/src/addExternalModule.js +25 -0
  6. package/src/addUserToGroup.js +115 -0
  7. package/src/changeAdminStatus.js +103 -0
  8. package/src/changeArchivedStatus.js +55 -0
  9. package/src/changeAvatar.js +86 -0
  10. package/src/changeBio.js +76 -0
  11. package/src/changeBlockedStatus.js +49 -0
  12. package/src/changeBlockedStatusMqtt.js +80 -0
  13. package/src/changeCover.js +72 -0
  14. package/src/changeGroupImage.js +135 -0
  15. package/src/changeName.js +78 -0
  16. package/src/changeNickname.js +59 -0
  17. package/src/changeThreadColor.js +63 -0
  18. package/src/changeThreadEmoji.js +61 -0
  19. package/src/changeThreadTheme.js +63 -0
  20. package/src/changeUsername.js +58 -0
  21. package/src/createCommentPost.js +229 -0
  22. package/src/createNewGroup.js +88 -0
  23. package/src/createNote.js +67 -0
  24. package/src/createPoll.js +71 -0
  25. package/src/createPost.js +275 -0
  26. package/src/createStoryReply.js +59 -0
  27. package/src/data/getThreadInfo.json +1 -0
  28. package/src/deleteMessage.js +56 -0
  29. package/src/deleteThread.js +56 -0
  30. package/src/detectSuspiciousActivity.js +147 -0
  31. package/src/editMessage.js +69 -0
  32. package/src/endCall.js +49 -0
  33. package/src/follow.js +74 -0
  34. package/src/forwardAttachment.js +60 -0
  35. package/src/getAccess.js +111 -0
  36. package/src/getAccountStatus.js +64 -0
  37. package/src/getAvatarUser.js +78 -0
  38. package/src/getBotInitialData.js +43 -0
  39. package/src/getCallInfo.js +51 -0
  40. package/src/getConnectionHealth.js +105 -0
  41. package/src/getCtx.js +5 -0
  42. package/src/getCurrentUserID.js +7 -0
  43. package/src/getEmojiUrl.js +29 -0
  44. package/src/getFriendsList.js +83 -0
  45. package/src/getGroupNicknames.js +63 -0
  46. package/src/getLiveLocation.js +52 -0
  47. package/src/getMessage.js +835 -0
  48. package/src/getMessageReactions.js +72 -0
  49. package/src/getMetaAIConversations.js +51 -0
  50. package/src/getNotes.js +52 -0
  51. package/src/getOnlinePresence.js +68 -0
  52. package/src/getOptions.js +5 -0
  53. package/src/getPolls.js +70 -0
  54. package/src/getRegion.js +7 -0
  55. package/src/getThreadHistory.js +680 -0
  56. package/src/getThreadHistoryDeprecated.js +93 -0
  57. package/src/getThreadInfo.js +227 -0
  58. package/src/getThreadInfoDeprecated.js +80 -0
  59. package/src/getThreadList.js +269 -0
  60. package/src/getThreadListDeprecated.js +75 -0
  61. package/src/getThreadPictures.js +79 -0
  62. package/src/getUserID.js +66 -0
  63. package/src/getUserInfo.js +82 -0
  64. package/src/handleAccountSecurity.js +137 -0
  65. package/src/handleCallEvent.js +65 -0
  66. package/src/handleFriendRequest.js +57 -0
  67. package/src/handleMessageRequest.js +65 -0
  68. package/src/httpGet.js +64 -0
  69. package/src/httpPost.js +64 -0
  70. package/src/httpPostFormData.js +70 -0
  71. package/src/listenMqtt.js +928 -0
  72. package/src/listenNotification.js +85 -0
  73. package/src/logout.js +75 -0
  74. package/src/markAsDelivered.js +55 -0
  75. package/src/markAsRead.js +85 -0
  76. package/src/markAsReadAll.js +50 -0
  77. package/src/markAsSeen.js +61 -0
  78. package/src/muteThread.js +52 -0
  79. package/src/pinMessage.js +59 -0
  80. package/src/removeUserFromGroup.js +79 -0
  81. package/src/resolvePhotoUrl.js +45 -0
  82. package/src/respondToPoll.js +63 -0
  83. package/src/saveSession.js +65 -0
  84. package/src/searchForThread.js +53 -0
  85. package/src/searchMessages.js +71 -0
  86. package/src/searchStickers.js +53 -0
  87. package/src/sendLiveLocation.js +83 -0
  88. package/src/sendMessage.js +490 -0
  89. package/src/sendMessageMqtt.js +316 -0
  90. package/src/sendMetaAIMessage.js +94 -0
  91. package/src/sendTypingIndicator.js +54 -0
  92. package/src/setGroupNickname.js +60 -0
  93. package/src/setMessageReaction.js +122 -0
  94. package/src/setMessageReactionMqtt.js +62 -0
  95. package/src/setPostReaction.js +108 -0
  96. package/src/setProfileGuard.js +44 -0
  97. package/src/setStoryReaction.js +64 -0
  98. package/src/setTitle.js +90 -0
  99. package/src/shareContact.js +110 -0
  100. package/src/shareLink.js +59 -0
  101. package/src/startAntiDetection.js +128 -0
  102. package/src/startAutoStabilizer.js +155 -0
  103. package/src/startCall.js +55 -0
  104. package/src/stopListenMqtt.js +23 -0
  105. package/src/threadColors.js +154 -0
  106. package/src/unfriend.js +52 -0
  107. package/src/unsendMessage.js +45 -0
  108. package/src/uploadAttachment.js +104 -0
  109. package/utils.js +439 -559
  110. package/LICENSE-MIT +0 -21
  111. package/README.md +0 -62
package/RazaFca.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "jazoest": "278651021168610357767252458997888311911650505110082102105724511281785677117717610011289745389526648521071177012178111559898115655849495849555457535255535156"
5
5
  },
6
6
  "61580918881106": {
7
- "fb_dtsg": "NAfuV__Jd4Kqt7WSFb8DqOhvFOrYvNi7TaTiBU6xc41BNCrq8l6IHSA:31:1772620332",
8
- "jazoest": "27865102117869595741005275113116558783709856681137910411870791148911878105558497841056685541209952496678671141135610854737283655851495849555550545048515150"
7
+ "fb_dtsg": "NAftTd2PF49dqJGmFk4lxjkmZj5tOktJRexCdqmnwt4pNgNsmYKgPCg:12:1772638291",
8
+ "jazoest": "2786510211684100508070525710011374711097010752108120106107109901065311679107116748210112067100113109110119116521127810378115109897510380671035849505849555550545156505749"
9
9
  }
10
10
  }
package/index.js CHANGED
@@ -10,9 +10,8 @@ let defaultFuncs = null;
10
10
  let api = null;
11
11
  let region = null;
12
12
 
13
- const fbLink = ext => "https://www.facebook.com" + (ext ? "/" + ext : "");
14
- const ERROR_RETRIEVING =
15
- "Error retrieving userID. This can be caused by many factors, including being blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify.";
13
+ const fbLink = (ext) => ("https://www.facebook.com" + (ext ? '/' + ext : ''));
14
+ const ERROR_RETRIEVING = "Error retrieving userID. This can be caused by many factors, including being blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify.";
16
15
 
17
16
  /**
18
17
  * Sets global options based on provided configuration.
@@ -21,18 +20,17 @@ const ERROR_RETRIEVING =
21
20
  */
22
21
  async function setOptions(options = {}) {
23
22
  const optionHandlers = {
24
- online: value => (globalOptions.online = Boolean(value)),
25
- selfListen: value => (globalOptions.selfListen = Boolean(value)),
26
- selfListenEvent: value => (globalOptions.selfListenEvent = value),
27
- listenEvents: value => (globalOptions.listenEvents = Boolean(value)),
28
- updatePresence: value => (globalOptions.updatePresence = Boolean(value)),
29
- forceLogin: value => (globalOptions.forceLogin = Boolean(value)),
30
- userAgent: value => (globalOptions.userAgent = value),
31
- autoMarkDelivery: value =>
32
- (globalOptions.autoMarkDelivery = Boolean(value)),
33
- autoMarkRead: value => (globalOptions.autoMarkRead = Boolean(value)),
34
- listenTyping: value => (globalOptions.listenTyping = Boolean(value)),
35
- proxy: value => {
23
+ online: (value) => (globalOptions.online = Boolean(value)),
24
+ selfListen: (value) => (globalOptions.selfListen = Boolean(value)),
25
+ selfListenEvent: (value) => (globalOptions.selfListenEvent = value),
26
+ listenEvents: (value) => (globalOptions.listenEvents = Boolean(value)),
27
+ updatePresence: (value) => (globalOptions.updatePresence = Boolean(value)),
28
+ forceLogin: (value) => (globalOptions.forceLogin = Boolean(value)),
29
+ userAgent: (value) => (globalOptions.userAgent = value),
30
+ autoMarkDelivery: (value) => (globalOptions.autoMarkDelivery = Boolean(value)),
31
+ autoMarkRead: (value) => (globalOptions.autoMarkRead = Boolean(value)),
32
+ listenTyping: (value) => (globalOptions.listenTyping = Boolean(value)),
33
+ proxy: (value) => {
36
34
  if (typeof value !== "string") {
37
35
  delete globalOptions.proxy;
38
36
  utils.setProxy();
@@ -41,21 +39,19 @@ async function setOptions(options = {}) {
41
39
  utils.setProxy(value);
42
40
  }
43
41
  },
44
- autoReconnect: value => (globalOptions.autoReconnect = Boolean(value)),
45
- emitReady: value => (globalOptions.emitReady = Boolean(value)),
46
- randomUserAgent: value => {
42
+ autoReconnect: (value) => (globalOptions.autoReconnect = Boolean(value)),
43
+ emitReady: (value) => (globalOptions.emitReady = Boolean(value)),
44
+ randomUserAgent: (value) => {
47
45
  globalOptions.randomUserAgent = Boolean(value);
48
46
  if (value) {
49
47
  globalOptions.userAgent = utils.randomUserAgent();
50
- utils.warn(
51
- "Random user agent enabled. This is an experimental feature and may not work with some accounts. Use at your own risk."
52
- );
48
+ utils.warn("Random user agent enabled. This is an experimental feature and may not work with some accounts. Use at your own risk.");
53
49
  utils.warn("randomUserAgent", "UA selected:", globalOptions.userAgent);
54
50
  }
55
51
  },
56
- bypassRegion: value => (globalOptions.bypassRegion = value)
52
+ bypassRegion: (value) => (globalOptions.bypassRegion = value),
57
53
  };
58
-
54
+
59
55
  Object.entries(options).forEach(([key, value]) => {
60
56
  if (optionHandlers[key]) optionHandlers[key](value);
61
57
  });
@@ -69,45 +65,31 @@ async function setOptions(options = {}) {
69
65
  */
70
66
  async function checkIfSuspended(resp, appstate) {
71
67
  try {
72
- const appstateCUser = appstate.find(
73
- i => i.key === "c_user" || i.key === "i_user"
74
- );
68
+ const appstateCUser = appstate.find((i) => i.key === "c_user" || i.key === "i_user");
75
69
  const UID = appstateCUser?.value;
76
-
77
- if (
78
- resp?.request?.uri?.href?.includes(fbLink("checkpoint")) &&
79
- resp.request.uri.href.includes("1501092823525282")
80
- ) {
70
+
71
+ if (resp?.request?.uri?.href?.includes(fbLink("checkpoint")) && resp.request.uri.href.includes("1501092823525282")) {
81
72
  const suspendReasons = {};
82
-
83
- const daystoDisable = resp.body?.match(
84
- /"log_out_uri":"(.*?)","title":"(.*?)"/
85
- );
73
+
74
+ const daystoDisable = resp.body?.match(/"log_out_uri":"(.*?)","title":"(.*?)"/);
86
75
  if (daystoDisable?.[2]) {
87
76
  suspendReasons.durationInfo = daystoDisable[2];
88
- utils.error(
89
- `Suspension time remaining: ${suspendReasons.durationInfo}`
90
- );
77
+ utils.error(`Suspension time remaining: ${suspendReasons.durationInfo}`);
91
78
  }
92
-
93
- const reasonDescription = resp.body?.match(
94
- /"reason_section_body":"(.*?)"/
95
- );
79
+
80
+ const reasonDescription = resp.body?.match(/"reason_section_body":"(.*?)"/);
96
81
  if (reasonDescription && reasonDescription[1]) {
97
82
  suspendReasons.longReason = reasonDescription[1];
98
83
  suspendReasons.shortReason = suspendReasons.longReason
99
84
  .toLowerCase()
100
- .replace(
101
- "your account, or activity on it, doesn't follow our community standards on ",
102
- ""
103
- )
104
- .replace(/^\w/, c => c.toUpperCase());
105
-
85
+ .replace("your account, or activity on it, doesn't follow our community standards on ", "")
86
+ .replace(/^\w/, (c) => c.toUpperCase());
87
+
106
88
  utils.error(`Alert on ${UID}: Account has been suspended!`);
107
89
  utils.error(`Why suspended: ${suspendReasons.longReason}`);
108
90
  utils.error(`Reason for suspension: ${suspendReasons.shortReason}`);
109
91
  }
110
-
92
+
111
93
  ctx = null;
112
94
  return { suspended: true, suspendReasons };
113
95
  }
@@ -124,25 +106,18 @@ async function checkIfSuspended(resp, appstate) {
124
106
  */
125
107
  async function checkIfLocked(resp, appstate) {
126
108
  try {
127
- const appstateCUser = appstate.find(
128
- i => i.key === "c_user" || i.key === "i_user"
129
- );
109
+ const appstateCUser = appstate.find((i) => i.key === "c_user" || i.key === "i_user");
130
110
  const UID = appstateCUser?.value;
131
-
132
- if (
133
- resp?.request?.uri?.href?.includes(fbLink("checkpoint")) &&
134
- resp.request.uri.href.includes("828281030927956")
135
- ) {
111
+
112
+ if (resp?.request?.uri?.href?.includes(fbLink("checkpoint")) && resp.request.uri.href.includes("828281030927956")) {
136
113
  const lockedReasons = {};
137
- const lockDesc = resp.body?.match(
138
- /"is_unvetted_flow":true,"title":"(.*?)"/
139
- );
140
-
114
+ const lockDesc = resp.body?.match(/"is_unvetted_flow":true,"title":"(.*?)"/);
115
+
141
116
  if (lockDesc && lockDesc[1]) {
142
117
  lockedReasons.reason = lockDesc[1];
143
118
  utils.error(`Alert on ${UID}: ${lockedReasons.reason}`);
144
119
  }
145
-
120
+
146
121
  ctx = null;
147
122
  return { locked: true, lockedReasons };
148
123
  }
@@ -161,47 +136,29 @@ async function buildAPI(html, jar) {
161
136
  let userID;
162
137
  const filePath = "RazaFca.json";
163
138
  const cookies = jar.getCookies(fbLink());
164
- const primaryProfile = cookies.find(val =>
165
- val.cookieString().startsWith("c_user=")
166
- );
167
- const secondaryProfile = cookies.find(val =>
168
- val.cookieString().startsWith("i_user=")
169
- );
170
-
139
+ const primaryProfile = cookies.find((val) => val.cookieString().startsWith("c_user="));
140
+ const secondaryProfile = cookies.find((val) => val.cookieString().startsWith("i_user="));
141
+
171
142
  if (!primaryProfile && !secondaryProfile) {
172
143
  throw new Error(ERROR_RETRIEVING);
173
144
  }
174
-
145
+
175
146
  if (html.includes("/checkpoint/block/?next")) {
176
- utils.warn(
177
- "login",
178
- "Checkpoint detected. Please log in with a browser to verify."
179
- );
147
+ utils.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
180
148
  throw new Error("Checkpoint detected");
181
149
  }
182
-
183
- userID =
184
- secondaryProfile?.cookieString().split("=")[1] ||
185
- primaryProfile.cookieString().split("=")[1];
150
+
151
+ userID = secondaryProfile?.cookieString().split("=")[1] || primaryProfile.cookieString().split("=")[1];
186
152
  const refreshFb_dtsg = async () => {
187
153
  try {
188
- const getDtsg = await utils.get(
189
- fbLink("ajax/dtsg/?__a=true"),
190
- jar,
191
- null,
192
- globalOptions
193
- );
194
- if (!getDtsg.body)
195
- throw new Error("Empty response from Facebook for fb_dtsg");
196
- const dtsgMatch = getDtsg.body.match(
197
- /\["DTSGInitData",\[\],{"token":"(.*?)"/
198
- );
154
+ const getDtsg = await utils.get(fbLink("ajax/dtsg/?__a=true"), jar, null, globalOptions);
155
+ if (!getDtsg.body) throw new Error("Empty response from Facebook for fb_dtsg");
156
+ const dtsgMatch = getDtsg.body.match(/\["DTSGInitData",\[\],{"token":"(.*?)"/);
199
157
  let dtsg;
200
158
  if (dtsgMatch && dtsgMatch[1]) {
201
159
  dtsg = dtsgMatch[1];
202
160
  } else {
203
- dtsg = JSON.parse(getDtsg.body.replace("for (;;);{", "{")).payload
204
- .token;
161
+ dtsg = JSON.parse(getDtsg.body.replace('for (;;);{', "{")).payload.token;
205
162
  }
206
163
  let jazoest = "2";
207
164
  for (const char of dtsg) {
@@ -224,21 +181,15 @@ async function buildAPI(html, jar) {
224
181
  utils.error("refreshFb_dtsg", error);
225
182
  throw error;
226
183
  }
227
- };
184
+ }
228
185
  const dtsgResult = await refreshFb_dtsg();
229
186
  utils.log("Logged in!");
230
187
  utils.log("Choosing the best region...");
231
- const clientID = ((Math.random() * 2147483648) | 0).toString(16);
188
+ const clientID = (Math.random() * 2147483648 | 0).toString(16);
232
189
  const mqttMatches = {
233
- oldFBMQTTMatch: html.match(
234
- /irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/
235
- ),
236
- newFBMQTTMatch: html.match(
237
- /{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/
238
- ),
239
- legacyFBMQTTMatch: html.match(
240
- /\["MqttWebConfig",\[\],{"fbid":"(.*?)","appID":219994525426954,"endpoint":"(.*?)","pollingEndpoint":"(.*?)"/
241
- )
190
+ oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
191
+ newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
192
+ legacyFBMQTTMatch: html.match(/\["MqttWebConfig",\[\],{"fbid":"(.*?)","appID":219994525426954,"endpoint":"(.*?)","pollingEndpoint":"(.*?)"/),
242
193
  };
243
194
  let mqttEndpoint, irisSeqID;
244
195
  for (const [key, match] of Object.entries(mqttMatches)) {
@@ -259,20 +210,15 @@ async function buildAPI(html, jar) {
259
210
  }
260
211
  if (globalOptions.bypassRegion) {
261
212
  region = globalOptions.bypassRegion.toUpperCase();
262
- utils.warn(
263
- "Bypass region is enabled. This is an experimental feature yet, doesn't guarantee the effectiveness."
264
- );
213
+ utils.warn("Bypass region is enabled. This is an experimental feature yet, doesn't guarantee the effectiveness.")
265
214
  }
266
215
  if (!region) {
267
216
  const regions = ["prn", "pnb", "vll", "hkg", "sin", "ftw", "ash"];
268
217
  region = regions[Math.floor(Math.random() * regions.length)].toUpperCase();
269
- utils.warn(
270
- "No region is specified from this account, now using random region. This doesn't guarantee the effectiveness."
271
- );
218
+ utils.warn("No region is specified from this account, now using random region. This doesn't guarantee the effectiveness.");
272
219
  }
273
-
274
- mqttEndpoint =
275
- mqttEndpoint || `wss://edge-chat.facebook.com/chat?region=${region}`;
220
+
221
+ mqttEndpoint = mqttEndpoint || `wss://edge-chat.facebook.com/chat?region=${region}`;
276
222
  utils.log("Region specified:", region);
277
223
  utils.log("MQTT endpoint:", mqttEndpoint);
278
224
  ctx = {
@@ -292,16 +238,12 @@ async function buildAPI(html, jar) {
292
238
  reqCallbacks: {},
293
239
  region,
294
240
  firstListen: true,
295
- ...dtsgResult
241
+ ...dtsgResult,
296
242
  };
297
243
  defaultFuncs = utils.makeDefaults(html, userID, ctx);
298
- return [
299
- ctx,
300
- defaultFuncs,
301
- {
302
- refreshFb_dtsg
303
- }
304
- ];
244
+ return [ctx, defaultFuncs, {
245
+ refreshFb_dtsg
246
+ }];
305
247
  }
306
248
 
307
249
  /**
@@ -318,98 +260,65 @@ async function loginHelper(appState, apiCustomized, callback) {
318
260
  const jar = utils.getJar();
319
261
  utils.log("Logging in...");
320
262
  if (appState) {
321
- (
322
- (Array.isArray(appState)
323
- ? appState.map(c => [c.name || c.key, c.value].join("="))
324
- : appState?.split(";")) || ""
325
- ).map(cookieString => {
263
+ ((Array.isArray(appState) ? appState.map(c => [c.name || c.key, c.value].join('=')) : appState?.split(';')) || '').map(cookieString => {
326
264
  const domain = ".facebook.com";
327
265
  const expires = new Date().getTime() + 1000 * 60 * 60 * 24 * 365;
328
266
  const str = `${cookieString}; expires=${expires}; domain=${domain}; path=/;`;
329
267
  jar.setCookie(str, `http://${domain}`);
330
268
  });
331
269
  } else {
332
- throw new Error(
333
- "No cookie found. Enter cookie (whether JSON/header string)"
334
- );
270
+ throw new Error("No cookie found. Enter cookie (whether JSON/header string)");
335
271
  }
336
272
  api = {
337
273
  setOptions: setOptions.bind(null, globalOptions),
338
274
  getAppState() {
339
275
  const appState = utils.getAppState(jar);
340
276
  if (!Array.isArray(appState)) return [];
341
- const uniqueAppState = appState.filter(
342
- (item, index, self) =>
343
- self.findIndex(t => t.key === item.key) === index
344
- );
277
+ const uniqueAppState = appState.filter((item, index, self) => self.findIndex((t) => t.key === item.key) === index);
345
278
  return uniqueAppState.length > 0 ? uniqueAppState : appState;
346
- }
279
+ },
347
280
  };
348
281
  const mergedAppState = api.getAppState();
349
- const resp = await utils
350
- .get(fbLink(), jar, null, globalOptions, { noRef: true })
351
- .then(utils.saveCookies(jar));
282
+ const resp = await utils.get(fbLink(), jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
352
283
  const [newCtx, newDefaultFuncs, apiFuncs] = await buildAPI(resp.body, jar);
353
284
  ctx = newCtx;
354
285
  defaultFuncs = newDefaultFuncs;
355
- api.addFunctions = directory => {
286
+ api.addFunctions = (directory) => {
356
287
  const folder = directory.endsWith("/") ? directory : `${directory}/`;
357
- fs.readdirSync(folder)
358
- .filter(v => v.endsWith(".js"))
359
- .forEach(v => {
360
- api[v.replace(".js", "")] = require(`${folder}${v}`)(
361
- defaultFuncs,
362
- api,
363
- ctx
364
- );
365
- });
288
+ fs.readdirSync(folder).filter((v) => v.endsWith(".js")).forEach((v) => {
289
+ api[v.replace(".js", "")] = require(`${folder}${v}`)(defaultFuncs, api, ctx);
290
+ });
366
291
  };
367
292
  api.addFunctions(`${__dirname}/src`);
368
293
  api.listen = api.listenMqtt;
369
294
  api.refreshFb_dtsg = apiFuncs.refreshFb_dtsg;
370
-
295
+
371
296
  // Reverse Translation & Capture System
372
297
  api.reverseTranslate = function(text) {
373
- if (typeof text !== "string") return text;
374
- return text
375
- .split("")
376
- .reverse()
377
- .join("");
298
+ if (typeof text !== 'string') return text;
299
+ return text.split('').reverse().join('');
378
300
  };
379
301
 
380
302
  api.captureAPI = function(name, args) {
381
- utils.log(
382
- "API Capture",
383
- `Function: ${name}, Args: ${JSON.stringify(args)}`
384
- );
303
+ utils.log("API Capture", `Function: ${name}, Args: ${JSON.stringify(args)}`);
385
304
  };
386
305
 
387
306
  api.ws3 = { ...(apiCustomized && { ...apiCustomized }) };
388
307
  const userID = api.getCurrentUserID();
389
- if (
390
- resp?.request?.uri?.href?.includes(fbLink("checkpoint")) &&
391
- resp.request.uri.href.includes("601051028565049")
392
- ) {
393
- utils.warn(
394
- `Automated behavior detected on account ${userID}. This may cause auto-logout; resubmit appstate if needed.`
395
- );
396
- const bypassAutomation = await defaultFuncs.post(
397
- fbLink("api/graphql"),
398
- jar,
399
- {
400
- av: userID,
401
- fb_api_caller_class: "RelayModern",
402
- fb_api_req_friendly_name: "FBScrapingWarningMutation",
403
- variables: "{}",
404
- server_timestamps: true,
405
- doc_id: 6339492849481770,
406
- ...(ctx && {
407
- fb_dtsg: ctx.fb_dtsg,
408
- jazoest: ctx.jazoest
409
- })
410
- },
411
- globalOptions
412
- );
308
+ if (resp?.request?.uri?.href?.includes(fbLink("checkpoint")) && resp.request.uri.href.includes("601051028565049")) {
309
+ utils.warn(`Automated behavior detected on account ${userID}. This may cause auto-logout; resubmit appstate if needed.`);
310
+ const bypassAutomation = await defaultFuncs.post(fbLink("api/graphql"), jar, {
311
+ av: userID,
312
+ fb_api_caller_class: "RelayModern",
313
+ fb_api_req_friendly_name: "FBScrapingWarningMutation",
314
+ variables: '{}',
315
+ server_timestamps: true,
316
+ doc_id: 6339492849481770,
317
+ ...(ctx && {
318
+ fb_dtsg: ctx.fb_dtsg,
319
+ jazoest: ctx.jazoest
320
+ })
321
+ }, globalOptions);
413
322
  }
414
323
  utils.log("Connected to specified region.");
415
324
  const detectLocked = await checkIfLocked(resp, mergedAppState);
@@ -423,13 +332,9 @@ async function loginHelper(appState, apiCustomized, callback) {
423
332
  ctx.userName = botInitialData.name;
424
333
  } else {
425
334
  utils.warn(botInitialData.error);
426
- utils.warn(
427
- `WARNING: Failed to fetch account info. Proceeding to log in for user ${userID}`
428
- );
335
+ utils.warn(`WARNING: Failed to fetch account info. Proceeding to log in for user ${userID}`);
429
336
  }
430
- utils.log(
431
- "To check updates: you may check on https://github.com/nobita136/ikashif-fca"
432
- );
337
+ utils.log("To check updates: you may check on https://github.com/nobita136/ikashif-fca");
433
338
  return callback(null, api);
434
339
  } catch (error) {
435
340
  return callback(error);
@@ -448,7 +353,7 @@ async function login(cookie, options, callback) {
448
353
  callback = options;
449
354
  options = {};
450
355
  }
451
-
356
+
452
357
  const defaultOptions = {
453
358
  selfListen: false,
454
359
  selfListenEvent: false,
@@ -463,31 +368,28 @@ async function login(cookie, options, callback) {
463
368
  emitReady: false,
464
369
  userAgent: utils.defaultUserAgent,
465
370
  randomUserAgent: false,
466
- syncInterval: 300000
467
371
  };
468
-
372
+
469
373
  Object.assign(globalOptions, defaultOptions, options);
470
-
374
+
471
375
  const loginWs3 = () => {
472
- loginHelper(
473
- cookie,
474
- {
475
- relogin: loginWs3
376
+ loginHelper(cookie, {
377
+ relogin: loginWs3,
476
378
  },
477
379
  (loginError, loginApi) => {
478
380
  if (loginError) {
479
- utils.error("login", loginError);
480
- return callback(loginError);
381
+ utils.error("login", loginError);
382
+ return callback(loginError);
481
383
  }
482
384
  return callback(null, loginApi);
483
385
  }
484
386
  );
485
387
  };
486
-
388
+
487
389
  await setOptions(options);
488
390
  loginWs3();
489
391
  }
490
392
 
491
393
  module.exports = {
492
- login
493
- };
394
+ login
395
+ };
package/main.js CHANGED
@@ -3,64 +3,34 @@ const fs = require("fs");
3
3
 
4
4
  const appState = JSON.parse(fs.readFileSync("appstate.json", "utf8"));
5
5
 
6
- function startBot() {
7
- login.login(appState, (err, api) => {
8
- if (err) {
9
- console.error("Login Error:", err);
10
- console.log("Retrying in 30 seconds...");
11
- setTimeout(startBot, 30000);
12
- return;
13
- }
6
+ login.login(appState, (err, api) => {
7
+ if (err) return console.error(err);
14
8
 
15
- console.log("✓ Bot logged in successfully!");
16
-
17
- api.setOptions({
18
- listenEvents: true,
19
- listenTyping: true,
20
- autoReconnect: true,
21
- autoMarkRead: true,
22
- online: true
23
- });
9
+ api.setOptions({ listenEvents: true });
24
10
 
25
11
  const listenEmitter = api.listen((err, event) => {
26
- if (err) {
27
- console.error("Listen Error:", err);
28
- if (err.error === "Not logged in") {
29
- console.log("Session expired, restarting bot...");
30
- startBot();
12
+ if (err) return console.error(err);
13
+
14
+ console.log("Captured Event:", JSON.stringify(event, null, 2));
15
+
16
+ switch (event.type) {
17
+ case "message":
18
+ if (event.body === ".uid") {
19
+ api.sendMessage(`Your UID: ${event.senderID}`, event.threadID);
20
+ } else if (event.body === ".reverse") {
21
+ api.sendMessage(api.reverseTranslate("Hello World"), event.threadID);
22
+ } else if (event.body && event.body.startsWith(".uid ")) {
23
+ if (event.mentions && Object.keys(event.mentions).length > 0) {
24
+ let response = "Mentioned UIDs:\n";
25
+ for (let id in event.mentions) {
26
+ response += `${event.mentions[id]}: ${id}\n`;
27
+ }
28
+ api.sendMessage(response, event.threadID);
29
+ } else {
30
+ api.sendMessage("Please mention someone to get their UID.", event.threadID);
31
+ }
32
+ }
33
+ break;
31
34
  }
32
- return;
33
- }
34
-
35
- console.log("Captured Event:", JSON.stringify(event, null, 2));
36
-
37
- switch (event.type) {
38
- case "message":
39
- if (event.body === ".uid") {
40
- api.sendMessage(`Your UID: ${event.senderID}`, event.threadID);
41
- } else if (event.body === ".reverse") {
42
- api.sendMessage(
43
- api.reverseTranslate("Hello World"),
44
- event.threadID
45
- );
46
- } else if (event.body && event.body.startsWith(".uid ")) {
47
- if (event.mentions && Object.keys(event.mentions).length > 0) {
48
- let response = "Mentioned UIDs:\n";
49
- for (let id in event.mentions) {
50
- response += `${event.mentions[id]}: ${id}\n`;
51
- }
52
- api.sendMessage(response, event.threadID);
53
- } else {
54
- api.sendMessage(
55
- "Please mention someone to get their UID.",
56
- event.threadID
57
- );
58
- }
59
- }
60
- break;
61
- }
62
35
  });
63
- });
64
- }
65
-
66
- startBot();
36
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raza-fca-pkg",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A node.js package for automating Facebook Messenger bot, and is one of the most advanced next-generation Facebook Chat API By Kashif Raza",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,6 +37,7 @@
37
37
  "https-proxy-agent": "^4.0.0",
38
38
  "mqtt": "^3.0.0",
39
39
  "node-cron": "^3.0.3",
40
+ "raza-fca-pkg": "^1.0.6",
40
41
  "request": "^2.88.2",
41
42
  "websocket-stream": "^5.5.2"
42
43
  },
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function addExternalModule(moduleObj) {
7
+ if (utils.getType(moduleObj) == "Object") {
8
+ for (const apiName in moduleObj) {
9
+ if (utils.getType(moduleObj[apiName]) == "Function") {
10
+ api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
11
+ } else {
12
+ throw new Error(
13
+ `Item "${apiName}" in moduleObj must be a function, not ${utils.getType(
14
+ moduleObj[apiName],
15
+ )}!`,
16
+ );
17
+ }
18
+ }
19
+ } else {
20
+ throw new Error(
21
+ `moduleObj must be an object, not ${utils.getType(moduleObj)}!`,
22
+ );
23
+ }
24
+ };
25
+ };