node-ainzfb-new 1.7.10-4-fix → 1.7.10-8
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/pinMessage.js +58 -0
- package/src/shareContact.js +46 -0
- package/src/shareLink.js +54 -0
- package/utils.js +9 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-ainzfb-new",
|
3
|
-
"version": "1.7.10-
|
3
|
+
"version": "1.7.10-8",
|
4
4
|
"description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
|
5
5
|
"scripts": {
|
6
6
|
"test": "mocha",
|
@@ -39,7 +39,7 @@
|
|
39
39
|
"node-superfetch": "^0.2.3",
|
40
40
|
"npmlog": "latest",
|
41
41
|
"path": "latest",
|
42
|
-
"pretty-ms": "
|
42
|
+
"pretty-ms": "^7.0.1",
|
43
43
|
"pm2": "^5.3.0",
|
44
44
|
"request": "latest",
|
45
45
|
"semver": "latest",
|
@@ -0,0 +1,58 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { generateOfflineThreadingID, getCurrentTimestamp } = require('../utils');
|
4
|
+
|
5
|
+
function isCallable(func) {
|
6
|
+
try {
|
7
|
+
Reflect.apply(func, null, []);
|
8
|
+
return true;
|
9
|
+
} catch (error) {
|
10
|
+
return false;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
15
|
+
return function pinMessage(pinMode, messageID, threadID, callback) {
|
16
|
+
if (!ctx.mqttClient) {
|
17
|
+
throw new Error('Not connected to MQTT');
|
18
|
+
}
|
19
|
+
|
20
|
+
ctx.wsReqNumber += 1;
|
21
|
+
ctx.wsTaskNumber += 1;
|
22
|
+
|
23
|
+
const taskLabel = pinMode ? '430' : '431';
|
24
|
+
const queueNamePrefix = pinMode ? 'pin_msg_v2_' : 'unpin_msg_v2_';
|
25
|
+
|
26
|
+
const taskPayload = {
|
27
|
+
thread_key: threadID,
|
28
|
+
message_id: messageID,
|
29
|
+
timestamp_ms: getCurrentTimestamp(),
|
30
|
+
};
|
31
|
+
|
32
|
+
const task = {
|
33
|
+
failure_count: null,
|
34
|
+
label: taskLabel,
|
35
|
+
payload: JSON.stringify(taskPayload),
|
36
|
+
queue_name: `${queueNamePrefix}${threadID}`,
|
37
|
+
task_id: ctx.wsTaskNumber,
|
38
|
+
};
|
39
|
+
|
40
|
+
const content = {
|
41
|
+
app_id: '2220391788200892',
|
42
|
+
payload: JSON.stringify({
|
43
|
+
data_trace_id: null,
|
44
|
+
epoch_id: parseInt(generateOfflineThreadingID()),
|
45
|
+
tasks: [task],
|
46
|
+
version_id: '25095469420099952',
|
47
|
+
}),
|
48
|
+
request_id: ctx.wsReqNumber,
|
49
|
+
type: 3,
|
50
|
+
};
|
51
|
+
|
52
|
+
if (isCallable(callback)) {
|
53
|
+
// to be implemented
|
54
|
+
}
|
55
|
+
|
56
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
|
57
|
+
};
|
58
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return async function shareContact(text, senderID, threadID, mentionID, userID, leaverID, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
if (!callback) {
|
15
|
+
callback = function (err, data) {
|
16
|
+
if (err) return rejectFunc(err);
|
17
|
+
resolveFunc(data);
|
18
|
+
};
|
19
|
+
}
|
20
|
+
let count_req = 0;
|
21
|
+
var form = JSON.stringify({
|
22
|
+
"app_id": "2220391788200892",
|
23
|
+
"payload": JSON.stringify({
|
24
|
+
tasks: [{
|
25
|
+
label: '359',
|
26
|
+
payload: JSON.stringify({
|
27
|
+
"contact_id": senderID,
|
28
|
+
"sync_group": 1,
|
29
|
+
"text": text || "",
|
30
|
+
"thread_id": threadID
|
31
|
+
}),
|
32
|
+
queue_name: 'messenger_contact_sharing',
|
33
|
+
task_id: Math.random() * 1001 << 0,
|
34
|
+
failure_count: null,
|
35
|
+
}],
|
36
|
+
epoch_id: utils.generateOfflineThreadingID(),
|
37
|
+
version_id: '7214102258676893',
|
38
|
+
}),
|
39
|
+
"request_id": ++count_req,
|
40
|
+
"type": 3
|
41
|
+
});
|
42
|
+
ctx.mqttClient.publish('/ls_req', form);
|
43
|
+
|
44
|
+
return returnPromise;
|
45
|
+
};
|
46
|
+
};
|
package/src/shareLink.js
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return async function shareLink(text, url, threadID, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
if (!callback) {
|
15
|
+
callback = function (err, data) {
|
16
|
+
if (err) return rejectFunc(err);
|
17
|
+
resolveFunc(data);
|
18
|
+
};
|
19
|
+
}
|
20
|
+
ctx.mqttClient.publish('/ls_req',
|
21
|
+
JSON.stringify({
|
22
|
+
"app_id": "2220391788200892",
|
23
|
+
"payload": JSON.stringify({
|
24
|
+
tasks: [{
|
25
|
+
label: 46,
|
26
|
+
payload: JSON.stringify({
|
27
|
+
"otid": utils.generateOfflineThreadingID(),
|
28
|
+
"source": 524289,
|
29
|
+
"sync_group": 1,
|
30
|
+
"send_type": 6,
|
31
|
+
"mark_thread_read": 0,
|
32
|
+
"url": url || "",
|
33
|
+
"text": text || "",
|
34
|
+
"thread_id": threadID,
|
35
|
+
"initiating_source": 0
|
36
|
+
}),
|
37
|
+
queue_name: threadID,
|
38
|
+
task_id: Math.random() * 1001 << 0,
|
39
|
+
failure_count: null,
|
40
|
+
}],
|
41
|
+
epoch_id: utils.generateOfflineThreadingID(),
|
42
|
+
version_id: '7191105584331330',
|
43
|
+
}),
|
44
|
+
"request_id": ++ctx.req_ID,
|
45
|
+
"type": 3
|
46
|
+
}),
|
47
|
+
{
|
48
|
+
qos: 1,
|
49
|
+
retain: false,
|
50
|
+
}
|
51
|
+
)
|
52
|
+
return returnPromise;
|
53
|
+
};
|
54
|
+
};
|
package/utils.js
CHANGED
@@ -150,6 +150,12 @@ function generateThreadingID(clientID) {
|
|
150
150
|
return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
|
151
151
|
}
|
152
152
|
|
153
|
+
function getCurrentTimestamp() {
|
154
|
+
const date = new Date();
|
155
|
+
const unixTime = date.getTime();
|
156
|
+
return unixTime;
|
157
|
+
}
|
158
|
+
|
153
159
|
function binaryToDecimal(data) {
|
154
160
|
var ret = "";
|
155
161
|
while (data !== "0") {
|
@@ -1395,5 +1401,6 @@ module.exports = {
|
|
1395
1401
|
decodeClientPayload,
|
1396
1402
|
getAppState,
|
1397
1403
|
getAdminTextMessageType,
|
1398
|
-
setProxy
|
1399
|
-
|
1404
|
+
setProxy,
|
1405
|
+
getCurrentTimestamp
|
1406
|
+
};
|