@dongdev/fca-unofficial 3.0.27 → 3.0.28

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/module/options.js CHANGED
@@ -1,45 +1,44 @@
1
- const { getType } = require("../src/utils/format");
2
- const { setProxy } = require("../src/utils/request");
3
- const logger = require("../func/logger");
4
- const Boolean_Option = [
5
- "online",
6
- "selfListen",
7
- "listenEvents",
8
- "updatePresence",
9
- "forceLogin",
10
- "autoMarkDelivery",
11
- "autoMarkRead",
12
- "listenTyping",
13
- "autoReconnect",
14
- "emitReady",
15
- "selfListenEvent"
16
- ];
17
- function setOptions(globalOptions, options) {
18
- for (const key of Object.keys(options || {})) {
19
- if (Boolean_Option.includes(key)) {
20
- globalOptions[key] = Boolean(options[key]);
21
- continue;
22
- }
23
- switch (key) {
24
- case "userAgent": {
25
- globalOptions.userAgent = options.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
26
- break;
27
- }
28
- case "proxy": {
29
- if (typeof options.proxy !== "string") {
30
- delete globalOptions.proxy;
31
- setProxy();
32
- } else {
33
- globalOptions.proxy = options.proxy;
34
- setProxy(globalOptions.proxy);
35
- }
36
- break;
37
- }
38
- default: {
39
- logger("setOptions Unrecognized option given to setOptions: " + key, "warn");
40
- break;
41
- }
42
- }
43
- }
44
- }
45
- module.exports = { setOptions, Boolean_Option };
1
+ const { getType } = require("../src/utils/format");
2
+ const { setProxy } = require("../src/utils/request");
3
+ const logger = require("../func/logger");
4
+ const Boolean_Option = [
5
+ "online",
6
+ "selfListen",
7
+ "listenEvents",
8
+ "updatePresence",
9
+ "forceLogin",
10
+ "autoMarkRead",
11
+ "listenTyping",
12
+ "autoReconnect",
13
+ "emitReady",
14
+ "selfListenEvent"
15
+ ];
16
+ function setOptions(globalOptions, options) {
17
+ for (const key of Object.keys(options || {})) {
18
+ if (Boolean_Option.includes(key)) {
19
+ globalOptions[key] = Boolean(options[key]);
20
+ continue;
21
+ }
22
+ switch (key) {
23
+ case "userAgent": {
24
+ globalOptions.userAgent = options.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
25
+ break;
26
+ }
27
+ case "proxy": {
28
+ if (typeof options.proxy !== "string") {
29
+ delete globalOptions.proxy;
30
+ setProxy();
31
+ } else {
32
+ globalOptions.proxy = options.proxy;
33
+ setProxy(globalOptions.proxy);
34
+ }
35
+ break;
36
+ }
37
+ default: {
38
+ logger("setOptions Unrecognized option given to setOptions: " + key, "warn");
39
+ break;
40
+ }
41
+ }
42
+ }
43
+ }
44
+ module.exports = { setOptions, Boolean_Option };
package/package.json CHANGED
@@ -1,81 +1,81 @@
1
- {
2
- "name": "@dongdev/fca-unofficial",
3
- "version": "3.0.27",
4
- "description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "exports": {
8
- ".": {
9
- "require": "./index.js",
10
- "default": "./index.js",
11
- "types": "./index.d.ts"
12
- }
13
- },
14
- "scripts": {
15
- "test": "mocha",
16
- "lint": "eslint ."
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/dongp06/fca-unofficial.git"
21
- },
22
- "keywords": [
23
- "facebook",
24
- "chat",
25
- "api",
26
- "messenger",
27
- "bot",
28
- "unofficial",
29
- "automation",
30
- "facebook-api",
31
- "facebook-chat",
32
- "facebook-messenger",
33
- "chatbot",
34
- "nodejs",
35
- "fca"
36
- ],
37
- "author": {
38
- "name": "DongDev",
39
- "url": "https://www.facebook.com/mdong.dev"
40
- },
41
- "contributors": [
42
- {
43
- "name": "DongDev",
44
- "url": "https://github.com/dongp06"
45
- }
46
- ],
47
- "license": "MIT",
48
- "bugs": {
49
- "url": "https://github.com/dongp06/fca-unofficial/issues"
50
- },
51
- "homepage": "https://github.com/dongp06/fca-unofficial#readme",
52
- "engines": {
53
- "node": ">=12.0.0"
54
- },
55
- "dependencies": {
56
- "@dongdev/fca-unofficial": "^3.0.25",
57
- "axios": "latest",
58
- "axios-cookiejar-support": "^5.0.5",
59
- "bluebird": "^3.7.2",
60
- "chalk": "^4.1.2",
61
- "cheerio": "^1.0.0-rc.10",
62
- "duplexify": "^4.1.3",
63
- "gradient-string": "^2.0.2",
64
- "https-proxy-agent": "^4.0.0",
65
- "mqtt": "^4.3.8",
66
- "npmlog": "^1.2.0",
67
- "request": "^2.53.0",
68
- "sequelize": "^6.37.6",
69
- "sqlite3": "^5.1.7",
70
- "totp-generator": "^1.0.0",
71
- "ws": "^8.18.1"
72
- },
73
- "devDependencies": {
74
- "eslint": "^8.50.0",
75
- "mocha": "^10.2.0"
76
- },
77
- "publishConfig": {
78
- "access": "public",
79
- "registry": "https://registry.npmjs.org/"
80
- }
81
- }
1
+ {
2
+ "name": "@dongdev/fca-unofficial",
3
+ "version": "3.0.28",
4
+ "description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./index.js",
10
+ "default": "./index.js",
11
+ "types": "./index.d.ts"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "test": "mocha",
16
+ "lint": "eslint ."
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/dongp06/fca-unofficial.git"
21
+ },
22
+ "keywords": [
23
+ "facebook",
24
+ "chat",
25
+ "api",
26
+ "messenger",
27
+ "bot",
28
+ "unofficial",
29
+ "automation",
30
+ "facebook-api",
31
+ "facebook-chat",
32
+ "facebook-messenger",
33
+ "chatbot",
34
+ "nodejs",
35
+ "fca"
36
+ ],
37
+ "author": {
38
+ "name": "DongDev",
39
+ "url": "https://www.facebook.com/mdong.dev"
40
+ },
41
+ "contributors": [
42
+ {
43
+ "name": "DongDev",
44
+ "url": "https://github.com/dongp06"
45
+ }
46
+ ],
47
+ "license": "MIT",
48
+ "bugs": {
49
+ "url": "https://github.com/dongp06/fca-unofficial/issues"
50
+ },
51
+ "homepage": "https://github.com/dongp06/fca-unofficial#readme",
52
+ "engines": {
53
+ "node": ">=12.0.0"
54
+ },
55
+ "dependencies": {
56
+ "@dongdev/fca-unofficial": "^3.0.25",
57
+ "axios": "latest",
58
+ "axios-cookiejar-support": "^5.0.5",
59
+ "bluebird": "^3.7.2",
60
+ "chalk": "^4.1.2",
61
+ "cheerio": "^1.0.0-rc.10",
62
+ "duplexify": "^4.1.3",
63
+ "gradient-string": "^2.0.2",
64
+ "https-proxy-agent": "^4.0.0",
65
+ "mqtt": "^4.3.8",
66
+ "npmlog": "^1.2.0",
67
+ "request": "^2.53.0",
68
+ "sequelize": "^6.37.6",
69
+ "sqlite3": "^5.1.7",
70
+ "totp-generator": "^1.0.0",
71
+ "ws": "^8.18.1"
72
+ },
73
+ "devDependencies": {
74
+ "eslint": "^8.50.0",
75
+ "mocha": "^10.2.0"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public",
79
+ "registry": "https://registry.npmjs.org/"
80
+ }
81
+ }
@@ -3,17 +3,17 @@
3
3
  const { generateOfflineThreadingID, getType } = require("../../utils/format");
