fca-nx 6.6.6 → 6.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fca-nx",
3
- "version": "6.6.6",
3
+ "version": "6.6.7",
4
4
  "description": "Facebook Messenger API for Node.js — Fast, Secure, and Feature-Rich",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ const log = require("../../../func/logAdapter");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const { formatID } = require("../../utils/format");
6
+
7
+ module.exports = function(defaultFuncs, api, ctx) {
8
+ return function addFriend(userID, callback) {
9
+ let resolveFunc = function() {};
10
+ let rejectFunc = function() {};
11
+
12
+ const returnPromise = new Promise(function(resolve, reject) {
13
+ resolveFunc = resolve;
14
+ rejectFunc = reject;
15
+ });
16
+
17
+ if (typeof callback !== "function") {
18
+ callback = function(err, data) {
19
+ if (err) {
20
+ return rejectFunc(err);
21
+ }
22
+
23
+ resolveFunc(data);
24
+ };
25
+ }
26
+
27
+ /*
28
+ * Validate user ID
29
+ */
30
+ try {
31
+ userID = formatID(userID);
32
+ } catch (err) {
33
+ return callback(err);
34
+ }
35
+
36
+ if (!userID) {
37
+ return callback(
38
+ new Error("Invalid user ID")
39
+ );
40
+ }
41
+
42
+ if (String(userID) === String(ctx.userID)) {
43
+ return callback(
44
+ new Error("You cannot send a friend request to yourself")
45
+ );
46
+ }
47
+
48
+ /*
49
+ * Facebook friend request endpoint
50
+ */
51
+ const form = {
52
+ uid: String(userID),
53
+ viewer_id: String(ctx.userID),
54
+ source: "profile_button",
55
+ ref: "profile",
56
+ floc: "profile",
57
+ nctr: "profile"
58
+ };
59
+
60
+ defaultFuncs
61
+ .post(
62
+ "https://www.facebook.com/ajax/friends/requests/send/",
63
+ ctx.jar,
64
+ form
65
+ )
66
+ .then(
67
+ parseAndCheckLogin(ctx, defaultFuncs)
68
+ )
69
+ .then(function(resData) {
70
+ /*
71
+ * Facebook may return different response
72
+ * structures depending on the account/session.
73
+ */
74
+ if (!resData) {
75
+ throw new Error(
76
+ "Empty response from Facebook"
77
+ );
78
+ }
79
+
80
+ if (
81
+ resData.error ||
82
+ resData.errors ||
83
+ resData.errorDescription
84
+ ) {
85
+ throw resData;
86
+ }
87
+
88
+ /*
89
+ * Some responses contain:
90
+ *
91
+ * payload.error
92
+ * payload.err
93
+ * payload.success
94
+ */
95
+ const payload = resData.payload;
96
+
97
+ if (payload) {
98
+ if (
99
+ payload.error ||
100
+ payload.err
101
+ ) {
102
+ throw payload;
103
+ }
104
+
105
+ if (
106
+ payload.errorDescription
107
+ ) {
108
+ throw new Error(
109
+ payload.errorDescription
110
+ );
111
+ }
112
+ }
113
+
114
+ return resData;
115
+ })
116
+ .then(function(resData) {
117
+ /*
118
+ * Return a simple result instead of
119
+ * exposing Facebook's whole response.
120
+ */
121
+ const result = {
122
+ success: true,
123
+ userID: String(userID),
124
+ response: resData
125
+ };
126
+
127
+ return callback(
128
+ null,
129
+ result
130
+ );
131
+ })
132
+ .catch(function(err) {
133
+ log.error(
134
+ "addFriend",
135
+ err
136
+ );
137
+
138
+ return callback(err);
139
+ });
140
+
141
+ return returnPromise;
142
+ };
143
+ };
@@ -5,8 +5,8 @@ const { getType } = require("../../utils/format");
5
5
 
