stfca 1.0.23 → 1.0.25
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 +1 -1
- package/src/OldMessage.js +2 -2
- package/src/sendMessage.js +2 -2
- package/src/sendTypingIndicator.js +45 -101
- package/utils.js +33 -6
- package/src/sendTypingIndicatorV2.js +0 -45
package/package.json
CHANGED
package/src/OldMessage.js
CHANGED
|
@@ -316,10 +316,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
316
316
|
const typingDuration = Number(configSource.typingDuration || ctx.config?.typingDuration || 4000);
|
|
317
317
|
|
|
318
318
|
if (enableTypingIndicator) {
|
|
319
|
-
api.
|
|
319
|
+
api.sendTypingIndicator(true, threadID, () => {});
|
|
320
320
|
const originalCallback = callback;
|
|
321
321
|
callback = (err, data) => {
|
|
322
|
-
api.
|
|
322
|
+
api.sendTypingIndicator(false, threadID, () => {});
|
|
323
323
|
originalCallback(err, data);
|
|
324
324
|
};
|
|
325
325
|
setTimeout(() => {
|
package/src/sendMessage.js
CHANGED
|
@@ -239,10 +239,10 @@ module.exports = (defaultFuncs, api, ctx) => {
|
|
|
239
239
|
const typingDuration = Number(configSource.typingDuration || ctx.config?.typingDuration || 4000);
|
|
240
240
|
|
|
241
241
|
if (enableTypingIndicator) {
|
|
242
|
-
await api.
|
|
242
|
+
await api.sendTypingIndicator(true, threadID, () => {});
|
|
243
243
|
await utils.delay(typingDuration);
|
|
244
244
|
const result = await sendContent(form, threadID, isSingleUser, messageAndOTID);
|
|
245
|
-
await api.
|
|
245
|
+
await api.sendTypingIndicator(false, threadID, () => {});
|
|
246
246
|
if (callback && typeof callback === "function") {
|
|
247
247
|
callback(null, result);
|
|
248
248
|
}
|
|
@@ -1,101 +1,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
defaultFuncs
|
|
47
|
-
.post(
|
|
48
|
-
"https://www.facebook.com/ajax/messaging/typ.php",
|
|
49
|
-
ctx.jar,
|
|
50
|
-
form,
|
|
51
|
-
)
|
|
52
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
53
|
-
.then(function (resData) {
|
|
54
|
-
if (resData.error) {
|
|
55
|
-
throw resData;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return callback();
|
|
59
|
-
})
|
|
60
|
-
.catch(function (err) {
|
|
61
|
-
console.error("sendTypingIndicator", err);
|
|
62
|
-
return callback(err);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return function sendTypingIndicator(threadID, callback, isGroup) {
|
|
69
|
-
if (
|
|
70
|
-
utils.getType(callback) !== "Function" &&
|
|
71
|
-
utils.getType(callback) !== "AsyncFunction"
|
|
72
|
-
) {
|
|
73
|
-
if (callback) {
|
|
74
|
-
console.warn(
|
|
75
|
-
"sendTypingIndicator",
|
|
76
|
-
"callback is not a function - ignoring.",
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
callback = () => {};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
makeTypingIndicator(true, threadID, callback, isGroup);
|
|
83
|
-
|
|
84
|
-
return function end(cb) {
|
|
85
|
-
if (
|
|
86
|
-
utils.getType(cb) !== "Function" &&
|
|
87
|
-
utils.getType(cb) !== "AsyncFunction"
|
|
88
|
-
) {
|
|
89
|
-
if (cb) {
|
|
90
|
-
console.warn(
|
|
91
|
-
"sendTypingIndicator",
|
|
92
|
-
"callback is not a function - ignoring.",
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
cb = () => {};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
makeTypingIndicator(false, threadID, cb, isGroup);
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var utils = require("../utils");
|
|
6
|
+
// @NethWs3Dev
|
|
7
|
+
|
|
8
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
9
|
+
return async function sendTypingIndicatorV2(sendTyping, threadID, callback) {
|
|
10
|
+
const mqttClient = ctx.mqttClient || global.mqttClient;
|
|
11
|
+
if (!mqttClient) {
|
|
12
|
+
if (typeof callback === 'function') callback(new Error('No MQTT client available for typing indicator'));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let count_req = 0;
|
|
17
|
+
var wsContent = {
|
|
18
|
+
app_id: 2220391788200892,
|
|
19
|
+
payload: JSON.stringify({
|
|
20
|
+
label: 3,
|
|
21
|
+
payload: JSON.stringify({
|
|
22
|
+
thread_key: threadID.toString(),
|
|
23
|
+
is_group_thread: +(threadID.toString().length >= 16),
|
|
24
|
+
is_typing: +sendTyping,
|
|
25
|
+
attribution: 0
|
|
26
|
+
}),
|
|
27
|
+
version: 5849951561777440
|
|
28
|
+
}),
|
|
29
|
+
request_id: ++count_req,
|
|
30
|
+
type: 4
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
if (typeof callback === 'function') callback(err);
|
|
37
|
+
reject(err);
|
|
38
|
+
} else {
|
|
39
|
+
if (typeof callback === 'function') callback(null, _packet);
|
|
40
|
+
resolve(_packet);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
};
|
package/utils.js
CHANGED
|
@@ -724,14 +724,41 @@ function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
|
|
|
724
724
|
|
|
725
725
|
function formatDeltaMessage(m) {
|
|
726
726
|
var md = m.delta.messageMetadata;
|
|
727
|
-
var mdata = m.delta.data === undefined ? [] : m.delta.data.prng === undefined ? [] : JSON.parse(m.delta.data.prng);
|
|
728
|
-
var m_id = mdata.map(u => u.i);
|
|
729
|
-
var m_offset = mdata.map(u => u.o);
|
|
730
|
-
var m_length = mdata.map(u => u.l);
|
|
731
|
-
var mentions = {};
|
|
732
727
|
var body = m.delta.body || "";
|
|
733
728
|
var args = body == "" ? [] : body.trim().split(/\s+/);
|
|
734
|
-
|
|
729
|
+
var mentions = {};
|
|
730
|
+
var mdata = [];
|
|
731
|
+
if (m.delta.data && m.delta.data.prng) {
|
|
732
|
+
try {
|
|
733
|
+
mdata = JSON.parse(m.delta.data.prng);
|
|
734
|
+
} catch (e) {
|
|
735
|
+
mdata = [];
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (mdata.length > 0) {
|
|
739
|
+
for (var i = 0; i < mdata.length; i++) {
|
|
740
|
+
var _id = String(mdata[i].i);
|
|
741
|
+
var _o = parseInt(mdata[i].o, 10) || 0;
|
|
742
|
+
var _l = parseInt(mdata[i].l, 10) || 0;
|
|
743
|
+
mentions[_id] = body.substring(_o, _o + _l);
|
|
744
|
+
}
|
|
745
|
+
} else if (
|
|
746
|
+
md && md.data && md.data.data && md.data.data.Gb &&
|
|
747
|
+
md.data.data.Gb.asMap && md.data.data.Gb.asMap.data
|
|
748
|
+
) {
|
|
749
|
+
var gbData = md.data.data.Gb.asMap.data;
|
|
750
|
+
for (var key in gbData) {
|
|
751
|
+
if (!Object.prototype.hasOwnProperty.call(gbData, key)) continue;
|
|
752
|
+
var entry = gbData[key];
|
|
753
|
+
if (entry && entry.asMap && entry.asMap.data) {
|
|
754
|
+
var d = entry.asMap.data;
|
|
755
|
+
var _gid = d.id && d.id.asLong ? String(d.id.asLong) : null;
|
|
756
|
+
var _go = parseInt(d.offset && d.offset.asLong ? d.offset.asLong : 0, 10);
|
|
757
|
+
var _gl = parseInt(d.length && d.length.asLong ? d.length.asLong : 0, 10);
|
|
758
|
+
if (_gid != null) mentions[_gid] = body.substring(_go, _go + _gl);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
735
762
|
|
|
736
763
|
// Determine if this is a DM or group
|
|
737
764
|
const otherUserFbId = md.threadKey.otherUserFbId;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var utils = require("../utils");
|
|
6
|
-
// @NethWs3Dev
|
|
7
|
-
|
|
8
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
9
|
-
return async function sendTypingIndicatorV2(sendTyping, threadID, callback) {
|
|
10
|
-
const mqttClient = ctx.mqttClient || global.mqttClient;
|
|
11
|
-
if (!mqttClient) {
|
|
12
|
-
if (typeof callback === 'function') callback(new Error('No MQTT client available for typing indicator'));
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let count_req = 0;
|
|
17
|
-
var wsContent = {
|
|
18
|
-
app_id: 2220391788200892,
|
|
19
|
-
payload: JSON.stringify({
|
|
20
|
-
label: 3,
|
|
21
|
-
payload: JSON.stringify({
|
|
22
|
-
thread_key: threadID.toString(),
|
|
23
|
-
is_group_thread: +(threadID.toString().length >= 16),
|
|
24
|
-
is_typing: +sendTyping,
|
|
25
|
-
attribution: 0
|
|
26
|
-
}),
|
|
27
|
-
version: 5849951561777440
|
|
28
|
-
}),
|
|
29
|
-
request_id: ++count_req,
|
|
30
|
-
type: 4
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => {
|
|
35
|
-
if (err) {
|
|
36
|
-
if (typeof callback === 'function') callback(err);
|
|
37
|
-
reject(err);
|
|
38
|
-
} else {
|
|
39
|
-
if (typeof callback === 'function') callback(null, _packet);
|
|
40
|
-
resolve(_packet);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
};
|