4
4
 
5
5
  module.exports = function (defaultFuncs, api, ctx) {
6
- function changeAdminStatusNoMqtt(threadID, adminID, adminStatus) {
7
- if (getType(threadID) !== "String") throw { error: "changeAdminStatus: threadID must be a string" };
8
- if (getType(adminID) !== "String" && getType(adminID) !== "Array") throw { error: "changeAdminStatus: adminID must be a string or an array" };
9
- if (getType(adminStatus) !== "Boolean") throw { error: "changeAdminStatus: adminStatus must be true or false" };
10
- if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
11
- const reqID = ++ctx.wsReqNumber;
12
- let wsContent = {
13
- request_id: reqID,
14
- type: 3,
15
- payload: {
16
- version_id: '3816854585040595',
6
+ function changeAdminStatusNoMqtt(threadID, adminID, adminStatus) {
7
+ if (getType(threadID) !== "String") throw { error: "changeAdminStatus: threadID must be a string" };
8
+ if (getType(adminID) !== "String" && getType(adminID) !== "Array") throw { error: "changeAdminStatus: adminID must be a string or an array" };
9
+ if (getType(adminStatus) !== "Boolean") throw { error: "changeAdminStatus: adminStatus must be true or false" };
10
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
11
+ const reqID = ++ctx.wsReqNumber;
12
+ let wsContent = {
13
+ request_id: reqID,
14
+ type: 3,
15
+ payload: {
16
+ version_id: '3816854585040595',
17
17
  tasks: [],
18
18
  epoch_id: generateOfflineThreadingID(),
19
19
  data_trace_id: null
@@ -39,20 +39,20 @@ module.exports = function (defaultFuncs, api, ctx) {
39
39
  failure_count: null
40
40
  });
41
41
  }
42
- wsContent.payload = JSON.stringify(wsContent.payload);
43
- return new Promise((resolve, reject) => {
44
- if (!ctx.mqttClient) {
45
- return reject(new Error("Not connected to MQTT"));
46
- }
47
- ctx.mqttClient.publish("/ls_req", JSON.stringify(wsContent), {}, (err) => {
48
- if (err) return reject(err);
49
- resolve();
50
- });
51
- });
52
- };
53
- function changeAdminStatusMqtt(threadID, adminID, adminStatus) {
54
- if (!ctx.mqttClient) {
55
- throw new Error("Not connected to MQTT");
42
+ wsContent.payload = JSON.stringify(wsContent.payload);
43
+ return new Promise((resolve, reject) => {
44
+ if (!ctx.mqttClient) {
45
+ return reject(new Error("Not connected to MQTT"));
46
+ }
47
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(wsContent), {}, (err) => {
48
+ if (err) return reject(err);
49
+ resolve();
50
+ });
51
+ });
52
+ };
53
+ function changeAdminStatusMqtt(threadID, adminID, adminStatus) {
54
+ if (!ctx.mqttClient) {
55
+ throw new Error("Not connected to MQTT");
56
56
  }
57
57
  if (getType(threadID) !== "String") {
58
58
  throw { error: "changeAdminStatus: threadID must be a string" };
@@ -93,34 +93,34 @@ module.exports = function (defaultFuncs, api, ctx) {
93
93
  task_id: 1
94
94
  });
95
95
  }
96
- if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
97
- const reqID = ++ctx.wsReqNumber;
98
- const form = JSON.stringify({
99
- app_id: "2220391788200892",
100
- payload: JSON.stringify({
101
- epoch_id: epochID,
102
- tasks: tasks,
103
- version_id: "8798795233522156"
104
- }),
105
- request_id: reqID,
106
- type: 3
107
- });
108
- return new Promise((resolve, reject) => {
109
- ctx.mqttClient.publish("/ls_req", form, {}, (err) => {
110
- if (err) return reject(err);
111
- resolve();
112
- });
113
- });
114
- };
115
- return function changeAdminStatus(threadID, adminID, adminStatus) {
116
- if (ctx.mqttClient) {
117
- try {
118
- return changeAdminStatusMqtt(threadID, adminID, adminStatus);
119
- } catch (e) {
120
- return changeAdminStatusNoMqtt(threadID, adminID, adminStatus);
121
- }
122
- } else {
123
- return changeAdminStatusNoMqtt(threadID, adminID, adminStatus);
124
- }
125
- };
126
- };
96
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
97
+ const reqID = ++ctx.wsReqNumber;
98
+ const form = JSON.stringify({
99
+ app_id: "2220391788200892",
100
+ payload: JSON.stringify({
101
+ epoch_id: epochID,
102
+ tasks: tasks,
103
+ version_id: "8798795233522156"
104
+ }),
105
+ request_id: reqID,
106
+ type: 3
107
+ });
108
+ return new Promise((resolve, reject) => {
109
+ ctx.mqttClient.publish("/ls_req", form, {}, (err) => {
110
+ if (err) return reject(err);
111
+ resolve();
112
+ });
113
+ });
114
+ };
115
+ return function changeAdminStatus(threadID, adminID, adminStatus) {
116
+ if (ctx.mqttClient) {
117
+ try {
118
+ return changeAdminStatusMqtt(threadID, adminID, adminStatus);
119
+ } catch (e) {
120
+ return changeAdminStatusNoMqtt(threadID, adminID, adminStatus);
121
+ }
122
+ } else {
123
+ return changeAdminStatusNoMqtt(threadID, adminID, adminStatus);
124
+ }
125
+ };
126
+ };
@@ -48,30 +48,30 @@ module.exports = function (defaultFuncs, api, ctx) {
48
48
  });
