@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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. 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.7",
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": "mtAlves/Baileys#fix/pairing-code",
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.8.3"
30
+ "prettier": "^3.9.5"
31
31
  },
32
32
  "engines": {
33
33
  "node": ">=18"
@@ -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 (fromMe) {
295
- from = this.args.device || 'me';
296
- to = chatId;
297
- } else if (chatId?.endsWith('@g.us')) {
298
- if (messages__value?.participant) {
299
- from = messages__value?.participant;
300
- } else if (messages__value?.key?.participantAlt) {
301
- from = messages__value?.key?.participantAlt;
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
- from = chatId;
306
- to = this.args.device || 'me';
307
- }
308
-
309
- if (from) {
310
- from = from.replace(/@.*$/, '');
311
- }
312
- if (to) {
313
- to = to.replace(/@.*$/, '');
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 === '') {