@innovatorssoft/innovators-bot2 2.0.5 → 2.0.7

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/example.js CHANGED
@@ -1,4 +1,11 @@
1
- const { WhatsAppClient } = require('./index')
1
+ const { WhatsAppClient,
2
+ STATUS_BACKGROUNDS,
3
+ STATUS_FONTS,
4
+ renderLatexToPng,
5
+ uploadUnencryptedToWA,
6
+ RichSubMessageType
7
+ } = require('./index')
8
+
2
9
  const qrcode = require('qrcode-terminal')
3
10
  const fs = require('fs');
4
11
  const readline = require('readline');
@@ -48,6 +55,7 @@ async function start() {
48
55
  sessionName: sessionDir,
49
56
  authmethod: authMethod,
50
57
  pairingPhoneNumber: pairingPhoneNumber,
58
+ ai: true, // Enable/Disable AI flag for outgoing messages (default: true)
51
59
  // Message store persistence configuration
52
60
  messageStoreFilePath: path.join(sessionDir, 'message-store.json'),
53
61
  autoSaveInterval: 5 * 60 * 1000, // Auto-save every 5 minutes
@@ -124,6 +132,37 @@ async function start() {
124
132
  console.log('Is Removed:', reaction.isRemoved)
125
133
  console.log('Message ID:', reaction.messageKey.id)
126
134
  })
135
+ client.on('poll-votes-update', async (data) => {
136
+ console.log('\nšŸ“Š Poll Votes Updated!');
137
+ console.log('Chat:', data.jid);
138
+ console.log('Voter:', data.voter);
139
+
140
+ // 1. Extract Poll Creation Message (Question, Options, etc.)
141
+ const pollCreation = data.pollCreationMessage;
142
+ if (pollCreation && pollCreation.message) {
143
+ const pollMessage = pollCreation.message.pollCreationMessage ||
144
+ pollCreation.message.pollCreationMessageV2 ||
145
+ pollCreation.message.pollCreationMessageV3;
146
+
147
+ if (pollMessage) {
148
+ console.log('\nšŸ“ Poll Creation Details:');
149
+ console.log('Question:', pollMessage.name);
150
+ console.log('Options:', pollMessage.options?.map(o => o.optionName) || []);
151
+ }
152
+ }
153
+
154
+ // 2. Extract voters array from pollUpdate
155
+ console.log('\nšŸ—³ļø Vote Breakdown:');
156
+ let totalVotesCount = 0;
157
+ data.pollUpdate.forEach((option) => {
158
+ console.log(`--> ${option.name}: ${option.voters.length} vote(s) ${JSON.stringify(option.voters)}`);
159
+ totalVotesCount += option.voters.length;
160
+ });
161
+ console.log(`--> Total Votes Cast: ${totalVotesCount}`);
162
+ const winner = data.pollUpdate.reduce((prev, current) =>
163
+ prev.voters.length > current.voters.length ? prev : current);
164
+ console.log(`--> The Winner Is ${winner.name} With ${winner.voters.length} votes`);
165
+ });
127
166
 
