@vielhuber/wahelper 1.0.9 → 1.1.1

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 (3) hide show
  1. package/README.MD +2 -2
  2. package/package.json +5 -2
  3. package/whatsapp.js +22 -8
package/README.MD CHANGED
@@ -93,8 +93,8 @@ WhatsApp::run([
93
93
  {
94
94
  "mcpServers": {
95
95
  "whatsapp": {
96
- "command": "npx",
97
- "args": ["/var/www/project/path/to/subfolder/wahelper/node_modules/.bin/wahelper", "--mcp"]
96
+ "command": "/root/.nvm/versions/node/v22.20.0/bin/node",
97
+ "args": ["/var/www/project/node_modules/@vielhuber/wahelper/whatsapp.js", "--mcp"]
98
98
  }
99
99
  }
100
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielhuber/wahelper",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
4
4
  "description": "Lightweight whatsapp integration layer.",
5
5
  "main": "whatsapp.js",
6
6
  "files": [
@@ -13,7 +13,10 @@
13
13
  "access": "public"
14
14
  },
15
15
  "type": "module",
16
- "repository": "git@github.com:vielhuber/wahelper.git",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+ssh://git@github.com/vielhuber/wahelper.git"
19
+ },
17
20
  "author": "David Vielhuber <david@vielhuber.de>",
18
21
  "license": "MIT",
19
22
  "dependencies": {
package/whatsapp.js CHANGED
@@ -8,7 +8,6 @@ import { fileURLToPath } from 'url';
8
8
  import { dirname } from 'path';
9
9
  import fs from 'fs';
10
10
  import { DatabaseSync } from 'node:sqlite';
11
- import dotenv from 'dotenv';
12
11
 
13
12
  export default class WhatsApp {
14
13
  constructor() {
@@ -356,18 +355,28 @@ export default class WhatsApp {
356
355
  if (message === null || message === undefined || message === '') {
357
356
  return message;
358
357
  }
358
+ // replace nbsp with spaces
359
+ message = message.replace(/&nbsp;/g, ' ');
359
360
  // replace <br> with real line breaks
360
- message = message.replace(/<br\s*\/?>/gi, '\n');
361
+ message = message.replace(/<br\s*\/?>/gis, '\n');
361
362
  // replace " </x>" with "</x> "
362
- message = message.replace(/ (\<\/[a-z]+\>)/gi, '$1 ');
363
+ message = message.replace(/ (\<\/[a-z]+\>)/gis, '$1 ');
363
364
  // replace "<x> " with " <x>"
364
- message = message.replace(/(\<[a-z]+\>) /gi, ' $1');
365
- // replace <strong></strong> with "*"
366
- message = message.replace(/<strong>(.*?)<\/strong>/gi, '*$1*');
365
+ message = message.replace(/(\<[a-z]+(?:\s[^>]*)?\>) /gis, ' $1');
366
+ // replace " \n" with "\n"
367
+ message = message.replace(/ \n/gis, '\n');
368
+ // remove "<x> </x>"
369
+ message = message.replace(/<([a-z]+)(?:\s[^>]*)?\>\s*<\/\1>/gis, '');
370
+ // replace <strong>...</strong> with "*"
371
+ message = message.replace(/<strong(?:\s[^>]*)?\>(.*?)<\/strong>/gis, '*$1*');
367
372
  // replace <em></em> with "_"
368
- message = message.replace(/<em>(.*?)<\/em>/gi, '_$1_');
373
+ message = message.replace(/<em(?:\s[^>]*)?\>(.*?)<\/em>/gis, '_$1_');
369
374
  // replace <i></i> with "_"
370
- message = message.replace(/<i>(.*?)<\/i>/gi, '_$1_');
375
+ message = message.replace(/<i(?:\s[^>]*)?\>(.*?)<\/i>/gis, '_$1_');
376
+ // replace <ul> with line break
377
+ message = message.replace(/<ul(?:\s[^>]*)?\>(.*?)<\/ul>/gis, '\n$1\n');
378
+ // replace "<li></li>" with " - "
379
+ message = message.replace(/<li(?:\s[^>]*)?\>(.*?)<\/li>/gis, ' - $1\n');
371
380
  // replace html entities
372
381
  message = message.replace(/&quot;/g, '"');
373
382
  message = message.replace(/&#39;/g, "'");
@@ -517,6 +526,9 @@ export default class WhatsApp {
517
526
  let key = argv[i].replace(/^-+/, '').replace(/-/, '_'),
518
527
  value = argv[i + 1] && !argv[i + 1].startsWith('-') ? argv[i + 1] : true;
519
528
  if (key === 'attachments') {
529
+ if (value === null || value === undefined || value === '' || typeof value !== 'string') {
530
+ continue;
531
+ }
520
532
  value = value.split(',');
521
533
  }
522
534
  args[key] = value;
@@ -643,10 +655,12 @@ export default class WhatsApp {
643
655
  if (from === null || from === undefined || from === '') {
644
656
  this.log('⛔missing from⛔');
645
657
  this.log(messages__value);
658
+ continue;
646
659
  }
647
660
  if (to === null || to === undefined || to === '') {
648
661
  this.log('⛔missing to⛔');
649
662
  this.log(messages__value);
663
+ continue;
650
664
  }
651
665
  // skip status messages
652
666
  if (from === 'status') {