6
6
  const httpPostFactory = function (defaultFuncs, api, ctx) {
7
7
  return function httpPost(url, form, callback, notAPI) {
8
- let resolveFunc = () => { };
9
- let rejectFunc = () => { };
8
+ let resolveFunc;
9
+ let rejectFunc;
10
10
 
11
11
  const returnPromise = new Promise((resolve, reject) => {
12
12
  resolveFunc = resolve;
@@ -23,12 +23,16 @@ const httpPostFactory = function (defaultFuncs, api, ctx) {
23
23
 
24
24
  form = form || {};
25
25
 
26
- callback =
27
- callback ||
28
- function (err, data) {
29
- if (err) return rejectFunc(err);
26
+ const handleCallback = (err, data) => {
27
+ if (typeof callback === "function") {
28
+ callback(err, data);
29
+ }
30
+ if (err) {
31
+ rejectFunc(err);
32
+ } else {
30
33
  resolveFunc(data);
31
- };
34
+ }
35
+ };
32
36
 
33
37
  const executor = notAPI ? post : defaultFuncs.post;
34
38
 
@@ -38,11 +42,11 @@ const httpPostFactory = function (defaultFuncs, api, ctx) {
38
42
  if (typeof data === "object") {
39
43
  data = JSON.stringify(data, null, 2);
40
44
  }
41
- callback(null, data);
45
+ handleCallback(null, data);
42
46
  })
43
47
  .catch((err) => {
44
- console.error("httpPost", err);
45
- return callback(err);
48
+ console.error("httpPost error:", err);
49
+ handleCallback(err, null);
46
50
  });
47
51
 
48
52
  return returnPromise;
@@ -8,32 +8,37 @@ function generateOfflineThreadingId() {
8
8
 
9
9
  module.exports = function (defaultFuncs, api, ctx) {
10
10
  return function editMessage(text, messageID, callback) {
11
- let resolveFunc = () => {};
12
- let rejectFunc = () => {};
11
+ let resolveFunc;
12
+ let rejectFunc;
13
+
13
14
  const returnPromise = new Promise((resolve, reject) => {
14
15
  resolveFunc = resolve;
15
16
  rejectFunc = reject;
16
17
  });
17
18
 
18
- if (!callback) {
19
- callback = (err, data) => {
20
- if (err) return rejectFunc(err);
19
+ const handleCallback = (err, data) => {
20
+ if (typeof callback === "function") {
21
+ callback(err, data);
22
+ }
23
+ if (err) {
24
+ rejectFunc(err);
25
+ } else {
21
26
  resolveFunc(data);
22
- };
23
- }
27
+ }
28
+ };
24
29
 
25
30
  if (!ctx.mqttClient) {
26
- callback({ error: "Not connected to MQTT" });
31
+ handleCallback({ error: "Not connected to MQTT" });
27
32
  return returnPromise;
28
33
  }
29
34
 
30
35
  if (!messageID || !text) {
31
- callback({ error: "messageID and text are required." });
36
+ handleCallback({ error: "messageID and text are required." });
32
37
  return returnPromise;
33
38
  }
34
39
 
35
- ctx.wsReqNumber += 1;
36
- ctx.wsTaskNumber += 1;
40
+ ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
41
+ ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
37
42
 
38
43
  const reqID = ctx.wsReqNumber;
39
44
 
@@ -42,49 +47,60 @@ module.exports = function (defaultFuncs, api, ctx) {
42
47
  payload: JSON.stringify({
43
48
  data_trace_id: null,
44
49
  epoch_id: parseInt(generateOfflineThreadingId()),
45
- tasks: [{
46
- failure_count: null,
47
- label: "742",
48
- payload: JSON.stringify({
49
- message_id: messageID,
50
- text: text,
51
- }),
52
- queue_name: "edit_message",
53
- task_id: ctx.wsTaskNumber,
54
- }],
50
+ tasks: [
51
+ {
52
+ failure_count: null,
53
+ label: "742",
54
+ payload: JSON.stringify({
55
+ message_id: messageID,
56
+ text: text,
57
+ }),
58
+ queue_name: "edit_message",
59
+ task_id: ctx.wsTaskNumber,
60
+ },
61
+ ],
55
62
  version_id: "6903494529735864",
56
63
  }),
57
64
  request_id: reqID,
58
- type: 3
65
+ type: 3,
59
66
  };
60
67
 
61
- ctx.mqttClient.publish("/ls_req", JSON.stringify(context), { qos: 1, retain: false });
62
-
63
- const timeout = setTimeout(() => {
64
- ctx.mqttClient.removeListener("message", handleRes);
65
- resolveFunc({ messageID, body: text });
66
- }, 5000);
68
+ const cleanup = () => {
69
+ if (ctx.mqttClient) {
70
+ ctx.mqttClient.removeListener("message", handleRes);
71
+ }
72
+ };
67
73
 
68
74
  const handleRes = (topic, message) => {
69
75
  if (topic !== "/ls_resp") return;
70
76
  try {
71
77
  let jsonMsg = JSON.parse(message.toString());
72
78
  if (!jsonMsg.payload) return;
73
- jsonMsg.payload = JSON.parse(jsonMsg.payload);
79
+
80
+ if (typeof jsonMsg.payload === "string") {
81
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
82
+ }
83
+
74
84
  if (jsonMsg.request_id != reqID) return;
75
85
 
76
86
  clearTimeout(timeout);
77
- ctx.mqttClient.removeListener("message", handleRes);
78
-
79
- callback(undefined, { messageID, body: text });
87
+ cleanup();
88
+ handleCallback(null, { messageID, body: text });
80
89
  } catch (e) {
81
90
  clearTimeout(timeout);
82
- ctx.mqttClient.removeListener("message", handleRes);
83
- callback(undefined, { messageID, body: text });
91
+ cleanup();
92
+ handleCallback(null, { messageID, body: text });
84
93
  }
85
94
  };
86
95
 
96
+ const timeout = setTimeout(() => {
97
+ cleanup();
98
+ handleCallback(null, { messageID, body: text });
99
+ }, 5000);
100
+
87
101
  ctx.mqttClient.on("message", handleRes);
102
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(context), { qos: 1, retain: false });
103
+
88
104
  return returnPromise;
89
105
  };
90
106
  };
@@ -1,14 +1,12 @@
1
1
  /**
2
2
  * Create by Donix-VN (DongDev)
3
- * Modified by MueidMursalinRifat
4
- * Don't change credit
3
+ * Modified by MueidMursalinRifat & Xalman
5
4
  * Send a message using MQTT.
6
- * @param {string} text - The text of the message to send.
5
+ * @param {string|object} msg - The message object or text to send.
7
6
  * @param {string} threadID - The ID of the thread to send the message to.
8
- * @param {string} [msgReplace] - Optional. The message ID of the message to replace.
9
- * @param {Array<Buffer|Stream>} [attachments] - Optional. The attachments to send with the message.
10
- * @param {function} [callback] - Optional. The callback function to call when the message is sent.
11
- * @returns {Promise<object>} A promise that resolves with the bodies of the sent message.
7
+ * @param {function} [callback] - Optional. The callback function.
8
+ * @param {string} [replyToMessage] - Optional. Message ID to reply to.
9
+ * @returns {Promise<object>} A promise that resolves with the sent message metadata.
12
10
  */
13
11
 
14
12
  "use strict";
@@ -173,6 +171,19 @@ module.exports = function (defaultFuncs, api, ctx) {
173
171
  metadata_dataclass: JSON.stringify({ media_accessibility_metadata: { alt_text: null } })
174
172
  };
175
173
 
174
+ // --- FIX: TEXT EFFECTS SUPPORT ---
175
+ if (m.text_effect_ids) {
176
+ let effectArray = [];
177
+ if (Array.isArray(m.text_effect_ids)) {
178
+ effectArray = m.text_effect_ids;
179
+ } else if (typeof m.text_effect_ids === "string") {
180
+ effectArray = [m.text_effect_ids];
181
+ }
182
+ if (effectArray.length > 0) {
183
+ payload0.text_effect_ids = effectArray.map(id => String(id));
184
+ }
185
+ }
186
+
176
187
  const mentionData = buildMentionData(m, baseBody);
177
188
  if (mentionData) payload0.mention_data = mentionData;
178
189