128
167
  client.on('call', (call) => {
129
168
  const callData = call[0]; // Get the first call object from the array
@@ -181,44 +220,74 @@ async function start() {
181
220
  return
182
221
  }
183
222
 
223
+
184
224
  console.log('Message Received');
185
- console.log('Number:', msg.from);
186
- console.log('Sender:', msg.raw.pushName);
225
+
226
+
227
+ isGroupMsg = msg.isGroup
228
+ if (isGroupMsg) {
229
+ msgFrom = msg.from
230
+ } else {
231
+ msgFrom = msg.sender
232
+ }
233
+
234
+ console.log('Msg From:', msg.from);
235
+ console.log('Msg Sender:', msg.sender);
236
+ console.log('Sender Name:', msg.raw.pushName);
187
237
  console.log('Message:', msg.body);
238
+ console.log('Is Group:', msg.isGroup);
188
239
  // Mark the message as read
189
240
  await client.readMessage(msg.raw.key)
190
241
 
191
- const command = msg.body.toLowerCase().split(' ')[0]
192
- const args = msg.body.toLowerCase().split(' ').slice(1).join(' ')
242
+ const command = msg.body.split(' ')[0].toLowerCase()
243
+ const args = msg.body.split(' ').slice(1).join(' ')
193
244
 
194
245
  switch (command) {
195
246
  case '!ping':
196
- await client.sendMessage(msg.from, 'pong')
247
+ await client.sendMessage(msgFrom, 'Hello Pong! šŸŽŠ')
248
+ break
249
+ case '!poll':
250
+ await client.sendMessage(msgFrom, '', {
251
+ poll: {
252
+ name: 'Which programming language do you like most?',
253
+ options: ['JavaScript', 'Python', 'C++', 'Java'],
254
+ selectableOptionsCount: 1,
255
+ messageId: 'poll1'
256
+ }
257
+ });
197
258
  break
198
-
199
259
  case '!echo':
200
260
  if (args) {
201
- await client.sendMessage(msg.from, args)
261
+ await client.sendMessage(msgFrom, args)
202
262
  } else {
203
- await client.sendMessage(msg.from, 'Please provide text to echo')
263
+ await client.sendMessage(msgFrom, 'Please provide text to echo')
204
264
  }
205
265
  break
206
-
207
266
  case '!mention':
208
- const number = msg.from.split('@')[0]
209
- await client.sendMessage(msg.from, {
267
+ const number = msg.sender.split('@')[0]
268
+ await client.sendMessage(msgFrom, {
210
269
  type: 'text',
211
270
  text: `Hey @${number}! How are you?`,
212
- mentions: [msg.from]
271
+ mentions: [number]
272
+ })
273
+ break
274
+ case '!mentionall':
275
+ if (!isGroupMsg) {
276
+ await client.sendMessage(msgFrom, 'This command is only for groups')
277
+ return
278
+ }
279
+ await client.sendMessage(msgFrom, {
280
+ type: 'text',
281
+ text: `Hey @all! How are you?`,
282
+ mentions: ['@all']
213
283
  })
214
284
  break
215
-
216
285
  case '!reply':
217
286
  await msg.reply('This is a reply message')
218
287
  break
219
288
 
220
289
  case '!location':
221
- await client.sendMessage(msg.from, {
290
+ await client.sendMessage(msgFrom, {
222
291
  type: 'location',
223
292
  latitude: 24.121231,
224
293
  longitude: 55.1121221
@@ -226,7 +295,7 @@ async function start() {
226
295
  break
227
296
 
228
297
  case '!contact':
229
- await client.sendMessage(msg.from, {
298
+ await client.sendMessage(msgFrom, {
230
299
  type: 'contact',
231
300
  fullName: 'John Doe',
232
301
  organization: 'Example Corp',
@@ -236,7 +305,7 @@ async function start() {
236
305
 
237
306
  case '!react':
238
307
  await client.sendMessage(
239
- msg.from,
308
+ msgFrom,
240
309
  {
241
310
  type: 'reaction',
242
311
  emoji: 'šŸ’–',
@@ -246,24 +315,36 @@ async function start() {
246
315
  break
247
316
  case '!media':
248
317
  if (fs.existsSync('./example.jpg')) {
249
- await client.sendMedia(msg.from, './example.jpg', {
318
+ await client.sendMedia(msgFrom, './example.jpg', {
250
319
  caption: 'Check out this image!'
251
320
  })
252
321
  } else {
253
- await client.sendMessage(msg.from, 'Example image not found')
322
+ await client.sendMessage(msgFrom, 'Example image not found')
323
+ }
324
+ break
325
+
326
+ case '!urlimage':
327
+ try {
328
+ const integrationFormula = '\\dpi{900}\\int\\frac{1}{x}dx=\\ln\\left|x\\right|+C';
329
+ const mediaurl = `https://latex.codecogs.com/png.image?${encodeURIComponent(integrationFormula)}`;
330
+ await client.sendMedia(msgFrom, mediaurl, {
331
+ caption: 'Check out this image!'
332
+ })
333
+ } catch (error) {
334
+ await client.sendMessage(msgFrom, `Failed to send image from URL: ${error.message}`)
254
335
  }
255
336
  break
256
337
 
257
338
  case '!doc':
258
339
  if (fs.existsSync('./example.pdf')) {
259
- await client.sendDocument(msg.from, './example.pdf', 'Check out this document!')
340
+ await client.sendDocument(msgFrom, './example.pdf', 'Check out this document!')
260
341
  } else {
261
- await client.sendMessage(msg.from, 'Example document not found')
342
+ await client.sendMessage(msgFrom, 'Example document not found')
262
343
  }
263
344
  break
264
345
 
265
346
  case '!list':
266
- await client.SendList(msg.from, {
347
+ await client.SendList(msgFrom, {
267
348
  text: 'Please select an option from the list below:',
268
349
  title: 'Comprehensive Menu',
269
350
  buttonText: 'View All Options',
@@ -298,7 +379,7 @@ async function start() {
298
379
  break
299
380
  case '!buttons':
300
381
  // Example: Send a text interactive message (modern Baileys format)
301
- await client.sendButtons(msg.from, {
382
+ await client.sendButtons(msgFrom, {
302
383
  text: 'Do you like this bot?',
303
384
  title: 'Feedback',
304
385
  subtitle: 'Let us know!',
@@ -323,7 +404,7 @@ async function start() {
323
404
 
324
405
  // Example: Send an image interactive message (modern Baileys format)
325
406
 
326
- await client.sendButtons(msg.from, {
407
+ await client.sendButtons(msgFrom, {
327
408
  imagePath: './example.jpg',
328
409
  caption: 'here is captions of image\nwith linebreaks', // Keep it short and concise
329
410
  title: 'Image Title', // Max 24 chars
@@ -372,7 +453,7 @@ async function start() {
372
453
  break
373
454
 
374
455
  case '!quickreplyv2':
375
- await client.sendQuickReplyV2(msg.from, 'Please select an option below:', [
456
+ await client.sendQuickReplyV2(msgFrom, 'Please select an option below:', [
376
457
  { id: 'btn-1', displayText: 'āœ… Accept' },
377
458
  { id: 'btn-2', displayText: 'āŒ Reject' },
378
459
  { id: 'btn-3', displayText: 'šŸ“ž Contact Support' }
@@ -380,17 +461,17 @@ async function start() {
380
461
  break
381
462
 
382
463
  case '!urlbuttonv2':
383
- await client.sendUrlButtonV2(msg.from, 'Visit our website for more info', [
464
+ await client.sendUrlButtonV2(msgFrom, 'Visit our website for more info', [
384
465
  { displayText: '🌐 Open Website', url: 'https://example.com' }
385
466
  ], { title: 'Product Info', footer: 'Click to open' });
386
467
  break
387
468
 
388
469
  case '!copycodev2':
389
- await client.sendCopyCodeV2(msg.from, 'Your OTP Code is:', '123456', 'šŸ“‹ Copy Code');
470
+ await client.sendCopyCodeV2(msgFrom, 'Your OTP Code is:', '123456', 'šŸ“‹ Copy Code');
390
471
  break
391
472
 
392
473
  case '!combinedv2':
393
- await client.sendCombinedButtonsV2(msg.from, 'Choose an action:', [
474
+ await client.sendCombinedButtonsV2(msgFrom, 'Choose an action:', [
394
475
  { type: 'reply', displayText: 'šŸ›’ Order Now', id: 'order' },
395
476
  { type: 'url', displayText: '🌐 Website', url: 'https://example.com' },
396
477
  { type: 'call', displayText: 'šŸ“ž Phone', phoneNumber: '+923224559543' },
@@ -399,7 +480,7 @@ async function start() {
399
480
  break
400
481
 
401
482
  case '!listv2':
402
- await client.sendListV2(msg.from, {
483
+ await client.sendListV2(msgFrom, {
403
484
  title: 'šŸ“‹ Product Menu',
404
485
  buttonText: 'View Menu',
405
486
  description: 'Please select a product',
@@ -423,6 +504,90 @@ async function start() {
423
504
  });
424
505
  break
425
506
 
507
+ case '!cards':
508
+ if (fs.existsSync('./example.jpg')) {
509
+ const imageBuffer = fs.readFileSync('./example.jpg');
510
+ const videoBuffer = fs.readFileSync('./example.mp4');
511
+
512
+ await client.sendcards(msgFrom, {
513
+ text: 'Body Message',
514
+ title: 'Title Message',
515
+ subtile: 'Subtitle Message',
516
+ footer: 'Footer Message',
517
+ cards: [
518
+ {
519
+ image: imageBuffer, // use local buffer
520
+ title: 'Title Cards 1',
521
+ body: 'Body Cards 1',
522
+ footer: 'Footer Cards 1',
523
+ buttons: [
524
+ {
525
+ name: 'quick_reply',
526
+ buttonParamsJson: JSON.stringify({
527
+ display_text: 'Display Button',
528
+ id: 'ID'
529
+ })
530
+ },
531
+ {
532
+ name: 'cta_url',
533
+ buttonParamsJson: JSON.stringify({
534
+ display_text: 'Display Button',
535
+ url: 'https://www.example.com'
536
+ })
537
+ }
538
+ ]
539
+ },
540
+ {
541
+ video: { url: 'https://files.inqscribe.com/samples/IS_Intro.mp4' },//videoBuffer, // use same local buffer for second card
542
+ title: 'Title Cards 2',
543
+ body: 'Body Cards 2',
544
+ footer: 'Video URL',
545
+ buttons: [
546
+ {
547
+ name: 'quick_reply',
548
+ buttonParamsJson: JSON.stringify({
549
+ display_text: 'Display Button',
550
+ id: 'ID2'
551
+ })
552
+ },
553
+ {
554
+ name: 'cta_url',
555
+ buttonParamsJson: JSON.stringify({
556
+ display_text: 'Display Button',
557
+ url: 'https://www.example.com'
558
+ })
559
+ }
560
+ ]
561
+ },
562
+ {
563
+ video: videoBuffer, // use same local buffer for second card
564
+ title: 'Title Cards 3',
565
+ body: 'Body Cards 3',
566
+ footer: 'Video Buffer',
567
+ buttons: [
568
+ {
569
+ name: 'quick_reply',
570
+ buttonParamsJson: JSON.stringify({
571
+ display_text: 'Display Button',
572
+ id: 'ID3'
573
+ })
574
+ },
575
+ {
576
+ name: 'cta_url',
577
+ buttonParamsJson: JSON.stringify({
578
+ display_text: 'Display Button',
579
+ url: 'https://www.example.com'
580
+ })
581
+ }
582
+ ]
583
+ }
584
+ ]
585
+ });
586
+ } else {
587
+ await client.sendMessage(msgFrom, 'Example image (example.jpg) not found for cards demonstration.');
588
+ }
589
+ break
590
+
426
591
 
427
592
  case '!call':
428
593
  try {
@@ -430,11 +595,11 @@ async function start() {
430
595
  clearTimeout(autoCancelCallTimer);
431
596
  autoCancelCallTimer = null;
432
597
  }
433
- const result = await client.initiateCall(msg.from);
598
+ const result = await client.initiateCall(msgFrom);
434
599
  lastOutgoingCallId = result?.callId || null;
435
- lastOutgoingCallJid = msg.from;
600
+ lastOutgoingCallJid = msgFrom;
436
601
 
437
- await client.sendMessage(msg.from, `Calling... CallId: ${lastOutgoingCallId || 'unknown'}`);
602
+ await client.sendMessage(msgFrom, `Calling... CallId: ${lastOutgoingCallId || 'unknown'}`);
438
603
 
439
604
  if (lastOutgoingCallId) {
440
605
  autoCancelCallTimer = setTimeout(async () => {
@@ -451,7 +616,7 @@ async function start() {
451
616
  }
452
617
  } catch (error) {
453
618
  console.error('Error initiating voice call:', error);
454
- await client.sendMessage(msg.from, 'Failed to initiate call');
619
+ await client.sendMessage(msgFrom, 'Failed to initiate call');
455
620
  }
456
621
  break
457
622
 
@@ -461,10 +626,10 @@ async function start() {
461
626
  clearTimeout(autoCancelCallTimer);
462
627
  autoCancelCallTimer = null;
463
628
  }
464
- const result = await client.initiateCall(msg.from, { isVideo: true });
629
+ const result = await client.initiateCall(msgFrom, { isVideo: true });
465
630
  lastOutgoingCallId = result?.callId || null;
466
- lastOutgoingCallJid = msg.from;
467
- await client.sendMessage(msg.from, `Video calling... CallId: ${lastOutgoingCallId || 'unknown'}`);
631
+ lastOutgoingCallJid = msgFrom;
632
+ await client.sendMessage(msgFrom, `Video calling... CallId: ${lastOutgoingCallId || 'unknown'}`);
468
633
 
469
634
  if (lastOutgoingCallId) {
470
635
  autoCancelCallTimer = setTimeout(async () => {
@@ -481,7 +646,7 @@ async function start() {
481
646
  }
482
647
  } catch (error) {
483
648
  console.error('Error initiating video call:', error);
484
- await client.sendMessage(msg.from, 'Failed to initiate video call');
649
+ await client.sendMessage(msgFrom, 'Failed to initiate video call');
485
650
  }
486
651
  break
487
652
 
@@ -492,16 +657,16 @@ async function start() {
492
657
  autoCancelCallTimer = null;
493
658
  }
494
659
  if (!lastOutgoingCallId) {
495
- await client.sendMessage(msg.from, 'No outgoing call to cancel');
660
+ await client.sendMessage(msgFrom, 'No outgoing call to cancel');
496
661
  break;
497
662
  }
498
- await client.cancelCall(lastOutgoingCallId, msg.from);
499
- await client.sendMessage(msg.from, `Canceled call: ${lastOutgoingCallId}`);
663
+ await client.cancelCall(lastOutgoingCallId, msgFrom);
664
+ await client.sendMessage(msgFrom, `Canceled call: ${lastOutgoingCallId}`);
500
665
  lastOutgoingCallId = null;
501
666
  lastOutgoingCallJid = null;
502
667
  } catch (error) {
503
668
  console.error('Error canceling call:', error);
504
- await client.sendMessage(msg.from, 'Failed to cancel call');
669
+ await client.sendMessage(msgFrom, 'Failed to cancel call');
505
670
  }
506
671
  break
507
672
 
@@ -562,14 +727,33 @@ async function start() {
562
727
  `• !updatestatus <text> - Update profile status\n` +
563
728
  `• !updatename <text> - Update profile name\n\n` +
564
729
 
730
+ `*šŸ¤– Rich AI Messaging*\n` +
731
+ `• !table - Send a formatted table\n` +
732
+ `• !richlist - Send a bulleted list\n` +
733
+ `• !codeblock - Send a syntax-highlighted code snippet\n` +
734
+ `• !latex - Send LaTeX text\n` +
735
+ `• !lateximage - Send LaTeX image\n` +
736
+ `• !latexinlineimage - Send LaTeX inline image\n` +
737
+ `• !rich - Send demo rich message\n` +
738
+ `• !markdown - Send native markdown message\n` +
739
+ `• !richresponse - Send rich text with code block\n\n` +
740
+
565
741
  `*šŸŽ›ļø Templates & Buttons*\n` +
566
742
  `• !buttons - Button template\n` +
567
- `• !list - Scrollable list\n` +
743
+ `• !list - Scrollable list\n\n` +
568
744
  `• !quickreplyv2 - Quick reply buttons V2\n` +
569
745
  `• !urlbuttonv2 - URL button V2\n` +
570
746
  `• !copycodev2 - Copy code button V2\n` +
571
747
  `• !combinedv2 - Mixed buttons V2\n` +
572
- `• !listv2 - Interactive list V2\n\n` +
748
+ `• !listv2 - Interactive list V2\n` +
749
+ `• !cards - Interactive cards message\n\n` +
750
+
751
+ `*🟢 Status*\n` +
752
+ `• !statustext - Post a text status\n` +
753
+ `• !statusimage - Post an image status\n` +
754
+ `• !statusvideo - Post a video status\n` +
755
+ `• !statusvoice - Post a voice note status\n` +
756
+ `• !groupstatus - Post a status directly inside a group (@g.us)\n\n` +
573
757
 
574
758
  `*šŸ“ž Calls*\n` +
575
759
  `• !call - Initiate a voice call\n` +
@@ -603,9 +787,179 @@ async function start() {
603
787
  `• !logout - End session\n\n` +
604
788
 
605
789
  `*šŸ“ Note*:\nReplace <number> with phone number\n(without + or spaces)`
606
- await client.sendMessage(msg.from, help)
790
+ await client.sendMessage(msgFrom, help)
607
791
  break
608
792
 
793
+ case '!table':
794
+ await client.sendTable(
795
+ msgFrom,
796
+ 'Price List',
797
+ ['Item', 'Qty', 'Price'],
798
+ [
799
+ ['Apple', '3', '$1.50'],
800
+ ['Banana', '6', '$0.90'],
801
+ ['Cherry', '1', '$3.00']
802
+ ],
803
+ msg.raw,
804
+ { headerText: 'Here is your order summary:', footer: 'Thank you!' }
805
+ );
806
+ break;
807
+
808
+ case '!richlist':
809
+ await client.sendRichList(
810
+ msgFrom,
811
+ 'Available Commands',
812
+ ['!help', '!ping', '!menu', '!info'],
813
+ msg.raw,
814
+ { headerText: 'Bot commands:', footer: 'Type any command to use it.' }
815
+ );
816
+ break;
817
+
818
+ case '!codeblock':
819
+ await client.sendCodeBlock(
820
+ msgFrom,
821
+ `async function fetchData(url) {\n const res = await fetch(url)\n return res.json()\n}`,
822
+ msg.raw,
823
+ { title: 'šŸ“¦ Example – fetch helper', language: 'javascript', footer: 'Copy and paste into your project.' }
824
+ );
825
+ break;
826
+
827
+ case '!latex':
828
+ await client.sendLatex(
829
+ msgFrom,
830
+ { text: 'Quadratic formula:', expressions: [{ latexExpression: 'x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}' }] }
831
+ );
832
+ break;
833
+
834
+ case '!lateximage':
835
+ try {
836
+ await client.sendLatexImage(
837
+ msgFrom,
838
+ {
839
+ formula: 'E=mc^2',
840
+ caption: 'Mass-Energy Equivalence (DPI 600)'
841
+ }
842
+ );
843
+ } catch (error) {
844
+ return (error)
845
+ }
846
+ break;
847
+
848
+ case '!latexinlineimage':
849
+ try {
850
+ await client.sendLatexInlineImage(
851
+ msgFrom,
852
+ {
853
+ expressions: [
854
+ { latexExpression: 'e^{i\\pi} + 1 = 0' },
855
+ { latexExpression: '\\int_a^b x^2 \\, dx = \\frac{b^3 - a^3}{3}' },
856
+ { latexExpression: 'f(x) = \\sum_{n=0}^{\\infty} \\frac{f^{(n)}(a)}{n!} (x-a)^n' }
857
+ ],
858
+ caption: true // Use each LaTeX expression as the caption for its respective image in the album
859
+ }
860
+ );
861
+ } catch (error) {
862
+ return (error)
863
+ }
864
+ break;
865
+
866
+ case '!rich':
867
+ const richLatexExpr = 'E = mc^2';
868
+ const richPngBuf = await renderLatexToPng(richLatexExpr);
869
+ const richImageUrl = (await uploadUnencryptedToWA(richPngBuf.buffer, client.sock.waUploadToServer)).url;
870
+
871
+ await client.sendRichMessage(msgFrom, [
872
+ {
873
+ messageType: RichSubMessageType.TEXT,
874
+ messageText: '# H1\n## H2\n### H3\n#### H4\n##### H5\n###### H6\n\n___\n\n> To use a horizontal line, you need to have two "\\n" above and below the "___"\n==Highlighted text==\n# By the way, ^you^ can _mix_ ==multiple markdowns== for a **richer response**\n###### Try different combinations...'
875
+ },
876
+ {
877
+ messageType: RichSubMessageType.TABLE,
878
+ tableMetadata: {
879
+ title: 'Product Prices',
880
+ rows: [
881
+ { items: ['Product', 'Price', 'Stock'], isHeading: true },
882
+ { items: ['Innovators Baileys Pro', '$49.99', 'In Stock'] },
883
+ { items: ['Rust WASM Plugin', '$19.99', 'Low Stock'] }
884
+ ]
885
+ }
886
+ },
887
+ {
888
+ messageType: RichSubMessageType.TEXT,
889
+ messageText: 'LaTeX Formula:'
890
+ },
891
+ {
892
+ messageType: RichSubMessageType.INLINE_IMAGE,
893
+ imageMetadata: {
894
+ imageUrl: {
895
+ imagePreviewUrl: richImageUrl,
896
+ imageHighResUrl: richImageUrl
897
+ },
898
+ imageText: richLatexExpr,
899
+ alignment: 2
900
+ }
901
+ },
902
+ {
903
+ messageType: RichSubMessageType.CODE,
904
+ codeMetadata: {
905
+ codeLanguage: 'javascript',
906
+ codeBlocks: [
907
+ { highlightType: 1, codeContent: 'const ' },
908
+ { highlightType: 0, codeContent: 'price = ' },
909
+ { highlightType: 4, codeContent: '49.99' },
910
+ { highlightType: 0, codeContent: ';\n' },
911
+ { highlightType: 1, codeContent: 'if ' },
912
+ { highlightType: 0, codeContent: '(price > ' },
913
+ { highlightType: 4, codeContent: '20' },
914
+ { highlightType: 0, codeContent: ') {\n console.log(' },
915
+ { highlightType: 3, codeContent: '"Premium tier"' },
916
+ { highlightType: 0, codeContent: ');\n}' }
917
+ ]
918
+ }
919
+ }
920
+ ], null, { useMarkdown: true });
921
+ break;
922
+
923
+ case '!markdown':
924
+ await client.sendMarkdown(
925
+ msgFrom,
926
+ '# Markdown Demo\n## Headers work\n==Highlighted text==\n_Italics_ and **Bold** are supported!',
927
+ msg.raw
928
+ );
929
+ break;
930
+
931
+ case '!richresponse':
932
+ // Demonstrate that sendMessage can now natively accept an array of rich submessages
933
+ await client.sendMessage(msgFrom, {
934
+ richResponse: [
935
+ {
936
+ messageType: 2,
937
+ messageText: '# H1\n## H2\n### H3\n#### H4\n##### H5\n###### H6\n\n___\n\n> To use a horizontal line, you need to have two "\\n" above and below the "___"\n==Highlighted text==\n# By the way, ^you^ can _mix_ ==multiple markdowns== for a **richer response**\n###### Try different combinations...'
938
+ },
939
+ {
940
+ messageType: 2,
941
+ messageText: 'And here is a syntax-highlighted code block natively passed:'
942
+ },
943
+ {
944
+ messageType: 5,
945
+ codeMetadata: {
946
+ codeLanguage: 'javascript',
947
+ codeBlocks: [
948
+ { highlightType: 1, codeContent: 'const ' },
949
+ { highlightType: 0, codeContent: 'greet = (name) => {\n console.log(' },
950
+ { highlightType: 3, codeContent: '"Hello, "' },
951
+ { highlightType: 0, codeContent: ' + name)\n}\n' },
952
+ { highlightType: 0, codeContent: 'greet(' },
953
+ { highlightType: 3, codeContent: '"World"' },
954
+ { highlightType: 0, codeContent: ')' }
955
+ ]
956
+ }
957
+ }
958
+ ]
959
+ },
960
+ { markdown: true });
961
+ break;
962
+
609
963
  case '!groups':
610
964
  try {
611
965
  const groups = await client.getAllGroups()
@@ -619,13 +973,13 @@ async function start() {
619
973
  if (group.desc) groupList += ` Description: ${group.desc}\n`
620
974
  groupList += '\n'
621
975
  })
622
- await client.sendMessage(msg.from, groupList)
976
+ await client.sendMessage(msgFrom, groupList)
623
977
  } else {
624
- await client.sendMessage(msg.from, 'You are not in any groups')
978
+ await client.sendMessage(msgFrom, 'You are not in any groups')
625
979
  }
626
980
  } catch (error) {
627
981
  console.error('Error fetching groups:', error)
628
- await client.sendMessage(msg.from, 'Failed to fetch groups')
982
+ await client.sendMessage(msgFrom, 'Failed to fetch groups')
629
983
  }
630
984
  break
631
985
 
@@ -634,7 +988,7 @@ async function start() {
634
988
  // Use provided group JID or current group
635
989
  const groupJid = args.trim() || msg.raw.key.remoteJid
636
990
  if (!groupJid || !groupJid.endsWith('@g.us')) {
637
- await client.sendMessage(msg.from, 'āŒ Please provide a group JID or use this command in a group.\nUsage: !groupinfo <groupJid>')
991
+ await client.sendMessage(msgFrom, 'āŒ Please provide a group JID or use this command in a group.\nUsage: !groupinfo <groupJid>')
638
992
  break
639
993
  }
640
994
  const groupInfo = await client.getGroupMetadata(groupJid)
@@ -659,18 +1013,18 @@ async function start() {
659
1013
  groupList += '\n'
660
1014
  })
661
1015
 
662
- await client.sendMessage(msg.from, groupList)
1016
+ await client.sendMessage(msgFrom, groupList)
663
1017
  } else {
664
- await client.sendMessage(msg.from, 'Group not found')
1018
+ await client.sendMessage(msgFrom, 'Group not found')
665
1019
  }
666
1020
  } catch (error) {
667
1021
  console.error('Error fetching group info:', error)
668
- await client.sendMessage(msg.from, 'Failed to fetch group info')
1022
+ await client.sendMessage(msgFrom, 'Failed to fetch group info')
669
1023
  }
670
1024
  break
671
1025
  case '!logout':
672
1026
  // Ask for confirmation before logging out
673
- await client.sendButtons(msg.from, {
1027
+ await client.sendButtons(msgFrom, {
674
1028
  text: 'Are you sure you want to logout?',
675
1029
  title: 'Logout Confirmation',
676
1030
  footer: 'Choose Yes to logout or No to cancel',
@@ -697,26 +1051,26 @@ async function start() {
697
1051
  case 'yes':
698
1052
  case 'logout_yes':
699
1053
 
700
- await client.sendMessage(msg.from, 'You have been logged out.');
1054
+ await client.sendMessage(msgFrom, 'You have been logged out.');
701
1055
  await client.logout();
702
1056
  break;
703
1057
  case 'No':
704
1058
  case 'no':
705
1059
  case 'logout_no':
706
- await client.sendMessage(msg.from, 'Logout cancelled.');
1060
+ await client.sendMessage(msgFrom, 'Logout cancelled.');
707
1061
  break;
708
1062
  case '!lid':
709
1063
  // Get LID for the user's phone number
710
1064
  try {
711
- const lid = await client.getLIDForPN(msg.from);
1065
+ const lid = await client.getLIDForPN(msgFrom);
712
1066
  if (lid) {
713
- await client.sendMessage(msg.from, `Your LID: ${lid}\nYour PN: ${msg.from}`);
1067
+ await client.sendMessage(msgFrom, `Your LID: ${lid}\nYour PN: ${msgFrom}`);
714
1068
  } else {
715
- await client.sendMessage(msg.from, `No LID found for ${msg.from}. You might be using a PN-only session.`);
1069
+ await client.sendMessage(msgFrom, `No LID found for ${msgFrom}. You might be using a PN-only session.`);
716
1070
  }
717
1071
  } catch (error) {
718
1072
  console.error('Error getting LID:', error);
719
- await client.sendMessage(msg.from, 'Failed to get LID.');
1073
+ await client.sendMessage(msgFrom, 'Failed to get LID.');
720
1074
  }
721
1075
  break;
722
1076
 
@@ -725,23 +1079,23 @@ async function start() {
725
1079
  try {
726
1080
  const lidToCheck = args.trim();
727
1081
  if (!lidToCheck) {
728
- await client.sendMessage(msg.from, 'Please provide a LID. Example: !pn 123456@lid');
1082
+ await client.sendMessage(msgFrom, 'Please provide a LID. Example: !pn 123456@lid');
729
1083
  break;
730
1084
  }
731
1085
  const pn = await client.getPNForLID(lidToCheck);
732
1086
  if (pn) {
733
- await client.sendMessage(msg.from, `Phone Number for ${lidToCheck}: ${pn}`);
1087
+ await client.sendMessage(msgFrom, `Phone Number for ${lidToCheck}: ${pn}`);
734
1088
  } else {
735
- await client.sendMessage(msg.from, `No phone number found for LID: ${lidToCheck}`);
1089
+ await client.sendMessage(msgFrom, `No phone number found for LID: ${lidToCheck}`);
736
1090
  }
737
1091
  } catch (error) {
738
1092
  console.error('Error getting PN from LID:', error);
739
- await client.sendMessage(msg.from, 'Failed to get phone number.');
1093
+ await client.sendMessage(msgFrom, 'Failed to get phone number.');
740
1094
  }
741
1095
  break;
742
1096
  case '!ad':
743
1097
  await client.sendAdReply(
744
- msg.from,
1098
+ msgFrom,
745
1099
  'Ad Message',
746
1100
  './example.jpg',
747
1101
  'Ad Title',
@@ -754,82 +1108,82 @@ async function start() {
754
1108
  if (fs.existsSync('./example.jpg')) {
755
1109
  const path = './example.jpg';
756
1110
  const imageBuffer = fs.readFileSync(path);
757
- await client.sendSticker(msg.from, imageBuffer, { packName: 'Innovators', author: 'Innovators Soft' });
1111
+ await client.sendSticker(msgFrom, imageBuffer, { packName: 'Innovators', author: 'Innovators Soft' });
758
1112
  } else {
759
- await client.sendMessage(msg.from, 'Example image (jpg) not found')
1113
+ await client.sendMessage(msgFrom, 'Example image (jpg) not found')
760
1114
  }
761
1115
  break;
762
1116
 
763
1117
  case '!parse':
764
1118
  if (args) {
765
1119
  const info = client.parseJid(args);
766
- await client.sendMessage(msg.from, `*JID Info:*\n\nUser: ${info.user}\nServer: ${info.server}\nIs LID: ${info.isLid}`);
1120
+ await client.sendMessage(msgFrom, `*JID Info:*\n\nUser: ${info.user}\nServer: ${info.server}\nIs LID: ${info.isLid}`);
767
1121
  } else {
768
- await client.sendMessage(msg.from, 'Please provide a JID to parse');
1122
+ await client.sendMessage(msgFrom, 'Please provide a JID to parse');
769
1123
  }
770
1124
  break;
771
1125
 
772
1126
  case '!normalize':
773
1127
  if (args) {
774
1128
  const jid = client.normalizePhoneToJid(args);
775
- await client.sendMessage(msg.from, `*Normalized JID:* ${jid}`);
1129
+ await client.sendMessage(msgFrom, `*Normalized JID:* ${jid}`);
776
1130
  } else {
777
- await client.sendMessage(msg.from, 'Please provide a phone number');
1131
+ await client.sendMessage(msgFrom, 'Please provide a phone number');
778
1132
  }
779
1133
  break;
780
1134
 
781
1135
  case '!typing':
782
- await client.sendStateTyping(msg.from);
783
- await client.sendMessage(msg.from, 'Typing indicator sent!');
1136
+ await client.sendStateTyping(msgFrom);
1137
+ await client.sendMessage(msgFrom, 'Typing indicator sent!');
784
1138
  break;
785
1139
 
786
1140
  case '!recording':
787
- await client.sendStateRecording(msg.from);
788
- await client.sendMessage(msg.from, 'Recording indicator sent!');
1141
+ await client.sendStateRecording(msgFrom);
1142
+ await client.sendMessage(msgFrom, 'Recording indicator sent!');
789
1143
  break;
790
1144
 
791
1145
  case '!paused':
792
- await client.clearState(msg.from);
793
- await client.sendMessage(msg.from, 'Stopped typing/recording indicator sent!');
1146
+ await client.clearState(msgFrom);
1147
+ await client.sendMessage(msgFrom, 'Stopped typing/recording indicator sent!');
794
1148
  break;
795
1149
 
796
1150
  case '!typing_simulate':
797
1151
  // Show "typing..." for 5 seconds, then send the message — all in one call
798
- await client.sendMessage(msg.from, 'Simulating typing for 5 seconds...');
1152
+ await client.sendMessage(msgFrom, 'Simulating typing for 5 seconds...');
799
1153
  const typing = client.createPresenceController();
800
- await typing.simulateTyping(msg.from, 5000, async () => {
801
- await client.sendMessage(msg.from, 'This message was sent after 5 seconds of typing! āœ…');
1154
+ await typing.simulateTyping(msgFrom, 5000, async () => {
1155
+ await client.sendMessage(msgFrom, 'This message was sent after 5 seconds of typing! āœ…');
802
1156
  });
803
1157
  break;
804
1158
 
805
1159
  case '!typing_start':
806
1160
  // Manual start (auto-pauses after 5 s by default if not specified)
807
1161
  const typingStart = client.createPresenceController();
808
- await typingStart.startTyping(msg.from, { duration: 10000 }); // Show for 10s
809
- await client.sendMessage(msg.from, 'Typing indicator started for 10 seconds.');
1162
+ await typingStart.startTyping(msgFrom, { duration: 10000 }); // Show for 10s
1163
+ await client.sendMessage(msgFrom, 'Typing indicator started for 10 seconds.');
810
1164
  break;
811
1165
 
812
1166
  case '!typing_stop':
813
1167
  const typingStop = client.createPresenceController();
814
- await typingStop.stopTyping(msg.from);
815
- await client.sendMessage(msg.from, 'Typing indicator stopped.');
1168
+ await typingStop.stopTyping(msgFrom);
1169
+ await client.sendMessage(msgFrom, 'Typing indicator stopped.');
816
1170
  break;
817
1171
 
818
1172
  case '!recording_start':
819
1173
  const recordingIndicator = client.createPresenceController();
820
- await recordingIndicator.startRecording(msg.from, { duration: 5000 });
821
- await client.sendMessage(msg.from, 'Recording indicator started for 5 seconds.');
1174
+ await recordingIndicator.startRecording(msgFrom, { duration: 5000 });
1175
+ await client.sendMessage(msgFrom, 'Recording indicator started for 5 seconds.');
822
1176
  break;
823
1177
 
824
1178
  case '!typing_stop_all':
825
1179
  const typingStopAll = client.createPresenceController();
826
1180
  await typingStopAll.stopAll();
827
- await client.sendMessage(msg.from, 'All active indicators for this controller stopped.');
1181
+ await client.sendMessage(msgFrom, 'All active indicators for this controller stopped.');
828
1182
  break;
829
1183
 
830
1184
  case '!read':
831
1185
  await client.readMessage(msg.raw.key);
832
- await client.sendMessage(msg.from, 'Message marked as read!');
1186
+ await client.sendMessage(msgFrom, 'Message marked as read!');
833
1187
  break;
834
1188
 
835
1189
  case '!add':
@@ -838,7 +1192,7 @@ async function start() {
838
1192
  case '!demote':
839
1193
  try {
840
1194
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
841
- await client.sendMessage(msg.from, 'This command can only be used in groups')
1195
+ await client.sendMessage(msgFrom, 'This command can only be used in groups')
842
1196
  break
843
1197
  }
844
1198
 
@@ -846,7 +1200,7 @@ async function start() {
846
1200
 
847
1201
  // Validate phone number format
848
1202
  if (!rawNumber || rawNumber.length < 10) {
849
- await client.sendMessage(msg.from,
1203
+ await client.sendMessage(msgFrom,
850
1204
  `āŒ Invalid phone number format.\n\n` +
851
1205
  `āœ… Correct format: !${command.slice(1)} 923001234567\n` +
852
1206
  `(Include country code without + or spaces)`
@@ -856,7 +1210,7 @@ async function start() {
856
1210
 
857
1211
  // Ensure country code is present (check if starts with common codes)
858
1212
  if (rawNumber.startsWith('0')) {
859
- await client.sendMessage(msg.from,
1213
+ await client.sendMessage(msgFrom,
860
1214
  `āŒ Phone number must include country code.\n\n` +
861
1215
  `Example:\n` +
862
1216
  `• Pakistan: 923001234567 (not 03001234567)\n` +
@@ -885,18 +1239,18 @@ async function start() {
885
1239
  }
886
1240
 
887
1241
  if (result[0].status == 200) {
888
- await client.sendMessage(msg.from, `Successfully ${actionMap[action]} the group`)
1242
+ await client.sendMessage(msgFrom, `Successfully ${actionMap[action]} the group`)
889
1243
  } else if (result[0].status == 403 && result[0].invitationSent) {
890
- await client.sendMessage(msg.from, `āš ļø Could not add directly due to privacy settings.\nāœ… Group invitation link has been sent to the user instead!`)
1244
+ await client.sendMessage(msgFrom, `āš ļø Could not add directly due to privacy settings.\nāœ… Group invitation link has been sent to the user instead!`)
891
1245
  } else {
892
- await client.sendMessage(msg.from, `Failed to ${action} participant: ${result[0].message || result[0].content || result[0].error || 'Unknown error'}`)
1246
+ await client.sendMessage(msgFrom, `Failed to ${action} participant: ${result[0].message || result[0].content || result[0].error || 'Unknown error'}`)
893
1247
  }
894
1248
  } catch (error) {
895
1249
  console.error(`Error ${command} participant:`, error)
896
1250
  if (error.output?.statusCode === 408) {
897
- await client.sendMessage(msg.from, `ā±ļø Request timed out. The number might be invalid or not on WhatsApp.`)
1251
+ await client.sendMessage(msgFrom, `ā±ļø Request timed out. The number might be invalid or not on WhatsApp.`)
898
1252
  } else {
899
- await client.sendMessage(msg.from, `Failed to ${command.slice(1)} participant: ${error.message || 'Unknown error'}`)
1253
+ await client.sendMessage(msgFrom, `Failed to ${command.slice(1)} participant: ${error.message || 'Unknown error'}`)
900
1254
  }
901
1255
  }
902
1256
  break
@@ -905,7 +1259,7 @@ async function start() {
905
1259
  case '!invite':
906
1260
  try {
907
1261
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
908
- await client.sendMessage(msg.from, 'This command can only be used in groups')
1262
+ await client.sendMessage(msgFrom, 'This command can only be used in groups')
909
1263
  break
910
1264
  }
911
1265
 
@@ -913,7 +1267,7 @@ async function start() {
913
1267
 
914
1268
  // Validate phone number format
915
1269
  if (!rawInviteNumber || rawInviteNumber.length < 10) {
916
- await client.sendMessage(msg.from,
1270
+ await client.sendMessage(msgFrom,
917
1271
  `āŒ Invalid phone number format.\n\n` +
918
1272
  `āœ… Correct format: !invite 923001234567\n` +
919
1273
  `(Include country code without + or spaces)`
@@ -923,7 +1277,7 @@ async function start() {
923
1277
 
924
1278
  // Ensure country code is present
925
1279
  if (rawInviteNumber.startsWith('0')) {
926
- await client.sendMessage(msg.from,
1280
+ await client.sendMessage(msgFrom,
927
1281
  `āŒ Phone number must include country code.\n\n` +
928
1282
  `Example:\n` +
929
1283
  `• Pakistan: 923001234567 (not 03001234567)\n` +
@@ -936,13 +1290,13 @@ async function start() {
936
1290
  const inviteNumber = rawInviteNumber + '@s.whatsapp.net'
937
1291
 
938
1292
  await client.sendGroupInvitation(msg.raw.key.remoteJid, inviteNumber)
939
- await client.sendMessage(msg.from, `āœ… Group invitation sent to ${rawInviteNumber}`)
1293
+ await client.sendMessage(msgFrom, `āœ… Group invitation sent to ${rawInviteNumber}`)
940
1294
  } catch (error) {
941
1295
  console.error('Error sending invitation:', error)
942
1296
  if (error.output?.statusCode === 408) {
943
- await client.sendMessage(msg.from, `ā±ļø Request timed out. The number might be invalid or not on WhatsApp.`)
1297
+ await client.sendMessage(msgFrom, `ā±ļø Request timed out. The number might be invalid or not on WhatsApp.`)
944
1298
  } else {
945
- await client.sendMessage(msg.from, `Failed to send group invitation: ${error.message || 'Unknown error'}`)
1299
+ await client.sendMessage(msgFrom, `Failed to send group invitation: ${error.message || 'Unknown error'}`)
946
1300
  }
947
1301
  }
948
1302
  break
@@ -954,61 +1308,61 @@ async function start() {
954
1308
  case '!creategroup':
955
1309
  try {
956
1310
  if (!args) {
957
- await client.sendMessage(msg.from, 'āŒ Please provide a group name.\nUsage: !creategroup My New Group');
1311
+ await client.sendMessage(msgFrom, 'āŒ Please provide a group name.\nUsage: !creategroup My New Group');
958
1312
  break;
959
1313
  }
960
- const newGroup = await client.createGroup(args, [msg.sender]);
961
- await client.sendMessage(msg.from, `āœ… Group created!\n\nName: *${args}*\nID: ${newGroup.id || newGroup.gid}`);
1314
+ const newGroup = await client.createGroup(args, [msgFrom]);
1315
+ await client.sendMessage(msgFrom, `āœ… Group created!\n\nName: *${args}*\nID: ${newGroup.id || newGroup.gid}`);
962
1316
  } catch (error) {
963
1317
  console.error('Error creating group:', error);
964
- await client.sendMessage(msg.from, `āŒ Failed to create group: ${error.message}`);
1318
+ await client.sendMessage(msgFrom, `āŒ Failed to create group: ${error.message}`);
965
1319
  }
966
1320
  break;
967
1321
 
968
1322
  case '!groupsubject':
969
1323
  try {
970
1324
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
971
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1325
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
972
1326
  break;
973
1327
  }
974
1328
  if (!args) {
975
- await client.sendMessage(msg.from, 'āŒ Please provide a new group name.\nUsage: !groupsubject New Name');
1329
+ await client.sendMessage(msgFrom, 'āŒ Please provide a new group name.\nUsage: !groupsubject New Name');
976
1330
  break;
977
1331
  }
978
1332
  await client.changeGroupSubject(msg.raw.key.remoteJid, args);
979
- await client.sendMessage(msg.from, `āœ… Group name changed to: *${args}*`);
1333
+ await client.sendMessage(msgFrom, `āœ… Group name changed to: *${args}*`);
980
1334
  } catch (error) {
981
1335
  console.error('Error changing group subject:', error);
982
- await client.sendMessage(msg.from, `āŒ Failed to change group name: ${error.message}`);
1336
+ await client.sendMessage(msgFrom, `āŒ Failed to change group name: ${error.message}`);
983
1337
  }
984
1338
  break;
985
1339
 
986
1340
  case '!groupdesc':
987
1341
  try {
988
1342
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
989
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1343
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
990
1344
  break;
991
1345
  }
992
1346
  if (!args) {
993
- await client.sendMessage(msg.from, 'āŒ Please provide a new description.\nUsage: !groupdesc New description here');
1347
+ await client.sendMessage(msgFrom, 'āŒ Please provide a new description.\nUsage: !groupdesc New description here');
994
1348
  break;
995
1349
  }
996
1350
  await client.changeGroupDescription(msg.raw.key.remoteJid, args);
997
- await client.sendMessage(msg.from, `āœ… Group description updated!`);
1351
+ await client.sendMessage(msgFrom, `āœ… Group description updated!`);
998
1352
  } catch (error) {
999
1353
  console.error('Error changing group description:', error);
1000
- await client.sendMessage(msg.from, `āŒ Failed to change description: ${error.message}`);
1354
+ await client.sendMessage(msgFrom, `āŒ Failed to change description: ${error.message}`);
1001
1355
  }
1002
1356
  break;
1003
1357
 
1004
1358
  case '!groupsetting':
1005
1359
  try {
1006
1360
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1007
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1361
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1008
1362
  break;
1009
1363
  }
1010
1364
  if (!args || !['announcement', 'not_announcement', 'locked', 'unlocked'].includes(args.trim())) {
1011
- await client.sendMessage(msg.from,
1365
+ await client.sendMessage(msgFrom,
1012
1366
  `āŒ Invalid setting.\n\n` +
1013
1367
  `Usage: !groupsetting <setting>\n\n` +
1014
1368
  `Available settings:\n` +
@@ -1020,66 +1374,66 @@ async function start() {
1020
1374
  break;
1021
1375
  }
1022
1376
  await client.changeGroupSettings(msg.raw.key.remoteJid, args.trim());
1023
- await client.sendMessage(msg.from, `āœ… Group setting changed to: *${args.trim()}*`);
1377
+ await client.sendMessage(msgFrom, `āœ… Group setting changed to: *${args.trim()}*`);
1024
1378
  } catch (error) {
1025
1379
  console.error('Error changing group settings:', error);
1026
- await client.sendMessage(msg.from, `āŒ Failed to change setting: ${error.message}`);
1380
+ await client.sendMessage(msgFrom, `āŒ Failed to change setting: ${error.message}`);
1027
1381
  }
1028
1382
  break;
1029
1383
 
1030
1384
  case '!invitecode':
1031
1385
  try {
1032
1386
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1033
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1387
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1034
1388
  break;
1035
1389
  }
1036
1390
  const inviteCode = await client.getGroupInviteCode(msg.raw.key.remoteJid);
1037
- await client.sendMessage(msg.from, `āœ… Group Invite Link:\nhttps://chat.whatsapp.com/${inviteCode}`);
1391
+ await client.sendMessage(msgFrom, `āœ… Group Invite Link:\nhttps://chat.whatsapp.com/${inviteCode}`);
1038
1392
  } catch (error) {
1039
1393
  console.error('Error getting invite code:', error);
1040
- await client.sendMessage(msg.from, `āŒ Failed to get invite code: ${error.message}`);
1394
+ await client.sendMessage(msgFrom, `āŒ Failed to get invite code: ${error.message}`);
1041
1395
  }
1042
1396
  break;
1043
1397
 
1044
1398
  case '!revokeinvite':
1045
1399
  try {
1046
1400
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1047
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1401
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1048
1402
  break;
1049
1403
  }
1050
1404
  const newInviteCode = await client.revokeGroupInviteCode(msg.raw.key.remoteJid);
1051
- await client.sendMessage(msg.from, `āœ… Invite code revoked!\nNew invite link:\nhttps://chat.whatsapp.com/${newInviteCode}`);
1405
+ await client.sendMessage(msgFrom, `āœ… Invite code revoked!\nNew invite link:\nhttps://chat.whatsapp.com/${newInviteCode}`);
1052
1406
  } catch (error) {
1053
1407
  console.error('Error revoking invite code:', error);
1054
- await client.sendMessage(msg.from, `āŒ Failed to revoke invite code: ${error.message}`);
1408
+ await client.sendMessage(msgFrom, `āŒ Failed to revoke invite code: ${error.message}`);
1055
1409
  }
1056
1410
  break;
1057
1411
 
1058
1412
  case '!leavegroup':
1059
1413
  try {
1060
1414
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1061
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1415
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1062
1416
  break;
1063
1417
  }
1064
- await client.sendMessage(msg.from, 'šŸ‘‹ Leaving group...');
1418
+ await client.sendMessage(msgFrom, 'šŸ‘‹ Leaving group...');
1065
1419
  await client.leaveGroup(msg.raw.key.remoteJid);
1066
1420
  } catch (error) {
1067
1421
  console.error('Error leaving group:', error);
1068
- await client.sendMessage(msg.from, `āŒ Failed to leave group: ${error.message}`);
1422
+ await client.sendMessage(msgFrom, `āŒ Failed to leave group: ${error.message}`);
1069
1423
  }
1070
1424
  break;
1071
1425
 
1072
1426
  case '!joingroup':
1073
1427
  try {
1074
1428
  if (!args) {
1075
- await client.sendMessage(msg.from, 'āŒ Please provide an invite code.\nUsage: !joingroup AbCdEfGhIjK\n(or full link: !joingroup https://chat.whatsapp.com/AbCdEfGhIjK)');
1429
+ await client.sendMessage(msgFrom, 'āŒ Please provide an invite code.\nUsage: !joingroup AbCdEfGhIjK\n(or full link: !joingroup https://chat.whatsapp.com/AbCdEfGhIjK)');
1076
1430
  break;
1077
1431
  }
1078
1432
  const joinedGroupId = await client.joinGroupByInviteCode(args.trim());
1079
- await client.sendMessage(msg.from, `āœ… Successfully joined group!\nGroup ID: ${joinedGroupId}`);
1433
+ await client.sendMessage(msgFrom, `āœ… Successfully joined group!\nGroup ID: ${joinedGroupId}`);
1080
1434
  } catch (error) {
1081
1435
  console.error('Error joining group:', error);
1082
- await client.sendMessage(msg.from, `āŒ Failed to join group: ${error.message}`);
1436
+ await client.sendMessage(msgFrom, `āŒ Failed to join group: ${error.message}`);
1083
1437
  }
1084
1438
  break;
1085
1439
 
@@ -1091,7 +1445,7 @@ async function start() {
1091
1445
  if (!input) {
1092
1446
  // No args: use current group
1093
1447
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1094
- await client.sendMessage(msg.from, 'āŒ Use this command in a group, or provide a group JID / invite code.\nUsage:\n• !groupinfo (in a group)\n• !groupinfo 120363xxxxx@g.us\n• !groupinfo AbCdEfGhIjK')
1448
+ await client.sendMessage(msgFrom, 'āŒ Use this command in a group, or provide a group JID / invite code.\nUsage:\n• !groupinfo (in a group)\n• !groupinfo 120363xxxxx@g.us\n• !groupinfo AbCdEfGhIjK')
1095
1449
  break
1096
1450
  }
1097
1451
  groupInfoResult = await client.getGroupMetadata(msg.raw.key.remoteJid)
@@ -1104,7 +1458,7 @@ async function start() {
1104
1458
  }
1105
1459
 
1106
1460
  if (!groupInfoResult) {
1107
- await client.sendMessage(msg.from, 'āŒ Group not found.')
1461
+ await client.sendMessage(msgFrom, 'āŒ Group not found.')
1108
1462
  break
1109
1463
  }
1110
1464
 
@@ -1140,17 +1494,17 @@ async function start() {
1140
1494
  })
1141
1495
  }
1142
1496
 
1143
- await client.sendMessage(msg.from, infoText)
1497
+ await client.sendMessage(msgFrom, infoText)
1144
1498
  } catch (error) {
1145
1499
  console.error('Error getting group info:', error)
1146
- await client.sendMessage(msg.from, `āŒ Failed to get group info: ${error.message}`)
1500
+ await client.sendMessage(msgFrom, `āŒ Failed to get group info: ${error.message}`)
1147
1501
  }
1148
1502
  break;
1149
1503
 
1150
1504
  case '!joinrequests':
1151
1505
  try {
1152
1506
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1153
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1507
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1154
1508
  break;
1155
1509
  }
1156
1510
  const requests = await client.getGroupJoinRequests(msg.raw.key.remoteJid);
@@ -1161,63 +1515,63 @@ async function start() {
1161
1515
  if (req.request_time) requestList += ` Requested: ${new Date(req.request_time * 1000).toLocaleString()}\n`;
1162
1516
  });
1163
1517
  requestList += `\nUse !approvejoin or !rejectjoin <number> to respond`;
1164
- await client.sendMessage(msg.from, requestList);
1518
+ await client.sendMessage(msgFrom, requestList);
1165
1519
  } else {
1166
- await client.sendMessage(msg.from, 'āœ… No pending join requests.');
1520
+ await client.sendMessage(msgFrom, 'āœ… No pending join requests.');
1167
1521
  }
1168
1522
  } catch (error) {
1169
1523
  console.error('Error getting join requests:', error);
1170
- await client.sendMessage(msg.from, `āŒ Failed to get join requests: ${error.message}`);
1524
+ await client.sendMessage(msgFrom, `āŒ Failed to get join requests: ${error.message}`);
1171
1525
  }
1172
1526
  break;
1173
1527
 
1174
1528
  case '!approvejoin':
1175
1529
  try {
1176
1530
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1177
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1531
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1178
1532
  break;
1179
1533
  }
1180
1534
  const approveNum = args?.replace(/[^0-9]/g, '');
1181
1535
  if (!approveNum || approveNum.length < 10) {
1182
- await client.sendMessage(msg.from, 'āŒ Please provide a valid phone number.\nUsage: !approvejoin 923001234567');
1536
+ await client.sendMessage(msgFrom, 'āŒ Please provide a valid phone number.\nUsage: !approvejoin 923001234567');
1183
1537
  break;
1184
1538
  }
1185
1539
  const approveResult = await client.handleGroupJoinRequest(msg.raw.key.remoteJid, [approveNum + '@s.whatsapp.net'], 'approve');
1186
- await client.sendMessage(msg.from, `āœ… Join request approved for ${approveNum}`);
1540
+ await client.sendMessage(msgFrom, `āœ… Join request approved for ${approveNum}`);
1187
1541
  } catch (error) {
1188
1542
  console.error('Error approving join request:', error);
1189
- await client.sendMessage(msg.from, `āŒ Failed to approve: ${error.message}`);
1543
+ await client.sendMessage(msgFrom, `āŒ Failed to approve: ${error.message}`);
1190
1544
  }
1191
1545
  break;
1192
1546
 
1193
1547
  case '!rejectjoin':
1194
1548
  try {
1195
1549
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1196
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1550
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1197
1551
  break;
1198
1552
  }
1199
1553
  const rejectNum = args?.replace(/[^0-9]/g, '');
1200
1554
  if (!rejectNum || rejectNum.length < 10) {
1201
- await client.sendMessage(msg.from, 'āŒ Please provide a valid phone number.\nUsage: !rejectjoin 923001234567');
1555
+ await client.sendMessage(msgFrom, 'āŒ Please provide a valid phone number.\nUsage: !rejectjoin 923001234567');
1202
1556
  break;
1203
1557
  }
1204
1558
  const rejectResult = await client.handleGroupJoinRequest(msg.raw.key.remoteJid, [rejectNum + '@s.whatsapp.net'], 'reject');
1205
- await client.sendMessage(msg.from, `āœ… Join request rejected for ${rejectNum}`);
1559
+ await client.sendMessage(msgFrom, `āœ… Join request rejected for ${rejectNum}`);
1206
1560
  } catch (error) {
1207
1561
  console.error('Error rejecting join request:', error);
1208
- await client.sendMessage(msg.from, `āŒ Failed to reject: ${error.message}`);
1562
+ await client.sendMessage(msgFrom, `āŒ Failed to reject: ${error.message}`);
1209
1563
  }
1210
1564
  break;
1211
1565
 
1212
1566
  case '!ephemeral':
1213
1567
  try {
1214
1568
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1215
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1569
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1216
1570
  break;
1217
1571
  }
1218
1572
  const ephemeralSeconds = parseInt(args);
1219
1573
  if (isNaN(ephemeralSeconds)) {
1220
- await client.sendMessage(msg.from,
1574
+ await client.sendMessage(msgFrom,
1221
1575
  `āŒ Please provide duration in seconds.\n\n` +
1222
1576
  `Usage: !ephemeral <seconds>\n\n` +
1223
1577
  `Options:\n` +
@@ -1230,21 +1584,21 @@ async function start() {
1230
1584
  }
1231
1585
  await client.toggleGroupEphemeral(msg.raw.key.remoteJid, ephemeralSeconds);
1232
1586
  const durationText = ephemeralSeconds === 0 ? 'OFF' : `${ephemeralSeconds} seconds`;
1233
- await client.sendMessage(msg.from, `āœ… Disappearing messages set to: *${durationText}*`);
1587
+ await client.sendMessage(msgFrom, `āœ… Disappearing messages set to: *${durationText}*`);
1234
1588
  } catch (error) {
1235
1589
  console.error('Error toggling ephemeral:', error);
1236
- await client.sendMessage(msg.from, `āŒ Failed to toggle disappearing messages: ${error.message}`);
1590
+ await client.sendMessage(msgFrom, `āŒ Failed to toggle disappearing messages: ${error.message}`);
1237
1591
  }
1238
1592
  break;
1239
1593
 
1240
1594
  case '!addmode':
1241
1595
  try {
1242
1596
  if (!msg.raw.key.remoteJid.endsWith('@g.us')) {
1243
- await client.sendMessage(msg.from, 'āŒ This command can only be used in groups');
1597
+ await client.sendMessage(msgFrom, 'āŒ This command can only be used in groups');
1244
1598
  break;
1245
1599
  }
1246
1600
  if (!args || !['all_member_add', 'admin_add'].includes(args.trim())) {
1247
- await client.sendMessage(msg.from,
1601
+ await client.sendMessage(msgFrom,
1248
1602
  `āŒ Invalid mode.\n\n` +
1249
1603
  `Usage: !addmode <mode>\n\n` +
1250
1604
  `Options:\n` +
@@ -1254,10 +1608,10 @@ async function start() {
1254
1608
  break;
1255
1609
  }
1256
1610
  await client.changeGroupAddMode(msg.raw.key.remoteJid, args.trim());
1257
- await client.sendMessage(msg.from, `āœ… Group add mode changed to: *${args.trim()}*`);
1611
+ await client.sendMessage(msgFrom, `āœ… Group add mode changed to: *${args.trim()}*`);
1258
1612
  } catch (error) {
1259
1613
  console.error('Error changing add mode:', error);
1260
- await client.sendMessage(msg.from, `āŒ Failed to change add mode: ${error.message}`);
1614
+ await client.sendMessage(msgFrom, `āŒ Failed to change add mode: ${error.message}`);
1261
1615
  }
1262
1616
  break;
1263
1617
 
@@ -1269,14 +1623,14 @@ async function start() {
1269
1623
  try {
1270
1624
  const blockNum = args?.replace(/[^0-9]/g, '');
1271
1625
  if (!blockNum || blockNum.length < 10) {
1272
- await client.sendMessage(msg.from, 'āŒ Please provide a valid phone number.\nUsage: !block 923001234567');
1626
+ await client.sendMessage(msgFrom, 'āŒ Please provide a valid phone number.\nUsage: !block 923001234567');
1273
1627
  break;
1274
1628
  }
1275
1629
  await client.blockUser(blockNum + '@s.whatsapp.net');
1276
- await client.sendMessage(msg.from, `āœ… User ${blockNum} has been blocked.`);
1630
+ await client.sendMessage(msgFrom, `āœ… User ${blockNum} has been blocked.`);
1277
1631
  } catch (error) {
1278
1632
  console.error('Error blocking user:', error);
1279
- await client.sendMessage(msg.from, `āŒ Failed to block user: ${error.message}`);
1633
+ await client.sendMessage(msgFrom, `āŒ Failed to block user: ${error.message}`);
1280
1634
  }
1281
1635
  break;
1282
1636
 
@@ -1284,14 +1638,14 @@ async function start() {
1284
1638
  try {
1285
1639
  const unblockNum = args?.replace(/[^0-9]/g, '');
1286
1640
  if (!unblockNum || unblockNum.length < 10) {
1287
- await client.sendMessage(msg.from, 'āŒ Please provide a valid phone number.\nUsage: !unblock 923001234567');
1641
+ await client.sendMessage(msgFrom, 'āŒ Please provide a valid phone number.\nUsage: !unblock 923001234567');
1288
1642
  break;
1289
1643
  }
1290
1644
  await client.unblockUser(unblockNum + '@s.whatsapp.net');
1291
- await client.sendMessage(msg.from, `āœ… User ${unblockNum} has been unblocked.`);
1645
+ await client.sendMessage(msgFrom, `āœ… User ${unblockNum} has been unblocked.`);
1292
1646
  } catch (error) {
1293
1647
  console.error('Error unblocking user:', error);
1294
- await client.sendMessage(msg.from, `āŒ Failed to unblock user: ${error.message}`);
1648
+ await client.sendMessage(msgFrom, `āŒ Failed to unblock user: ${error.message}`);
1295
1649
  }
1296
1650
  break;
1297
1651
 
@@ -1302,10 +1656,10 @@ async function start() {
1302
1656
  for (const [key, value] of Object.entries(privacySettings)) {
1303
1657
  privacyText += `• ${key}: *${value}*\n`;
1304
1658
  }
1305
- await client.sendMessage(msg.from, privacyText);
1659
+ await client.sendMessage(msgFrom, privacyText);
1306
1660
  } catch (error) {
1307
1661
  console.error('Error fetching privacy settings:', error);
1308
- await client.sendMessage(msg.from, `āŒ Failed to get privacy settings: ${error.message}`);
1662
+ await client.sendMessage(msgFrom, `āŒ Failed to get privacy settings: ${error.message}`);
1309
1663
  }
1310
1664
  break;
1311
1665
 
@@ -1317,13 +1671,13 @@ async function start() {
1317
1671
  blockedList.forEach((jid, i) => {
1318
1672
  blockText += `${i + 1}. ${jid}\n`;
1319
1673
  });
1320
- await client.sendMessage(msg.from, blockText);
1674
+ await client.sendMessage(msgFrom, blockText);
1321
1675
  } else {
1322
- await client.sendMessage(msg.from, 'āœ… No blocked contacts.');
1676
+ await client.sendMessage(msgFrom, 'āœ… No blocked contacts.');
1323
1677
  }
1324
1678
  } catch (error) {
1325
1679
  console.error('Error fetching block list:', error);
1326
- await client.sendMessage(msg.from, `āŒ Failed to get block list: ${error.message}`);
1680
+ await client.sendMessage(msgFrom, `āŒ Failed to get block list: ${error.message}`);
1327
1681
  }
1328
1682
  break;
1329
1683
 
@@ -1331,16 +1685,16 @@ async function start() {
1331
1685
  try {
1332
1686
  const lsValues = ['all', 'contacts', 'contact_blacklist', 'none'];
1333
1687
  if (!args || !lsValues.includes(args.trim())) {
1334
- await client.sendMessage(msg.from,
1688
+ await client.sendMessage(msgFrom,
1335
1689
  `āŒ Invalid value.\n\nUsage: !lastseenprivacy <value>\n\nOptions: ${lsValues.join(', ')}`
1336
1690
  );
1337
1691
  break;
1338
1692
  }
1339
1693
  await client.updateLastSeenPrivacy(args.trim());
1340
- await client.sendMessage(msg.from, `āœ… Last seen privacy updated to: *${args.trim()}*`);
1694
+ await client.sendMessage(msgFrom, `āœ… Last seen privacy updated to: *${args.trim()}*`);
1341
1695
  } catch (error) {
1342
1696
  console.error('Error updating last seen privacy:', error);
1343
- await client.sendMessage(msg.from, `āŒ Failed to update: ${error.message}`);
1697
+ await client.sendMessage(msgFrom, `āŒ Failed to update: ${error.message}`);
1344
1698
  }
1345
1699
  break;
1346
1700
 
@@ -1348,16 +1702,16 @@ async function start() {
1348
1702
  try {
1349
1703
  const onValues = ['all', 'match_last_seen'];
1350
1704
  if (!args || !onValues.includes(args.trim())) {
1351
- await client.sendMessage(msg.from,
1705
+ await client.sendMessage(msgFrom,
1352
1706
  `āŒ Invalid value.\n\nUsage: !onlineprivacy <value>\n\nOptions: ${onValues.join(', ')}`
1353
1707
  );
1354
1708
  break;
1355
1709
  }
1356
1710
  await client.updateOnlinePrivacy(args.trim());
1357
- await client.sendMessage(msg.from, `āœ… Online privacy updated to: *${args.trim()}*`);
1711
+ await client.sendMessage(msgFrom, `āœ… Online privacy updated to: *${args.trim()}*`);
1358
1712
  } catch (error) {
1359
1713
  console.error('Error updating online privacy:', error);
1360
- await client.sendMessage(msg.from, `āŒ Failed to update: ${error.message}`);
1714
+ await client.sendMessage(msgFrom, `āŒ Failed to update: ${error.message}`);
1361
1715
  }
1362
1716
  break;
1363
1717
 
@@ -1365,16 +1719,16 @@ async function start() {
1365
1719
  try {
1366
1720
  const pfpValues = ['all', 'contacts', 'contact_blacklist', 'none'];
1367
1721
  if (!args || !pfpValues.includes(args.trim())) {
1368
- await client.sendMessage(msg.from,
1722
+ await client.sendMessage(msgFrom,
1369
1723
  `āŒ Invalid value.\n\nUsage: !pfpprivacy <value>\n\nOptions: ${pfpValues.join(', ')}`
1370
1724
  );
1371
1725
  break;
1372
1726
  }
1373
1727
  await client.updateProfilePicturePrivacy(args.trim());
1374
- await client.sendMessage(msg.from, `āœ… Profile picture privacy updated to: *${args.trim()}*`);
1728
+ await client.sendMessage(msgFrom, `āœ… Profile picture privacy updated to: *${args.trim()}*`);
1375
1729
  } catch (error) {
1376
1730
  console.error('Error updating profile picture privacy:', error);
1377
- await client.sendMessage(msg.from, `āŒ Failed to update: ${error.message}`);
1731
+ await client.sendMessage(msgFrom, `āŒ Failed to update: ${error.message}`);
1378
1732
  }
1379
1733
  break;
1380
1734
 
@@ -1382,16 +1736,16 @@ async function start() {
1382
1736
  try {
1383
1737
  const stValues = ['all', 'contacts', 'contact_blacklist', 'none'];
1384
1738
  if (!args || !stValues.includes(args.trim())) {
1385
- await client.sendMessage(msg.from,
1739
+ await client.sendMessage(msgFrom,
1386
1740
  `āŒ Invalid value.\n\nUsage: !statusprivacy <value>\n\nOptions: ${stValues.join(', ')}`
1387
1741
  );
1388
1742
  break;
1389
1743
  }
1390
1744
  await client.updateStatusPrivacy(args.trim());
1391
- await client.sendMessage(msg.from, `āœ… Status privacy updated to: *${args.trim()}*`);
1745
+ await client.sendMessage(msgFrom, `āœ… Status privacy updated to: *${args.trim()}*`);
1392
1746
  } catch (error) {
1393
1747
  console.error('Error updating status privacy:', error);
1394
- await client.sendMessage(msg.from, `āŒ Failed to update: ${error.message}`);
1748
+ await client.sendMessage(msgFrom, `āŒ Failed to update: ${error.message}`);
1395
1749
  }
1396
1750
  break;
1397
1751
 
@@ -1399,16 +1753,16 @@ async function start() {
1399
1753
  try {
1400
1754
  const rrValues = ['all', 'none'];
1401
1755
  if (!args || !rrValues.includes(args.trim())) {
1402
- await client.sendMessage(msg.from,
1756
+ await client.sendMessage(msgFrom,
1403
1757
  `āŒ Invalid value.\n\nUsage: !readreceiptprivacy <value>\n\nOptions: ${rrValues.join(', ')}`
1404
1758
  );
1405
1759
  break;
1406
1760
  }
1407
1761
  await client.updateReadReceiptsPrivacy(args.trim());
1408
- await client.sendMessage(msg.from, `āœ… Read receipts privacy updated to: *${args.trim()}*`);
1762
+ await client.sendMessage(msgFrom, `āœ… Read receipts privacy updated to: *${args.trim()}*`);
1409
1763
  } catch (error) {
1410
1764
  console.error('Error updating read receipts privacy:', error);
1411
- await client.sendMessage(msg.from, `āŒ Failed to update: ${error.message}`);
1765
+ await client.sendMessage(msgFrom, `āŒ Failed to update: ${error.message}`);
1412
1766
  }
1413
1767
  break;
1414
1768
 
@@ -1416,16 +1770,16 @@ async function start() {
1416
1770
  try {
1417
1771
  const gaValues = ['all', 'contacts', 'contact_blacklist'];
1418
1772
  if (!args || !gaValues.includes(args.trim())) {
1419
- await client.sendMessage(msg.from,
1773
+ await client.sendMessage(msgFrom,
1420
1774
  `āŒ Invalid value.\n\nUsage: !groupaddprivacy <value>\n\nOptions: ${gaValues.join(', ')}`
1421
1775
  );
1422
1776
  break;
1423
1777
  }
1424
1778
  await client.updateGroupsAddPrivacy(args.trim());
1425
- await client.sendMessage(msg.from, `āœ… Groups add privacy updated to: *${args.trim()}*`);
1779
+ await client.sendMessage(msgFrom, `āœ… Groups add privacy updated to: *${args.trim()}*`);
1426
1780
  } catch (error) {
1427
1781
  console.error('Error updating groups add privacy:', error);
1428
- await client.sendMessage(msg.from, `āŒ Failed to update: ${error.message}`);
1782
+ await client.sendMessage(msgFrom, `āŒ Failed to update: ${error.message}`);
1429
1783
  }
1430
1784
  break;
1431
1785
 
@@ -1433,7 +1787,7 @@ async function start() {
1433
1787
  try {
1434
1788
  const disappearingSeconds = parseInt(args);
1435
1789
  if (isNaN(disappearingSeconds)) {
1436
- await client.sendMessage(msg.from,
1790
+ await client.sendMessage(msgFrom,
1437
1791
  `āŒ Please provide duration in seconds.\n\n` +
1438
1792
  `Usage: !disappearing <seconds>\n\n` +
1439
1793
  `Options:\n` +
@@ -1446,102 +1800,193 @@ async function start() {
1446
1800
  }
1447
1801
  await client.updateDefaultDisappearingMode(disappearingSeconds);
1448
1802
  const disappearText = disappearingSeconds === 0 ? 'OFF' : `${disappearingSeconds} seconds`;
1449
- await client.sendMessage(msg.from, `āœ… Default disappearing mode set to: *${disappearText}*`);
1803
+ await client.sendMessage(msgFrom, `āœ… Default disappearing mode set to: *${disappearText}*`);
1450
1804
  } catch (error) {
1451
1805
  console.error('Error updating default disappearing mode:', error);
1452
- await client.sendMessage(msg.from, `āŒ Failed to update: ${error.message}`);
1806
+ await client.sendMessage(msgFrom, `āŒ Failed to update: ${error.message}`);
1453
1807
  }
1454
1808
  break;
1455
1809
 
1456
1810
  case '!updatestatus':
1457
1811
  try {
1458
1812
  if (!args) {
1459
- await client.sendMessage(msg.from, 'āŒ Please provide a new status.\nUsage: !updatestatus <text>');
1813
+ await client.sendMessage(msgFrom, 'āŒ Please provide a new status.\nUsage: !updatestatus <text>');
1460
1814
  break;
1461
1815
  }
1462
1816
  await client.updateProfileStatus(args.trim());
1463
- await client.sendMessage(msg.from, `āœ… Profile status updated successfully!`);
1817
+ await client.sendMessage(msgFrom, `āœ… Profile status updated successfully!`);
1464
1818
  } catch (error) {
1465
1819
  console.error('Error updating profile status:', error);
1466
- await client.sendMessage(msg.from, `āŒ Failed to update profile status: ${error.message}`);
1820
+ await client.sendMessage(msgFrom, `āŒ Failed to update profile status: ${error.message}`);
1467
1821
  }
1468
1822
  break;
1469
1823
 
1470
1824
  case '!updatename':
1471
1825
  try {
1472
1826
  if (!args) {
1473
- await client.sendMessage(msg.from, 'āŒ Please provide a new name.\nUsage: !updatename <text>');
1827
+ await client.sendMessage(msgFrom, 'āŒ Please provide a new name.\nUsage: !updatename <text>');
1474
1828
  break;
1475
1829
  }
1476
1830
  const newName = args.trim().toTitleCase();
1477
1831
  await client.updateProfileName(newName);
1478
- await client.sendMessage(msg.from, `āœ… *${newName}* \nProfile name updated successfully!`);
1832
+ await client.sendMessage(msgFrom, `āœ… *${newName}* \nProfile name updated successfully!`);
1479
1833
  } catch (error) {
1480
1834
  console.error('Error updating profile name:', error);
1481
- await client.sendMessage(msg.from, `āŒ Failed to update profile name: ${error.message}`);
1835
+ await client.sendMessage(msgFrom, `āŒ Failed to update profile name: ${error.message}`);
1836
+ }
1837
+ break;
1838
+
1839
+ case '!statustext':
1840
+ try {
1841
+ await client.sendStatus({
1842
+ text: 'This is a test status!',
1843
+ backgroundColor: STATUS_BACKGROUNDS.solid.orange,
1844
+ font: STATUS_FONTS.SANS_SERIF
1845
+ }, [msgFrom]);
1846
+ await client.sendMessage(msgFrom, 'āœ… Status posted successfully!');
1847
+ } catch (error) {
1848
+ console.error('Error sending text status:', error);
1849
+ await client.sendMessage(msgFrom, `āŒ Failed to post text status: ${error.message}`);
1850
+ }
1851
+ break;
1852
+
1853
+ case '!statusimage':
1854
+ try {
1855
+ if (fs.existsSync('./example.jpg')) {
1856
+ await client.sendStatus({
1857
+ imagePath: './example.jpg',
1858
+ caption: args || 'Beautiful day from Innovators Soft! ā˜€ļø'
1859
+ }, [msgFrom]);
1860
+ await client.sendMessage(msgFrom, 'āœ… Image status posted successfully!');
1861
+ } else {
1862
+ await client.sendMessage(msgFrom, 'āŒ example.jpg not found for status demonstration.');
1863
+ }
1864
+ } catch (error) {
1865
+ console.error('Error sending image status:', error);
1866
+ await client.sendMessage(msgFrom, `āŒ Failed to post image status: ${error.message}`);
1867
+ }
1868
+ break;
1869
+
1870
+ case '!statusvideo':
1871
+ try {
1872
+ if (fs.existsSync('./example.mp4')) {
1873
+ await client.sendStatus({
1874
+ videoPath: './example.mp4',
1875
+ caption: args || 'Check this out! šŸŽ¬',
1876
+ isGif: false
1877
+ }, [msgFrom]);
1878
+ await client.sendMessage(msgFrom, 'āœ… Video status posted successfully!');
1879
+ } else {
1880
+ await client.sendMessage(msgFrom, 'āŒ example.mp4 not found for status demonstration.');
1881
+ }
1882
+ } catch (error) {
1883
+ console.error('Error sending video status:', error);
1884
+ await client.sendMessage(msgFrom, `āŒ Failed to post video status: ${error.message}`);
1885
+ }
1886
+ break;
1887
+
1888
+ case '!statusvoice':
1889
+ try {
1890
+ if (fs.existsSync('./example.ogg')) {
1891
+ await client.sendStatus({
1892
+ audioPath: './example.ogg'
1893
+ }, [msgFrom]);
1894
+ await client.sendMessage(msgFrom, 'āœ… Voice note status posted successfully!');
1895
+ } else {
1896
+ await client.sendMessage(msgFrom, 'āŒ example.ogg not found for status demonstration. Try finding a small audio file.');
1897
+ }
1898
+ } catch (error) {
1899
+ console.error('Error sending voice note status:', error);
1900
+ await client.sendMessage(msgFrom, `āŒ Failed to post voice note status: ${error.message}`);
1901
+ }
1902
+ break;
1903
+
1904
+ case '!groupstatus':
1905
+ try {
1906
+ if (!msgFrom.endsWith('@g.us')) {
1907
+ await client.sendMessage(msgFrom, 'āŒ This command only works inside a group chat (@g.us).');
1908
+ break;
1909
+ }
1910
+
1911
+ await client.sendGroupStatus(msgFrom, {
1912
+ text: 'this is group status'
1913
+ });
1914
+
1915
+ if (fs.existsSync('./example.jpg')) {
1916
+ await client.sendGroupStatus(msgFrom, {
1917
+ image: { url: './example.jpg' },
1918
+ caption: args || 'Hello Group!'
1919
+ });
1920
+ await client.sendMessage(msgFrom, 'āœ… Group status posted successfully!');
1921
+ } else {
1922
+ await client.sendMessage(msgFrom, 'āŒ example.jpg not found for group status demonstration.');
1923
+ }
1924
+ } catch (error) {
1925
+ console.error('Error sending group status:', error);
1926
+ await client.sendMessage(msgFrom, `āŒ Failed to post group status: ${error.message}`);
1482
1927
  }
1483
1928
  break;
1484
1929
 
1485
1930
  case '!messages':
1486
- const history = client.getStoredMessages(msg.from);
1931
+ const history = client.getStoredMessages(msgFrom);
1487
1932
  let historyText = `*šŸ’¾ Stored Messages for this chat (${history.length}):*\n\n`;
1488
1933
  history.slice(-10).forEach((m, i) => {
1489
1934
  const content = m.message.conversation || m.message.extendedTextMessage?.text || "[Media/Other]";
1490
1935
  historyText += `${i + 1}. ID: ${m.key.id}\n Text: ${content.substring(0, 50)}${content.length > 50 ? '...' : ''}\n\n`;
1491
1936
  });
1492
- await client.sendMessage(msg.from, historyText);
1937
+ await client.sendMessage(msgFrom, historyText);
1493
1938
  break;
1494
1939
 
1495
1940
  case '!message':
1496
1941
  if (!args) {
1497
- await client.sendMessage(msg.from, "āŒ Please provide a message ID.");
1942
+ await client.sendMessage(msgFrom, "āŒ Please provide a message ID.");
1498
1943
  break;
1499
1944
  }
1500
- const storedMsg = client.getStoredMessage({ remoteJid: msg.from, id: args.trim(), fromMe: false });
1945
+ const storedMsg = client.getStoredMessage({ remoteJid: msgFrom, id: args.trim(), fromMe: false });
1501
1946
  if (storedMsg) {
1502
- await client.sendMessage(msg.from, `āœ… Found message!\n\nContent: ${JSON.stringify(storedMsg.message, null, 2).substring(0, 1000)}`);
1947
+ await client.sendMessage(msgFrom, `āœ… Found message!\n\nContent: ${JSON.stringify(storedMsg.message, null, 2).substring(0, 1000)}`);
1503
1948
  } else {
1504
- await client.sendMessage(msg.from, "āŒ Message not found in store.");
1949
+ await client.sendMessage(msgFrom, "āŒ Message not found in store.");
1505
1950
  }
1506
1951
  break;
1507
1952
 
1508
1953
  case '!stats':
1509
1954
  const stats = client.getStoreStats();
1510
- await client.sendMessage(msg.from, `*šŸ“Š Message Store Statistics*\n\n• Total Chats: ${stats.totalChats}\n• Total Messages: ${stats.totalMessages}\n• Total Deleted: ${stats.totalDeleted}`);
1955
+ await client.sendMessage(msgFrom, `*šŸ“Š Message Store Statistics*\n\n• Total Chats: ${stats.totalChats}\n• Total Messages: ${stats.totalMessages}\n• Total Deleted: ${stats.totalDeleted}`);
1511
1956
  break;
1512
1957
 
1513
1958
  case '!allmessages':
1514
1959
  const allMsgs = client.getAllStoredMessages();
1515
1960
  const activeChats = client.getStoredChatIds();
1516
- await client.sendMessage(msg.from, `*🌐 Global Message Store*\n\n• Total Messages Held: ${allMsgs.length}\n• Total Active Chats: ${activeChats.length}\n\n*Active JIDs:* \n${activeChats.join('\n')}`);
1961
+ await client.sendMessage(msgFrom, `*🌐 Global Message Store*\n\n• Total Messages Held: ${allMsgs.length}\n• Total Active Chats: ${activeChats.length}\n\n*Active JIDs:* \n${activeChats.join('\n')}`);
1517
1962
  break;
1518
1963
 
1519
1964
  case '!savestore':
1520
- await client.sendMessage(msg.from, 'šŸ’¾ Saving message store to file...');
1965
+ await client.sendMessage(msgFrom, 'šŸ’¾ Saving message store to file...');
1521
1966
  const saveResult = await client.saveMessageStore();
1522
1967
  if (saveResult.success) {
1523
- await client.sendMessage(msg.from,
1968
+ await client.sendMessage(msgFrom,
1524
1969
  `āœ… *Store Saved Successfully*\n\n` +
1525
1970
  `• Messages: ${saveResult.messageCount}\n` +
1526
1971
  `• Path: ${saveResult.path}\n` +
1527
1972
  `• Saved at: ${saveResult.savedAt.toLocaleString()}`
1528
1973
  );
1529
1974
  } else {
1530
- await client.sendMessage(msg.from, `āŒ Failed to save store: ${saveResult.error}`);
1975
+ await client.sendMessage(msgFrom, `āŒ Failed to save store: ${saveResult.error}`);
1531
1976
  }
1532
1977
  break;
1533
1978
 
1534
1979
  case '!loadstore':
1535
- await client.sendMessage(msg.from, 'šŸ“‚ Loading message store from file...');
1980
+ await client.sendMessage(msgFrom, 'šŸ“‚ Loading message store from file...');
1536
1981
  const loadResult = await client.loadMessageStore();
1537
1982
  if (loadResult.success) {
1538
- await client.sendMessage(msg.from,
1983
+ await client.sendMessage(msgFrom,
1539
1984
  `āœ… *Store Loaded Successfully*\n\n` +
1540
1985
  `• Messages: ${loadResult.messageCount}\n` +
1541
1986
  `• Loaded from: ${loadResult.loadedFrom}`
1542
1987
  );
1543
1988
  } else {
1544
- await client.sendMessage(msg.from,
1989
+ await client.sendMessage(msgFrom,
1545
1990
  `āš ļø Could not load store\n` +
1546
1991
  `Reason: ${loadResult.reason || loadResult.error}`
1547
1992
  );