49
49
  return returnPromise;
50
50
  };
51
- function changeThreadEmojiMqtt(emoji, threadID, callback) {
52
- if (!ctx.mqttClient) {
53
- throw new Error("Not connected to MQTT");
54
- }
55
- if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
56
- const reqID = ++ctx.wsReqNumber;
57
- var resolveFunc = function () { };
58
- var rejectFunc = function () { };
59
- var returnPromise = new Promise(function (resolve, reject) {
60
- resolveFunc = resolve;
61
- rejectFunc = reject;
62
- });
63
- const done = (err, data) => {
64
- if (err) {
65
- if (callback) callback(err);
66
- return rejectFunc(err);
67
- }
68
- if (callback) callback(null, data);
69
- resolveFunc(data);
70
- };
71
- var form = JSON.stringify({
72
- "app_id": "2220391788200892",
73
- "payload": JSON.stringify({
74
- epoch_id: generateOfflineThreadingID(),
51
+ function changeThreadEmojiMqtt(emoji, threadID, callback) {
52
+ if (!ctx.mqttClient) {
53
+ throw new Error("Not connected to MQTT");
54
+ }
55
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
56
+ const reqID = ++ctx.wsReqNumber;
57
+ var resolveFunc = function () { };
58
+ var rejectFunc = function () { };
59
+ var returnPromise = new Promise(function (resolve, reject) {
60
+ resolveFunc = resolve;
61
+ rejectFunc = reject;
62
+ });
63
+ const done = (err, data) => {
64
+ if (err) {
65
+ if (callback) callback(err);
66
+ return rejectFunc(err);
67
+ }
68
+ if (callback) callback(null, data);
69
+ resolveFunc(data);
70
+ };
71
+ var form = JSON.stringify({
72
+ "app_id": "2220391788200892",
73
+ "payload": JSON.stringify({
74
+ epoch_id: generateOfflineThreadingID(),
75
75
  tasks: [
76
76
  {
77
77
  failure_count: null,
@@ -86,26 +86,26 @@ module.exports = function (defaultFuncs, api, ctx) {
86
86
  task_id: Math.random() * 1001 << 0
87
87
  }
88
88
  ],
89
- version_id: '8798795233522156'
90
- }),
91
- "request_id": reqID,
92
- "type": 3
93
- });
94
- ctx.mqttClient.publish("/ls_req", form, { qos: 1, retain: false }, (err) => {
95
- if (err) return done(err);
96
- done(null, { success: true });
97
- });
98
- return returnPromise;
99
- };
100
- return function changeThreadEmoji(emoji, threadID, callback) {
101
- if (ctx.mqttClient) {
102
- try {
103
- return changeThreadEmojiMqtt(emoji, threadID, callback);
104
- } catch (e) {
105
- return changeThreadEmojiNoMqtt(emoji, threadID, callback);
106
- }
107
- } else {
108
- return changeThreadEmojiNoMqtt(emoji, threadID, callback);
109
- }
110
- };
111
- };
89
+ version_id: '8798795233522156'
90
+ }),
91
+ "request_id": reqID,
92
+ "type": 3
93
+ });
94
+ ctx.mqttClient.publish("/ls_req", form, { qos: 1, retain: false }, (err) => {
95
+ if (err) return done(err);
96
+ done(null, { success: true });
97
+ });
98
+ return returnPromise;
99
+ };
100
+ return function changeThreadEmoji(emoji, threadID, callback) {
101
+ if (ctx.mqttClient) {
102
+ try {
103
+ return changeThreadEmojiMqtt(emoji, threadID, callback);
104
+ } catch (e) {
105
+ return changeThreadEmojiNoMqtt(emoji, threadID, callback);
106
+ }
107
+ } else {
108
+ return changeThreadEmojiNoMqtt(emoji, threadID, callback);
109
+ }
110
+ };
111
+ };
@@ -1,46 +1,46 @@
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
- if (!ctx.mqttClient) {
10
- return reject(new Error("Not connected to MQTT"));
11
- }
12
- const payload = {
13
- epoch_id: generateOfflineThreadingID(),
14
- tasks: [
15
- {
16
- failure_count: null,
17
- label: "163",
18
- payload: JSON.stringify({
19
- question_text: questionText,
20
- thread_key: threadID,
21
- options: options,
22
- sync_group: 1,
23
- }),
24
- queue_name: "poll_creation",
25
- task_id: Math.floor(Math.random() * 1001),
26
- },
27
- ],
28
- version_id: "34195258046739157",
29
- };
30
-
31
- const form = JSON.stringify({
32
- app_id: "2220391788200892",
33
- payload: JSON.stringify(payload),
34
- request_id: ++count_req,
35
- type: 3,
36
- });
37
-
38
- try {
39
- ctx.mqttClient.publish("/ls_req", form);
40
- resolve();
41
- } catch (err) {
42
- reject(err);
43
- }
44
- });
45
- };
46
- };
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
+ if (!ctx.mqttClient) {
10
+ return reject(new Error("Not connected to MQTT"));
11
+ }
12
+ const payload = {
13
+ epoch_id: generateOfflineThreadingID(),
14
+ tasks: [
15
+ {
16
+ failure_count: null,
17
+ label: "163",
18
+ payload: JSON.stringify({
19
+ question_text: questionText,
20
+ thread_key: threadID,
21
+ options: options,
22
+ sync_group: 1,
23
+ }),
24
+ queue_name: "poll_creation",
25
+ task_id: Math.floor(Math.random() * 1001),
26
+ },
27
+ ],
28
+ version_id: "34195258046739157",
29
+ };
30
+
31
+ const form = JSON.stringify({
32
+ app_id: "2220391788200892",
33
+ payload: JSON.stringify(payload),
34
+ request_id: ++count_req,
35
+ type: 3,
36
+ });
37
+
38
+ try {
39
+ ctx.mqttClient.publish("/ls_req", form);
40
+ resolve();
41
+ } catch (err) {
42
+ reject(err);
43
+ }
44
+ });
45
+ };
46
+ };
@@ -2,29 +2,29 @@
2
2
 
