@vielhuber/wahelper 1.3.2 → 1.3.3
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/WhatsApp.js +23 -12
- package/package.json +1 -1
package/WhatsApp.js
CHANGED
|
@@ -34,6 +34,7 @@ export default class WhatsApp {
|
|
|
34
34
|
this.inactivityTimeCur = 0;
|
|
35
35
|
this.inactivityTimeInterval = null;
|
|
36
36
|
this.inactivityTimeStatus = false;
|
|
37
|
+
this.writeOnEnd = null;
|
|
37
38
|
if (this.args.device !== undefined && this.args.device !== null && this.args.device !== '') {
|
|
38
39
|
this.authFolder = 'auth_' + this.formatNumber(this.args.device);
|
|
39
40
|
this.dbPath = 'whatsapp_' + this.formatNumber(this.args.device) + '.sqlite';
|
|
@@ -58,7 +59,7 @@ export default class WhatsApp {
|
|
|
58
59
|
async init() {
|
|
59
60
|
await this.awaitLock('init', true);
|
|
60
61
|
this.setLock('init', true);
|
|
61
|
-
this.write({ success: false, message: 'loading_state', data: null });
|
|
62
|
+
this.write({ success: false, message: 'loading_state', data: null }, false);
|
|
62
63
|
|
|
63
64
|
if (this.isMcp === false) {
|
|
64
65
|
this.log('cli start');
|
|
@@ -73,12 +74,15 @@ export default class WhatsApp {
|
|
|
73
74
|
) {
|
|
74
75
|
console.error('input missing or unknown action!');
|
|
75
76
|
this.log('⛔input missing or unknown action!');
|
|
76
|
-
this.write(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
this.write(
|
|
78
|
+
{
|
|
79
|
+
success: false,
|
|
80
|
+
message: 'error',
|
|
81
|
+
public_message: 'input missing or unknown action!',
|
|
82
|
+
data: null
|
|
83
|
+
},
|
|
84
|
+
true
|
|
85
|
+
);
|
|
82
86
|
this.removeLocks();
|
|
83
87
|
} else {
|
|
84
88
|
this.initDatabase();
|
|
@@ -198,7 +202,7 @@ export default class WhatsApp {
|
|
|
198
202
|
code = code.match(/.{1,4}/g).join('-');
|
|
199
203
|
console.log('Bitte verknüpfe das neue Gerät und gib diesen Code ein:');
|
|
200
204
|
console.log(code);
|
|
201
|
-
this.write({ success: false, message: 'pairing_code_required', data: code });
|
|
205
|
+
this.write({ success: false, message: 'pairing_code_required', data: code }, true);
|
|
202
206
|
}
|
|
203
207
|
if (this.isMcp) {
|
|
204
208
|
resolve({
|
|
@@ -263,6 +267,9 @@ export default class WhatsApp {
|
|
|
263
267
|
process.exit(0);
|
|
264
268
|
});
|
|
265
269
|
process.on('exit', code => {
|
|
270
|
+
if (this.writeOnEnd !== null) {
|
|
271
|
+
this.write(this.writeOnEnd, false);
|
|
272
|
+
}
|
|
266
273
|
this.removeLocks();
|
|
267
274
|
this.log('final exit');
|
|
268
275
|
console.log('final exit');
|
|
@@ -361,7 +368,7 @@ export default class WhatsApp {
|
|
|
361
368
|
`
|
|
362
369
|
)
|
|
363
370
|
.all();
|
|
364
|
-
this.write({ success: true, message: 'messages_fetched', data: messages });
|
|
371
|
+
this.write({ success: true, message: 'messages_fetched', data: messages }, true);
|
|
365
372
|
return {
|
|
366
373
|
content: [
|
|
367
374
|
{
|
|
@@ -450,7 +457,7 @@ export default class WhatsApp {
|
|
|
450
457
|
msgResponse.push(await this.sock.sendMessage(jid, this.getAttachmentObj(attachments__value)));
|
|
451
458
|
}
|
|
452
459
|
}
|
|
453
|
-
this.write({ success: true, message: 'message_user_sent', data: msgResponse });
|
|
460
|
+
this.write({ success: true, message: 'message_user_sent', data: msgResponse }, true);
|
|
454
461
|
//this.log(msgResponse);
|
|
455
462
|
return {
|
|
456
463
|
content: [{ type: 'text', text: JSON.stringify(msgResponse, null, 2) }],
|
|
@@ -476,7 +483,7 @@ export default class WhatsApp {
|
|
|
476
483
|
}
|
|
477
484
|
}
|
|
478
485
|
}
|
|
479
|
-
this.write({ success: true, message: 'message_group_sent', data: msgResponse });
|
|
486
|
+
this.write({ success: true, message: 'message_group_sent', data: msgResponse }, true);
|
|
480
487
|
//this.log(msgResponse);
|
|
481
488
|
return {
|
|
482
489
|
content: [{ type: 'text', text: JSON.stringify(msgResponse, null, 2) }],
|
|
@@ -608,10 +615,14 @@ export default class WhatsApp {
|
|
|
608
615
|
fs.appendFileSync(this.dirname + '/' + this.logPath, logLine);
|
|
609
616
|
}
|
|
610
617
|
|
|
611
|
-
write(msg) {
|
|
618
|
+
write(msg, writeOnEnd = true) {
|
|
612
619
|
if (this.dataPath === undefined) {
|
|
613
620
|
return;
|
|
614
621
|
}
|
|
622
|
+
if (writeOnEnd === true) {
|
|
623
|
+
this.writeOnEnd = msg;
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
615
626
|
fs.writeFileSync(this.dirname + '/' + this.dataPath, JSON.stringify(msg));
|
|
616
627
|
}
|
|
617
628
|
|