@vielhuber/wahelper 1.6.7 → 1.6.9
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 +3 -3
- package/wahelper-daemon.js +44 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielhuber/wahelper",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.9",
|
|
4
4
|
"description": "Lightweight whatsapp integration layer.",
|
|
5
5
|
"main": "wahelper.js",
|
|
6
6
|
"files": [
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"author": "David Vielhuber <david@vielhuber.de>",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"baileys": "
|
|
25
|
+
"baileys": "latest",
|
|
26
26
|
"qrcode-terminal": "^0.12.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@prettier/plugin-php": "^0.25.0",
|
|
30
|
-
"prettier": "^3.
|
|
30
|
+
"prettier": "^3.9.5"
|
|
31
31
|
},
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=18"
|
package/wahelper-daemon.js
CHANGED
|
@@ -175,6 +175,29 @@ export default class wahelperDaemon {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
// resolve a jid + its baileys "alt" counterpart (remoteJidAlt / participantAlt,
|
|
179
|
+
// which carries the opposite id type) into { pn, lid } — purely from the message.
|
|
180
|
+
resolveIdentity(primaryJid, altJid) {
|
|
181
|
+
let out = { pn: null, lid: null };
|
|
182
|
+
let classify = jid => {
|
|
183
|
+
if (!jid || typeof jid !== 'string') {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
let bare = jid.replace(/@.*$/, '');
|
|
187
|
+
if (bare === '') {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (jid.endsWith('@lid')) {
|
|
191
|
+
out.lid = bare;
|
|
192
|
+
} else if (jid.endsWith('@s.whatsapp.net') || jid.endsWith('@c.us')) {
|
|
193
|
+
out.pn = bare;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
classify(primaryJid);
|
|
197
|
+
classify(altJid);
|
|
198
|
+
return out;
|
|
199
|
+
}
|
|
200
|
+
|
|
178
201
|
formatMessage(message) {
|
|
179
202
|
if (message === null || message === undefined || message === '') {
|
|
180
203
|
return message;
|
|
@@ -289,28 +312,31 @@ export default class wahelperDaemon {
|
|
|
289
312
|
timestamp = Math.floor(Date.now() / 1000);
|
|
290
313
|
}
|
|
291
314
|
|
|
315
|
+
// resolve the human partner's jid to the phone number; the group
|
|
316
|
+
// chat (and "me") stay as-is, only the contact id gets canonicalized.
|
|
317
|
+
let isGroup = chatId?.endsWith('@g.us');
|
|
318
|
+
let me = this.args.device || 'me';
|
|
292
319
|
let from = null;
|
|
293
320
|
let to = null;
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
from =
|
|
321
|
+
if (isGroup) {
|
|
322
|
+
to = chatId ? chatId.replace(/@.*$/, '') : null;
|
|
323
|
+
if (fromMe) {
|
|
324
|
+
from = me;
|
|
325
|
+
} else {
|
|
326
|
+
let participantJid = messages__value?.participant || messages__value?.key?.participant || null;
|
|
327
|
+
let ident = this.resolveIdentity(participantJid, messages__value?.key?.participantAlt || null);
|
|
328
|
+
from = ident.pn || ident.lid || (participantJid || '').replace(/@.*$/, '');
|
|
302
329
|
}
|
|
303
|
-
to = chatId;
|
|
304
330
|
} else {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
331
|
+
let ident = this.resolveIdentity(chatId || null, messages__value?.key?.remoteJidAlt || null);
|
|
332
|
+
let partnerId = ident.pn || ident.lid || (chatId || '').replace(/@.*$/, '');
|
|
333
|
+
if (fromMe) {
|
|
334
|
+
from = me;
|
|
335
|
+
to = partnerId;
|
|
336
|
+
} else {
|
|
337
|
+
from = partnerId;
|
|
338
|
+
to = me;
|
|
339
|
+
}
|
|
314
340
|
}
|
|
315
341
|
|
|
316
342
|
if (from === null || from === undefined || from === '') {
|