3
3
  const { generateOfflineThreadingID } = require("../../utils/format");
4
4
 
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- return async function forwardMessage(threadID, forwardedMsgID, callback) {
7
- let resolveFunc, rejectFunc;
8
- const returnPromise = new Promise((resolve, reject) => {
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return async function forwardMessage(threadID, forwardedMsgID, callback) {
7
+ let resolveFunc, rejectFunc;
8
+ const returnPromise = new Promise((resolve, reject) => {
9
9
  resolveFunc = resolve;
10
10
  rejectFunc = reject;
11
11
  });
12
- if (!callback) {
13
- callback = (err, data) => {
14
- if (err) return rejectFunc(err);
15
- resolveFunc(data);
16
- };
17
- }
18
- if (!ctx.mqttClient) {
19
- const err = new Error("Not connected to MQTT");
20
- callback?.(err);
21
- rejectFunc(err);
22
- return returnPromise;
23
- }
24
- let count_req = 0
25
- const payload = {
26
- epoch_id: generateOfflineThreadingID(),
27
- tasks: [
12
+ if (!callback) {
13
+ callback = (err, data) => {
14
+ if (err) return rejectFunc(err);
15
+ resolveFunc(data);
16
+ };
17
+ }
18
+ if (!ctx.mqttClient) {
19
+ const err = new Error("Not connected to MQTT");
20
+ callback?.(err);
21
+ rejectFunc(err);
22
+ return returnPromise;
23
+ }
24
+ let count_req = 0
25
+ const payload = {
26
+ epoch_id: generateOfflineThreadingID(),
27
+ tasks: [
28
28
  {
29
29
  failure_count: null,
30
30
  label: "46",
@@ -47,11 +47,11 @@ module.exports = function (defaultFuncs, api, ctx) {
47
47
  };
48
48
  const form = JSON.stringify({
49
49
  app_id: "772021112871879",
50
- payload: JSON.stringify(payload),
51
- "request_id": ++count_req,
52
- "type": 3
53
- });
54
- ctx.mqttClient.publish("/ls_req", form);
55
- return returnPromise;
56
- };
57
- };
50
+ payload: JSON.stringify(payload),
51
+ "request_id": ++count_req,
52
+ "type": 3
53
+ });
54
+ ctx.mqttClient.publish("/ls_req", form);
55
+ return returnPromise;
56
+ };
57
+ };