stfca 1.0.21 → 1.0.23
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/index.js +73 -3
- package/package.json +1 -1
- package/src/OldMessage.js +8 -4
- package/src/sendMessage.js +8 -4
- package/src/sendTypingIndicatorV2.js +20 -3
package/index.js
CHANGED
|
@@ -192,13 +192,83 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
192
192
|
};
|
|
193
193
|
let config = { enableTypingIndicator: false, typingDuration: 4000 };
|
|
194
194
|
try {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
// Prefer global root config (project-level), but fallback to fca/config.json if present.
|
|
196
|
+
const rootConfigPath = path.join(process.cwd(), 'config.json');
|
|
197
|
+
if (fs.existsSync(rootConfigPath)) {
|
|
198
|
+
const rootConfig = JSON.parse(fs.readFileSync(rootConfigPath, 'utf8'));
|
|
199
|
+
if (rootConfig && typeof rootConfig === 'object') {
|
|
200
|
+
if (typeof rootConfig.enableTypingIndicator !== 'undefined') config.enableTypingIndicator = rootConfig.enableTypingIndicator;
|
|
201
|
+
if (typeof rootConfig.typingDuration !== 'undefined') config.typingDuration = rootConfig.typingDuration;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const fcaConfigPath = path.join(__dirname, 'config.json');
|
|
206
|
+
if (fs.existsSync(fcaConfigPath)) {
|
|
207
|
+
const fcaConfig = JSON.parse(fs.readFileSync(fcaConfigPath, 'utf8'));
|
|
208
|
+
if (fcaConfig && typeof fcaConfig === 'object') {
|
|
209
|
+
if (typeof fcaConfig.enableTypingIndicator !== 'undefined') config.enableTypingIndicator = fcaConfig.enableTypingIndicator;
|
|
210
|
+
if (typeof fcaConfig.typingDuration !== 'undefined') config.typingDuration = fcaConfig.typingDuration;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (global.GoatBot && global.GoatBot.config) {
|
|
215
|
+
if (typeof global.GoatBot.config.enableTypingIndicator !== 'undefined') config.enableTypingIndicator = global.GoatBot.config.enableTypingIndicator;
|
|
216
|
+
if (typeof global.GoatBot.config.typingDuration !== 'undefined') config.typingDuration = global.GoatBot.config.typingDuration;
|
|
198
217
|
}
|
|
199
218
|
} catch (e) {
|
|
200
219
|
console.log('Error loading config.json:', e);
|
|
201
220
|
}
|
|
221
|
+
|
|
222
|
+
const refreshFcaConfig = () => {
|
|
223
|
+
try {
|
|
224
|
+
// Defaults first
|
|
225
|
+
const updatedConfig = { enableTypingIndicator: false, typingDuration: 4000 };
|
|
226
|
+
|
|
227
|
+
// Layered config sources
|
|
228
|
+
if (fs.existsSync(path.join(process.cwd(), 'config.json'))) {
|
|
229
|
+
const rootConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'config.json'), 'utf8'));
|
|
230
|
+
if (rootConfig && typeof rootConfig === 'object') {
|
|
231
|
+
if (typeof rootConfig.enableTypingIndicator !== 'undefined') updatedConfig.enableTypingIndicator = rootConfig.enableTypingIndicator;
|
|
232
|
+
if (typeof rootConfig.typingDuration !== 'undefined') updatedConfig.typingDuration = rootConfig.typingDuration;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (fs.existsSync(path.join(__dirname, 'config.json'))) {
|
|
237
|
+
const fcaConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'), 'utf8'));
|
|
238
|
+
if (fcaConfig && typeof fcaConfig === 'object') {
|
|
239
|
+
if (typeof fcaConfig.enableTypingIndicator !== 'undefined') updatedConfig.enableTypingIndicator = fcaConfig.enableTypingIndicator;
|
|
240
|
+
if (typeof fcaConfig.typingDuration !== 'undefined') updatedConfig.typingDuration = fcaConfig.typingDuration;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (global.GoatBot && global.GoatBot.config) {
|
|
245
|
+
if (typeof global.GoatBot.config.enableTypingIndicator !== 'undefined') updatedConfig.enableTypingIndicator = global.GoatBot.config.enableTypingIndicator;
|
|
246
|
+
if (typeof global.GoatBot.config.typingDuration !== 'undefined') updatedConfig.typingDuration = global.GoatBot.config.typingDuration;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
ctx.config = updatedConfig;
|
|
250
|
+
config = updatedConfig;
|
|
251
|
+
if (global.GoatBot) global.GoatBot.config = global.GoatBot.config || {};
|
|
252
|
+
if (global.GoatBot && typeof global.GoatBot.config.enableTypingIndicator !== 'undefined') {
|
|
253
|
+
global.GoatBot.config.enableTypingIndicator = updatedConfig.enableTypingIndicator;
|
|
254
|
+
}
|
|
255
|
+
if (global.GoatBot && typeof global.GoatBot.config.typingDuration !== 'undefined') {
|
|
256
|
+
global.GoatBot.config.typingDuration = updatedConfig.typingDuration;
|
|
257
|
+
}
|
|
258
|
+
} catch (e) {
|
|
259
|
+
console.log('Failed to refresh fca config:', e);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// Initial config load
|
|
264
|
+
refreshFcaConfig();
|
|
265
|
+
|
|
266
|
+
// Accessible runtime API for config reload
|
|
267
|
+
ctx.refreshFcaConfig = refreshFcaConfig;
|
|
268
|
+
if (global.GoatBot) {
|
|
269
|
+
global.GoatBot.refreshFcaConfig = refreshFcaConfig;
|
|
270
|
+
}
|
|
271
|
+
|
|
202
272
|
ctx.config = config;
|
|
203
273
|
var api = {
|
|
204
274
|
setOptions: setOptions.bind(null, globalOptions),
|
package/package.json
CHANGED
package/src/OldMessage.js
CHANGED
|
@@ -311,11 +311,15 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
311
311
|
};
|
|
312
312
|
// console.log(form)
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
314
|
+
const configSource = (global.GoatBot && global.GoatBot.config) ? global.GoatBot.config : ctx.config || {};
|
|
315
|
+
const enableTypingIndicator = typeof configSource.enableTypingIndicator !== 'undefined' ? configSource.enableTypingIndicator : ctx.config?.enableTypingIndicator;
|
|
316
|
+
const typingDuration = Number(configSource.typingDuration || ctx.config?.typingDuration || 4000);
|
|
317
|
+
|
|
318
|
+
if (enableTypingIndicator) {
|
|
319
|
+
api.sendTypingIndicatorV2(true, threadID, () => {});
|
|
316
320
|
const originalCallback = callback;
|
|
317
321
|
callback = (err, data) => {
|
|
318
|
-
|
|
322
|
+
api.sendTypingIndicatorV2(false, threadID, () => {});
|
|
319
323
|
originalCallback(err, data);
|
|
320
324
|
};
|
|
321
325
|
setTimeout(() => {
|
|
@@ -332,7 +336,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
332
336
|
)
|
|
333
337
|
)
|
|
334
338
|
);
|
|
335
|
-
},
|
|
339
|
+
}, typingDuration);
|
|
336
340
|
} else {
|
|
337
341
|
handleLocation(msg, form, callback, () =>
|
|
338
342
|
handleSticker(msg, form, callback, () =>
|
package/src/sendMessage.js
CHANGED
|
@@ -234,11 +234,15 @@ module.exports = (defaultFuncs, api, ctx) => {
|
|
|
234
234
|
form["profile_xmd[" + i + "][type]"] = "p";
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
const configSource = (global.GoatBot && global.GoatBot.config) ? global.GoatBot.config : ctx.config || {};
|
|
238
|
+
const enableTypingIndicator = typeof configSource.enableTypingIndicator !== 'undefined' ? configSource.enableTypingIndicator : ctx.config?.enableTypingIndicator;
|
|
239
|
+
const typingDuration = Number(configSource.typingDuration || ctx.config?.typingDuration || 4000);
|
|
240
|
+
|
|
241
|
+
if (enableTypingIndicator) {
|
|
242
|
+
await api.sendTypingIndicatorV2(true, threadID, () => {});
|
|
243
|
+
await utils.delay(typingDuration);
|
|
240
244
|
const result = await sendContent(form, threadID, isSingleUser, messageAndOTID);
|
|
241
|
-
|
|
245
|
+
await api.sendTypingIndicatorV2(false, threadID, () => {});
|
|
242
246
|
if (callback && typeof callback === "function") {
|
|
243
247
|
callback(null, result);
|
|
244
248
|
}
|
|
@@ -6,8 +6,14 @@ var utils = require("../utils");
|
|
|
6
6
|
// @NethWs3Dev
|
|
7
7
|
|
|
8
8
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
9
|
-
return async function sendTypingIndicatorV2(sendTyping,threadID, callback) {
|
|
10
|
-
|
|
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;
|
|
11
17
|
var wsContent = {
|
|
12
18
|
app_id: 2220391788200892,
|
|
13
19
|
payload: JSON.stringify({
|
|
@@ -23,6 +29,17 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
23
29
|
request_id: ++count_req,
|
|
24
30
|
type: 4
|
|
25
31
|
};
|
|
26
|
-
|
|
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
|
+
});
|
|
27
44
|
};
|
|
28
45
|
};
|