@dongdev/fca-unofficial 3.0.23 → 3.0.27
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/CHANGELOG.md +6 -0
- package/DOCS.md +3 -3
- package/Fca_Database/database.sqlite +0 -0
- package/LICENSE-MIT +1 -1
- package/README.md +1 -1
- package/index.d.ts +1 -1
- package/module/config.js +3 -7
- package/module/login.js +2 -4
- package/module/loginHelper.js +479 -287
- package/package.json +6 -7
- package/src/api/messaging/changeAdminStatus.js +56 -52
- package/src/api/messaging/changeGroupImage.js +2 -1
- package/src/api/messaging/changeThreadEmoji.js +47 -42
- package/src/api/messaging/createPoll.js +46 -43
- package/src/api/messaging/deleteMessage.js +110 -30
- package/src/api/messaging/forwardAttachment.js +28 -22
- package/src/api/messaging/removeUserFromGroup.js +11 -55
- package/src/api/messaging/sendMessage.js +15 -17
- package/src/api/messaging/sendTypingIndicator.js +23 -16
- package/src/api/messaging/setMessageReaction.js +91 -76
- package/src/api/messaging/setTitle.js +47 -42
- package/src/api/messaging/shareContact.js +1 -1
- package/src/api/messaging/uploadAttachment.js +471 -73
- package/src/api/socket/core/connectMqtt.js +0 -5
- package/src/api/socket/core/emitAuth.js +1 -8
- package/src/api/socket/core/getSeqID.js +292 -10
- package/src/api/socket/listenMqtt.js +15 -7
- package/src/utils/client.js +2 -312
- package/src/utils/cookies.js +68 -0
- package/src/utils/format.js +117 -90
- package/src/utils/loginParser.js +347 -0
- package/src/utils/messageFormat.js +1173 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dongdev/fca-unofficial",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.27",
|
|
4
4
|
"description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/
|
|
20
|
+
"url": "git+https://github.com/dongp06/fca-unofficial.git"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"facebook",
|
|
@@ -41,18 +41,19 @@
|
|
|
41
41
|
"contributors": [
|
|
42
42
|
{
|
|
43
43
|
"name": "DongDev",
|
|
44
|
-
"url": "https://github.com/
|
|
44
|
+
"url": "https://github.com/dongp06"
|
|
45
45
|
}
|
|
46
46
|
],
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"bugs": {
|
|
49
|
-
"url": "https://github.com/
|
|
49
|
+
"url": "https://github.com/dongp06/fca-unofficial/issues"
|
|
50
50
|
},
|
|
51
|
-
"homepage": "https://github.com/
|
|
51
|
+
"homepage": "https://github.com/dongp06/fca-unofficial#readme",
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=12.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
+
"@dongdev/fca-unofficial": "^3.0.25",
|
|
56
57
|
"axios": "latest",
|
|
57
58
|
"axios-cookiejar-support": "^5.0.5",
|
|
58
59
|
"bluebird": "^3.7.2",
|
|
@@ -73,8 +74,6 @@
|
|
|
73
74
|
"eslint": "^8.50.0",
|
|
74
75
|
"mocha": "^10.2.0"
|
|
75
76
|
},
|
|
76
|
-
"optionalDependencies": {},
|
|
77
|
-
"peerDependencies": {},
|
|
78
77
|
"publishConfig": {
|
|
79
78
|
"access": "public",
|
|
80
79
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -3,15 +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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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',
|
|
15
17
|
tasks: [],
|
|
16
18
|
epoch_id: generateOfflineThreadingID(),
|
|
17
19
|
data_trace_id: null
|
|
@@ -37,12 +39,20 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
37
39
|
failure_count: null
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
|
-
wsContent.payload = JSON.stringify(wsContent.payload);
|
|
41
|
-
return new Promise((resolve, reject) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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");
|
|
46
56
|
}
|
|
47
57
|
if (getType(threadID) !== "String") {
|
|
48
58
|
throw { error: "changeAdminStatus: threadID must be a string" };
|
|
@@ -83,40 +93,34 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
83
93
|
task_id: 1
|
|
84
94
|
});
|
|
85
95
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
changeAdminStatusNoMqtt(threadID, adminID, adminStatus);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
};
|
|
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
|
+
};
|
|
@@ -7,10 +7,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
7
7
|
function handleUpload(image) {
|
|
8
8
|
const form = {
|
|
9
9
|
images_only: "true",
|
|
10
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
10
11
|
"attachment[]": image
|
|
11
12
|
};
|
|
12
13
|
return defaultFuncs
|
|
13
|
-
.postFormData("https://
|
|
14
|
+
.postFormData("https://www.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
|
14
15
|
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
15
16
|
.then(resData => {
|
|
16
17
|
if (resData.error) throw resData;
|
|
@@ -48,28 +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
|
-
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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(),
|
|
73
75
|
tasks: [
|
|
74
76
|
{
|
|
75
77
|
failure_count: null,
|
|
@@ -84,23 +86,26 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
84
86
|
task_id: Math.random() * 1001 << 0
|
|
85
87
|
}
|
|
86
88
|
],
|
|
87
|
-
version_id: '8798795233522156'
|
|
88
|
-
}),
|
|
89
|
-
"request_id":
|
|
90
|
-
"type": 3
|
|
91
|
-
});
|
|
92
|
-
mqttClient.publish(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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,43 +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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
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,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const log = require("npmlog");
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
4
|
+
const { getType, generateOfflineThreadingID } = require("../../utils/format");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
7
|
return function deleteMessage(messageOrMessages, callback) {
|
|
8
|
-
let resolveFunc = function() {};
|
|
9
|
-
let rejectFunc = function() {};
|
|
10
|
-
const returnPromise = new Promise(function(resolve, reject) {
|
|
8
|
+
let resolveFunc = function () {};
|
|
9
|
+
let rejectFunc = function () {};
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
11
|
resolveFunc = resolve;
|
|
12
12
|
rejectFunc = reject;
|
|
13
13
|
});
|
|
14
14
|
if (!callback) {
|
|
15
|
-
callback = function(err) {
|
|
15
|
+
callback = function (err) {
|
|
16
16
|
if (err) {
|
|
17
17
|
return rejectFunc(err);
|
|
18
18
|
}
|
|
@@ -20,36 +20,116 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const form = {
|
|
24
|
-
client: "mercury"
|
|
25
|
-
};
|
|
26
|
-
|
|
27
23
|
if (getType(messageOrMessages) !== "Array") {
|
|
28
24
|
messageOrMessages = [messageOrMessages];
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if (!ctx || !ctx.mqttClient) {
|
|
28
|
+
const err = new Error("Not connected to MQTT");
|
|
29
|
+
callback(err);
|
|
30
|
+
return rejectFunc(err);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
const epochId = String(generateOfflineThreadingID());
|
|
34
|
+
if (typeof ctx.wsTaskNumber !== "number") ctx.wsTaskNumber = 0;
|
|
35
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
36
|
+
|
|
37
|
+
const tasks = messageOrMessages.map((threadID) => {
|
|
38
|
+
const threadKey = String(threadID);
|
|
39
|
+
const taskPayload = `{"thread_key":${threadKey},"remove_type":0,"sync_group":1}`;
|
|
40
|
+
return {
|
|
41
|
+
failure_count: null,
|
|
42
|
+
label: "146",
|
|
43
|
+
payload: taskPayload,
|
|
44
|
+
queue_name: threadKey,
|
|
45
|
+
task_id: ++ctx.wsTaskNumber,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const payload = `{"epoch_id":${epochId},"tasks":${JSON.stringify(
|
|
50
|
+
tasks,
|
|
51
|
+
)},"version_id":"25909428212080747"}`;
|
|
52
|
+
|
|
53
|
+
const reqID = ++ctx.wsReqNumber;
|
|
54
|
+
const form = JSON.stringify({
|
|
55
|
+
app_id: "2220391788200892",
|
|
56
|
+
payload,
|
|
57
|
+
request_id: reqID,
|
|
58
|
+
type: 3,
|
|
59
|
+
});
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
let timer = null;
|
|
62
|
+
|
|
63
|
+
const cleanup = () => {
|
|
64
|
+
if (timer) {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
timer = null;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
ctx.mqttClient?.removeListener("message", handleRes);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// ignore
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handleRes = (topic, message) => {
|
|
76
|
+
if (topic !== "/ls_resp") return;
|
|
77
|
+
let msg;
|
|
78
|
+
try {
|
|
79
|
+
msg = JSON.parse(message.toString());
|
|
80
|
+
} catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (msg.request_id !== reqID) return;
|
|
84
|
+
cleanup();
|
|
85
|
+
try {
|
|
86
|
+
msg.payload =
|
|
87
|
+
typeof msg.payload === "string"
|
|
88
|
+
? JSON.parse(msg.payload)
|
|
89
|
+
: msg.payload;
|
|
90
|
+
} catch {}
|
|
91
|
+
callback(null, { success: true, response: msg.payload });
|
|
92
|
+
resolveFunc({ success: true, response: msg.payload });
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
ctx.mqttClient.on("message", handleRes);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
cleanup();
|
|
99
|
+
log.error("deleteMessage", err);
|
|
100
|
+
callback(err);
|
|
101
|
+
rejectFunc(err);
|
|
102
|
+
return returnPromise;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
timer = setTimeout(() => {
|
|
106
|
+
const err = new Error("MQTT response timeout");
|
|
107
|
+
cleanup();
|
|
108
|
+
log.error("deleteMessage", err);
|
|
109
|
+
callback(err);
|
|
110
|
+
rejectFunc(err);
|
|
111
|
+
}, 20000);
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
ctx.mqttClient.publish(
|
|
115
|
+
"/ls_req",
|
|
116
|
+
form,
|
|
117
|
+
{ qos: 1, retain: false },
|
|
118
|
+
(err) => {
|
|
119
|
+
if (err) {
|
|
120
|
+
cleanup();
|
|
121
|
+
log.error("deleteMessage", err);
|
|
122
|
+
callback(err);
|
|
123
|
+
rejectFunc(err);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
cleanup();
|
|
129
|
+
log.error("deleteMessage", err);
|
|
130
|
+
callback(err);
|
|
131
|
+
rejectFunc(err);
|
|
132
|
+
}
|
|
53
133
|
|
|
54
134
|
return returnPromise;
|
|
55
135
|
};
|
|
@@ -2,23 +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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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: [
|
|
22
28
|
{
|
|
23
29
|
failure_count: null,
|
|
24
30
|
label: "46",
|
|
@@ -41,11 +47,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
41
47
|
};
|
|
42
48
|
const form = JSON.stringify({
|
|
43
49
|
app_id: "772021112871879",
|
|
44
|
-
payload: JSON.stringify(payload),
|
|
45
|
-
"request_id": ++count_req,
|
|
46
|
-
"type": 3
|
|
47
|
-
});
|
|
48
|
-
mqttClient.publish("/ls_req", form);
|
|
49
|
-
return returnPromise;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
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
|
+
};
|