sanka-baileyss 1.6.3 → 1.6.5
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/README.md +177 -191
- package/lib/Utils/generics.js +2 -2
- package/lib/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,31 +50,17 @@ To run the example script, download or clone the repo and then type the followin
|
|
|
50
50
|
|
|
51
51
|
Use the stable version:
|
|
52
52
|
```
|
|
53
|
-
yarn add Sanka-
|
|
54
|
-
```
|
|
55
|
-
```
|
|
56
|
-
npm install sanka-baileyss
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Use package.json
|
|
60
|
-
```
|
|
61
|
-
"@whiskeysockets/baileys": "npm:sanka-baileyss@latest"
|
|
62
|
-
```
|
|
63
|
-
```
|
|
64
|
-
"@adiwajshing/baileys": "npm:sanka-baileyss@latest"
|
|
53
|
+
yarn add @SankaVollereii/Sanka-Bail
|
|
65
54
|
```
|
|
66
55
|
|
|
67
56
|
Use the edge version (no guarantee of stability, but latest fixes + features)
|
|
68
57
|
```
|
|
69
|
-
yarn add github:SankaVollereii/Sanka-
|
|
70
|
-
```
|
|
71
|
-
```
|
|
72
|
-
yarn add npm:sanka-baileyss@latest
|
|
58
|
+
yarn add github:SankaVollereii/Sanka-Bail
|
|
73
59
|
```
|
|
74
60
|
|
|
75
61
|
Then import your code using:
|
|
76
62
|
```ts
|
|
77
|
-
import makeWASocket from 'Sanka-
|
|
63
|
+
import makeWASocket from '@SankaVollereii/Sanka-Bail'
|
|
78
64
|
```
|
|
79
65
|
|
|
80
66
|
# Links
|
|
@@ -231,9 +217,9 @@ WhatsApp provides a multi-device API that allows Baileys to be authenticated as
|
|
|
231
217
|
> You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://baileys.whiskeysockets.io/types/BrowsersMap.html)**
|
|
232
218
|
|
|
233
219
|
```ts
|
|
234
|
-
import makeWASocket from 'Sanka-
|
|
220
|
+
import makeWASocket from '@SankaVollereii/Sanka-Bail'
|
|
235
221
|
|
|
236
|
-
const
|
|
222
|
+
const suki = makeWASocket({
|
|
237
223
|
// can provide additional config here
|
|
238
224
|
browser: Browsers.ubuntu('My App'),
|
|
239
225
|
printQRInTerminal: true
|
|
@@ -251,16 +237,16 @@ If the connection is successful, you will see a QR code printed on your terminal
|
|
|
251
237
|
The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
|
|
252
238
|
|
|
253
239
|
```ts
|
|
254
|
-
import makeWASocket from 'Sanka-
|
|
240
|
+
import makeWASocket from '@SankaVollereii/Sanka-Bail'
|
|
255
241
|
|
|
256
|
-
const
|
|
242
|
+
const suki = makeWASocket({
|
|
257
243
|
// can provide additional config here
|
|
258
244
|
printQRInTerminal: false //need to be false
|
|
259
245
|
})
|
|
260
246
|
|
|
261
|
-
if (!
|
|
247
|
+
if (!suki.authState.creds.registered) {
|
|
262
248
|
const number = 'XXXXXXXXXXX'
|
|
263
|
-
const code = await
|
|
249
|
+
const code = await suki.requestPairingCode(number) // or await suki.requestPairingCode(number, 'CODEOTPS') custom your pairing code
|
|
264
250
|
console.log(code)
|
|
265
251
|
}
|
|
266
252
|
```
|
|
@@ -272,7 +258,7 @@ if (!sanka.authState.creds.registered) {
|
|
|
272
258
|
- If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
|
|
273
259
|
|
|
274
260
|
```ts
|
|
275
|
-
const
|
|
261
|
+
const suki = makeWASocket({
|
|
276
262
|
...otherOpts,
|
|
277
263
|
// can use Windows, Ubuntu here too
|
|
278
264
|
browser: Browsers.macOS('Desktop'),
|
|
@@ -288,17 +274,17 @@ const sanka = makeWASocket({
|
|
|
288
274
|
```ts
|
|
289
275
|
const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
|
|
290
276
|
|
|
291
|
-
const
|
|
277
|
+
const suki = makeWASocket({
|
|
292
278
|
cachedGroupMetadata: async (jid) => groupCache.get(jid)
|
|
293
279
|
})
|
|
294
280
|
|
|
295
|
-
|
|
296
|
-
const metadata = await
|
|
281
|
+
suki.ev.on('groups.update', async ([event]) => {
|
|
282
|
+
const metadata = await suki.groupMetadata(event.id)
|
|
297
283
|
groupCache.set(event.id, metadata)
|
|
298
284
|
})
|
|
299
285
|
|
|
300
|
-
|
|
301
|
-
const metadata = await
|
|
286
|
+
suki.ev.on('group-participants.update', async (event) => {
|
|
287
|
+
const metadata = await suki.groupMetadata(event.id)
|
|
302
288
|
groupCache.set(event.id, metadata)
|
|
303
289
|
})
|
|
304
290
|
```
|
|
@@ -306,7 +292,7 @@ const sanka = makeWASocket({
|
|
|
306
292
|
### Improve Retry System & Decrypt Poll Votes
|
|
307
293
|
- If you want to improve sending message, retrying when error occurs and decrypt poll votes, you need to have a store and set `getMessage` config in socket like this:
|
|
308
294
|
```ts
|
|
309
|
-
const
|
|
295
|
+
const suki = makeWASocket({
|
|
310
296
|
getMessage: async (key) => await getMessageFromStore(key)
|
|
311
297
|
})
|
|
312
298
|
```
|
|
@@ -314,7 +300,7 @@ const sanka = makeWASocket({
|
|
|
314
300
|
### Receive Notifications in Whatsapp App
|
|
315
301
|
- If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
|
|
316
302
|
```ts
|
|
317
|
-
const
|
|
303
|
+
const suki = makeWASocket({
|
|
318
304
|
markOnlineOnConnect: false
|
|
319
305
|
})
|
|
320
306
|
```
|
|
@@ -324,16 +310,16 @@ You obviously don't want to keep scanning the QR code every time you want to con
|
|
|
324
310
|
|
|
325
311
|
So, you can load the credentials to log back in:
|
|
326
312
|
```ts
|
|
327
|
-
import makeWASocket, { useMultiFileAuthState } from 'Sanka-
|
|
313
|
+
import makeWASocket, { useMultiFileAuthState } from '@SankaVollereii/Sanka-Bail'
|
|
328
314
|
|
|
329
315
|
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
|
|
330
316
|
|
|
331
317
|
// will use the given state to connect
|
|
332
318
|
// so if valid credentials are available -- it'll connect without QR
|
|
333
|
-
const
|
|
319
|
+
const suki = makeWASocket({ auth: state })
|
|
334
320
|
|
|
335
321
|
// this will be called as soon as the credentials are updated
|
|
336
|
-
|
|
322
|
+
suki.ev.on('creds.update', saveCreds)
|
|
337
323
|
```
|
|
338
324
|
|
|
339
325
|
> [!IMPORTANT]
|
|
@@ -352,8 +338,8 @@ They're all nicely typed up, so you shouldn't have any issues with an Intellisen
|
|
|
352
338
|
|
|
353
339
|
You can listen to these events like this:
|
|
354
340
|
```ts
|
|
355
|
-
const
|
|
356
|
-
|
|
341
|
+
const suki = makeWASocket()
|
|
342
|
+
suki.ev.on('messages.upsert', ({ messages }) => {
|
|
357
343
|
console.log('got messages', messages)
|
|
358
344
|
})
|
|
359
345
|
```
|
|
@@ -364,17 +350,17 @@ sanka.ev.on('messages.upsert', ({ messages }) => {
|
|
|
364
350
|
> This example includes basic auth storage too
|
|
365
351
|
|
|
366
352
|
```ts
|
|
367
|
-
import makeWASocket, { DisconnectReason, useMultiFileAuthState } from 'Sanka-
|
|
353
|
+
import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@SankaVollereii/Sanka-Bail'
|
|
368
354
|
import { Boom } from '@hapi/boom'
|
|
369
355
|
|
|
370
356
|
async function connectToWhatsApp () {
|
|
371
357
|
const { state, saveCreds } = await useMultiFileAuthState('./auth_info_baileys')
|
|
372
|
-
const
|
|
358
|
+
const suki = makeWASocket({
|
|
373
359
|
// can provide additional config here
|
|
374
360
|
auth: state,
|
|
375
361
|
printQRInTerminal: true
|
|
376
362
|
})
|
|
377
|
-
|
|
363
|
+
suki.ev.on('connection.update', (update) => {
|
|
378
364
|
const { connection, lastDisconnect } = update
|
|
379
365
|
if(connection === 'close') {
|
|
380
366
|
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
|
|
@@ -387,17 +373,17 @@ async function connectToWhatsApp () {
|
|
|
387
373
|
console.log('opened connection')
|
|
388
374
|
}
|
|
389
375
|
})
|
|
390
|
-
|
|
376
|
+
suki.ev.on('messages.upsert', event => {
|
|
391
377
|
for (const m of event.messages) {
|
|
392
378
|
console.log(JSON.stringify(m, undefined, 2))
|
|
393
379
|
|
|
394
380
|
console.log('replying to', m.key.remoteJid)
|
|
395
|
-
await
|
|
381
|
+
await suki.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
|
|
396
382
|
}
|
|
397
383
|
})
|
|
398
384
|
|
|
399
385
|
// to storage creds (session info) when it updates
|
|
400
|
-
|
|
386
|
+
suki.ev.on('creds.update', saveCreds)
|
|
401
387
|
}
|
|
402
388
|
// run in main file
|
|
403
389
|
connectToWhatsApp()
|
|
@@ -405,16 +391,16 @@ connectToWhatsApp()
|
|
|
405
391
|
|
|
406
392
|
### For example if you use useSingleFileAuthState and useMongoFileAuthState
|
|
407
393
|
```ts
|
|
408
|
-
import makeWASocket, { useSingleFileAuthState, useMongoFileAuthState } from 'Sanka-
|
|
394
|
+
import makeWASocket, { useSingleFileAuthState, useMongoFileAuthState } from '@SankaVollereii/Sanka-Bail'
|
|
409
395
|
|
|
410
396
|
// Single Auth
|
|
411
397
|
const { state, saveState } = await useSingleFileAuthState('./auth_info_baileys.json')
|
|
412
|
-
const
|
|
398
|
+
const suki = makeWASocket({
|
|
413
399
|
auth: state,
|
|
414
400
|
printQRInTerminal: true
|
|
415
401
|
})
|
|
416
402
|
|
|
417
|
-
|
|
403
|
+
suki.ev.on('creds.update', saveState)
|
|
418
404
|
|
|
419
405
|
// Mongo Auth
|
|
420
406
|
import { MongoClient } from "mongodb"
|
|
@@ -436,12 +422,12 @@ const connectAuth = async() => {
|
|
|
436
422
|
|
|
437
423
|
const Authentication = await connectAuth()
|
|
438
424
|
const { state, saveCreds } = await useMongoFileAuthState(Authentication)
|
|
439
|
-
const
|
|
425
|
+
const suki = makeWASocket({
|
|
440
426
|
auth: state,
|
|
441
427
|
printQRInTerminal: true
|
|
442
428
|
})
|
|
443
429
|
|
|
444
|
-
|
|
430
|
+
suki.ev.on('creds.update', saveCreds)
|
|
445
431
|
```
|
|
446
432
|
|
|
447
433
|
> [!IMPORTANT]
|
|
@@ -452,9 +438,9 @@ sanka.ev.on('creds.update', saveCreds)
|
|
|
452
438
|
- By default poll votes are encrypted and handled in `messages.update`
|
|
453
439
|
```ts
|
|
454
440
|
import pino from "pino"
|
|
455
|
-
import { makeInMemoryStore, getAggregateVotesInPollMessage } from 'Sanka-
|
|
441
|
+
import { makeInMemoryStore, getAggregateVotesInPollMessage } from '@SankaVollereii/Sanka-Bail'
|
|
456
442
|
|
|
457
|
-
const logger = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` }).child({ class: "
|
|
443
|
+
const logger = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` }).child({ class: "@SankaVollereii" })
|
|
458
444
|
logger.level = "fatal"
|
|
459
445
|
const store = makeInMemoryStore({ logger })
|
|
460
446
|
|
|
@@ -468,7 +454,7 @@ async function getMessage(key){
|
|
|
468
454
|
}
|
|
469
455
|
}
|
|
470
456
|
|
|
471
|
-
|
|
457
|
+
suki.ev.on("messages.update", async (chatUpdate) => {
|
|
472
458
|
for(const { key, update } of chatUpdate) {
|
|
473
459
|
if(update.pollUpdates && key.fromMe) {
|
|
474
460
|
const pollCreation = await getMessage(key)
|
|
@@ -501,7 +487,7 @@ sanka.ev.on("messages.update", async (chatUpdate) => {
|
|
|
501
487
|
It can be used as follows:
|
|
502
488
|
|
|
503
489
|
```ts
|
|
504
|
-
import makeWASocket, { makeInMemoryStore } from 'Sanka-
|
|
490
|
+
import makeWASocket, { makeInMemoryStore } from '@SankaVollereii/Sanka-Bail'
|
|
505
491
|
// the store maintains the data of the WA connection in memory
|
|
506
492
|
// can be written out to a file & read from it
|
|
507
493
|
const store = makeInMemoryStore({ })
|
|
@@ -512,18 +498,18 @@ setInterval(() => {
|
|
|
512
498
|
store.writeToFile('./baileys_store.json')
|
|
513
499
|
}, 10_000)
|
|
514
500
|
|
|
515
|
-
const
|
|
501
|
+
const suki = makeWASocket({ })
|
|
516
502
|
// will listen from this socket
|
|
517
503
|
// the store can listen from a new socket once the current socket outlives its lifetime
|
|
518
|
-
store.bind(
|
|
504
|
+
store.bind(suki.ev)
|
|
519
505
|
|
|
520
|
-
|
|
506
|
+
suki.ev.on('chats.upsert', () => {
|
|
521
507
|
// can use 'store.chats' however you want, even after the socket dies out
|
|
522
508
|
// 'chats' => a KeyedDB instance
|
|
523
509
|
console.log('got chats', store.chats.all())
|
|
524
510
|
})
|
|
525
511
|
|
|
526
|
-
|
|
512
|
+
suki.ev.on('contacts.upsert', () => {
|
|
527
513
|
console.log('got contacts', Object.values(store.contacts))
|
|
528
514
|
})
|
|
529
515
|
|
|
@@ -558,25 +544,25 @@ The store also provides some simple functions such as `loadMessages` that utiliz
|
|
|
558
544
|
const content: AnyMessageContent
|
|
559
545
|
const options: MiscMessageGenerationOptions
|
|
560
546
|
|
|
561
|
-
|
|
547
|
+
suki.sendMessage(jid, content, options)
|
|
562
548
|
```
|
|
563
549
|
|
|
564
550
|
### Non-Media Messages
|
|
565
551
|
|
|
566
552
|
#### Text Message
|
|
567
553
|
```ts
|
|
568
|
-
await
|
|
554
|
+
await suki.sendMessage(jid, { text: 'hello word' })
|
|
569
555
|
```
|
|
570
556
|
|
|
571
557
|
#### Quote Message (works with all types)
|
|
572
558
|
```ts
|
|
573
|
-
await
|
|
559
|
+
await suki.sendMessage(jid, { text: 'hello word' }, { quoted: message })
|
|
574
560
|
```
|
|
575
561
|
|
|
576
562
|
#### Mention User (works with most types)
|
|
577
563
|
- @number is to mention in text, it's optional
|
|
578
564
|
```ts
|
|
579
|
-
await
|
|
565
|
+
await suki.sendMessage(
|
|
580
566
|
jid,
|
|
581
567
|
{
|
|
582
568
|
text: '@12345678901',
|
|
@@ -589,12 +575,12 @@ await sanka.sendMessage(
|
|
|
589
575
|
- You need to have message object, can be retrieved from [store](#implementing-a-data-store) or use a [message](https://baileys.whiskeysockets.io/types/WAMessage.html) object
|
|
590
576
|
```ts
|
|
591
577
|
const msg = getMessageFromStore() // implement this on your end
|
|
592
|
-
await
|
|
578
|
+
await suki.sendMessage(jid, { forward: msg, force: true or number }) // WA forward the message!
|
|
593
579
|
```
|
|
594
580
|
|
|
595
581
|
#### Location Message
|
|
596
582
|
```ts
|
|
597
|
-
await
|
|
583
|
+
await suki.sendMessage(
|
|
598
584
|
jid,
|
|
599
585
|
{
|
|
600
586
|
location: {
|
|
@@ -607,7 +593,7 @@ await sanka.sendMessage(
|
|
|
607
593
|
|
|
608
594
|
#### Live Location Message
|
|
609
595
|
```ts
|
|
610
|
-
await
|
|
596
|
+
await suki.sendMessage(
|
|
611
597
|
jid,
|
|
612
598
|
{
|
|
613
599
|
location: {
|
|
@@ -627,7 +613,7 @@ const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
|
|
|
627
613
|
+ 'TELtype=CELLtype=VOICEwaid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
|
|
628
614
|
+ 'END:VCARD'
|
|
629
615
|
|
|
630
|
-
await
|
|
616
|
+
await suki.sendMessage(
|
|
631
617
|
id,
|
|
632
618
|
{
|
|
633
619
|
contacts: {
|
|
@@ -641,7 +627,7 @@ await sanka.sendMessage(
|
|
|
641
627
|
#### Reaction Message
|
|
642
628
|
- You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.whiskeysockets.io/types/WAMessageKey.html) object
|
|
643
629
|
```ts
|
|
644
|
-
await
|
|
630
|
+
await suki.sendMessage(
|
|
645
631
|
jid,
|
|
646
632
|
{
|
|
647
633
|
react: {
|
|
@@ -664,7 +650,7 @@ await sanka.sendMessage(
|
|
|
664
650
|
| 30d | 2.592.000 |
|
|
665
651
|
|
|
666
652
|
```ts
|
|
667
|
-
await
|
|
653
|
+
await suki.sendMessage(
|
|
668
654
|
jid,
|
|
669
655
|
{
|
|
670
656
|
pin: {
|
|
@@ -678,7 +664,7 @@ await sanka.sendMessage(
|
|
|
678
664
|
|
|
679
665
|
### Keep Message
|
|
680
666
|
```ts
|
|
681
|
-
await
|
|
667
|
+
await suki.sendMessage(
|
|
682
668
|
jid,
|
|
683
669
|
{
|
|
684
670
|
keep: {
|
|
@@ -691,7 +677,7 @@ await sanka.sendMessage(
|
|
|
691
677
|
|
|
692
678
|
#### Poll Message
|
|
693
679
|
```ts
|
|
694
|
-
await
|
|
680
|
+
await suki.sendMessage(
|
|
695
681
|
jid,
|
|
696
682
|
{
|
|
697
683
|
poll: {
|
|
@@ -706,7 +692,7 @@ await sanka.sendMessage(
|
|
|
706
692
|
|
|
707
693
|
#### Poll Result Message
|
|
708
694
|
```ts
|
|
709
|
-
await
|
|
695
|
+
await suki.sendMessage(
|
|
710
696
|
jid,
|
|
711
697
|
{
|
|
712
698
|
pollResult: {
|
|
@@ -728,7 +714,7 @@ await sanka.sendMessage(
|
|
|
728
714
|
|
|
729
715
|
### Call Message
|
|
730
716
|
```ts
|
|
731
|
-
await
|
|
717
|
+
await suki.sendMessage(
|
|
732
718
|
jid,
|
|
733
719
|
{
|
|
734
720
|
call: {
|
|
@@ -741,7 +727,7 @@ await sanka.sendMessage(
|
|
|
741
727
|
|
|
742
728
|
### Event Message
|
|
743
729
|
```ts
|
|
744
|
-
await
|
|
730
|
+
await suki.sendMessage(
|
|
745
731
|
jid,
|
|
746
732
|
{
|
|
747
733
|
event: {
|
|
@@ -763,7 +749,7 @@ await sanka.sendMessage(
|
|
|
763
749
|
|
|
764
750
|
### Order Message
|
|
765
751
|
```ts
|
|
766
|
-
await
|
|
752
|
+
await suki.sendMessage(
|
|
767
753
|
jid,
|
|
768
754
|
{
|
|
769
755
|
order: {
|
|
@@ -785,7 +771,7 @@ await sanka.sendMessage(
|
|
|
785
771
|
|
|
786
772
|
### Product Message
|
|
787
773
|
```ts
|
|
788
|
-
await
|
|
774
|
+
await suki.sendMessage(
|
|
789
775
|
jid,
|
|
790
776
|
{
|
|
791
777
|
product: {
|
|
@@ -811,7 +797,7 @@ await sanka.sendMessage(
|
|
|
811
797
|
|
|
812
798
|
### Payment Message
|
|
813
799
|
```ts
|
|
814
|
-
await
|
|
800
|
+
await suki.sendMessage(
|
|
815
801
|
jid,
|
|
816
802
|
{
|
|
817
803
|
payment: {
|
|
@@ -833,7 +819,7 @@ await sanka.sendMessage(
|
|
|
833
819
|
|
|
834
820
|
#### Payment Invite Message
|
|
835
821
|
```ts
|
|
836
|
-
await
|
|
822
|
+
await suki.sendMessage(
|
|
837
823
|
id,
|
|
838
824
|
{
|
|
839
825
|
paymentInvite: {
|
|
@@ -846,7 +832,7 @@ await sanka.sendMessage(
|
|
|
846
832
|
|
|
847
833
|
### Admin Invite Message
|
|
848
834
|
```ts
|
|
849
|
-
await
|
|
835
|
+
await suki.sendMessage(
|
|
850
836
|
jid,
|
|
851
837
|
{
|
|
852
838
|
adminInvite: {
|
|
@@ -862,7 +848,7 @@ await sanka.sendMessage(
|
|
|
862
848
|
|
|
863
849
|
### Group Invite Message
|
|
864
850
|
```ts
|
|
865
|
-
await
|
|
851
|
+
await suki.sendMessage(
|
|
866
852
|
jid,
|
|
867
853
|
{
|
|
868
854
|
groupInvite: {
|
|
@@ -879,7 +865,7 @@ await sanka.sendMessage(
|
|
|
879
865
|
|
|
880
866
|
### Share Phone Number Message
|
|
881
867
|
```ts
|
|
882
|
-
await
|
|
868
|
+
await suki.sendMessage(
|
|
883
869
|
jid,
|
|
884
870
|
{
|
|
885
871
|
sharePhoneNumber: {
|
|
@@ -890,7 +876,7 @@ await sanka.sendMessage(
|
|
|
890
876
|
|
|
891
877
|
### Request Phone Number Message
|
|
892
878
|
```ts
|
|
893
|
-
await
|
|
879
|
+
await suki.sendMessage(
|
|
894
880
|
jid,
|
|
895
881
|
{
|
|
896
882
|
requestPhoneNumber: {
|
|
@@ -902,7 +888,7 @@ await sanka.sendMessage(
|
|
|
902
888
|
### Buttons Reply Message
|
|
903
889
|
```ts
|
|
904
890
|
// List
|
|
905
|
-
await
|
|
891
|
+
await suki.sendMessage(
|
|
906
892
|
jid,
|
|
907
893
|
{
|
|
908
894
|
buttonReply: {
|
|
@@ -914,7 +900,7 @@ await sanka.sendMessage(
|
|
|
914
900
|
}
|
|
915
901
|
)
|
|
916
902
|
// Plain
|
|
917
|
-
await
|
|
903
|
+
await suki.sendMessage(
|
|
918
904
|
jid,
|
|
919
905
|
{
|
|
920
906
|
buttonReply: {
|
|
@@ -926,7 +912,7 @@ await sanka.sendMessage(
|
|
|
926
912
|
)
|
|
927
913
|
|
|
928
914
|
// Template
|
|
929
|
-
await
|
|
915
|
+
await suki.sendMessage(
|
|
930
916
|
jid,
|
|
931
917
|
{
|
|
932
918
|
buttonReply: {
|
|
@@ -939,7 +925,7 @@ await sanka.sendMessage(
|
|
|
939
925
|
)
|
|
940
926
|
|
|
941
927
|
// Interactive
|
|
942
|
-
await
|
|
928
|
+
await suki.sendMessage(
|
|
943
929
|
jid,
|
|
944
930
|
{
|
|
945
931
|
buttonReply: {
|
|
@@ -957,7 +943,7 @@ await sanka.sendMessage(
|
|
|
957
943
|
|
|
958
944
|
### Buttons Message
|
|
959
945
|
```ts
|
|
960
|
-
await
|
|
946
|
+
await suki.sendMessage(
|
|
961
947
|
jid,
|
|
962
948
|
{
|
|
963
949
|
text: 'This is a button message!', // image: buffer or // image: { url: url } If you want to use images
|
|
@@ -988,7 +974,7 @@ await sanka.sendMessage(
|
|
|
988
974
|
### Buttons List Message
|
|
989
975
|
```ts
|
|
990
976
|
// Just working in a private chat
|
|
991
|
-
await
|
|
977
|
+
await suki.sendMessage(
|
|
992
978
|
jid,
|
|
993
979
|
{
|
|
994
980
|
text: 'This is a list!',
|
|
@@ -1027,7 +1013,7 @@ await sanka.sendMessage(
|
|
|
1027
1013
|
### Buttons Product List Message
|
|
1028
1014
|
```ts
|
|
1029
1015
|
// Just working in a private chat
|
|
1030
|
-
await
|
|
1016
|
+
await suki.sendMessage(
|
|
1031
1017
|
jid,
|
|
1032
1018
|
{
|
|
1033
1019
|
text: 'This is a list!',
|
|
@@ -1053,7 +1039,7 @@ await sanka.sendMessage(
|
|
|
1053
1039
|
|
|
1054
1040
|
### Buttons Cards Message
|
|
1055
1041
|
```ts
|
|
1056
|
-
await
|
|
1042
|
+
await suki.sendMessage(
|
|
1057
1043
|
jid,
|
|
1058
1044
|
{
|
|
1059
1045
|
text: 'Body Message',
|
|
@@ -1112,7 +1098,7 @@ await sanka.sendMessage(
|
|
|
1112
1098
|
|
|
1113
1099
|
### Buttons Template Message
|
|
1114
1100
|
```ts
|
|
1115
|
-
await
|
|
1101
|
+
await suki.sendMessage(
|
|
1116
1102
|
jid,
|
|
1117
1103
|
{
|
|
1118
1104
|
text: 'This is a template message!',
|
|
@@ -1144,7 +1130,7 @@ await sanka.sendMessage(
|
|
|
1144
1130
|
|
|
1145
1131
|
### Buttons Interactive Message
|
|
1146
1132
|
```ts
|
|
1147
|
-
await
|
|
1133
|
+
await suki.sendMessage(
|
|
1148
1134
|
jid,
|
|
1149
1135
|
{
|
|
1150
1136
|
text: 'This is an Interactive message!',
|
|
@@ -1296,7 +1282,7 @@ await sanka.sendMessage(
|
|
|
1296
1282
|
)
|
|
1297
1283
|
|
|
1298
1284
|
// If you want to use an image
|
|
1299
|
-
await
|
|
1285
|
+
await suki.sendMessage(
|
|
1300
1286
|
jid,
|
|
1301
1287
|
{
|
|
1302
1288
|
image: {
|
|
@@ -1320,7 +1306,7 @@ await sanka.sendMessage(
|
|
|
1320
1306
|
)
|
|
1321
1307
|
|
|
1322
1308
|
// If you want to use an video
|
|
1323
|
-
await
|
|
1309
|
+
await suki.sendMessage(
|
|
1324
1310
|
jid,
|
|
1325
1311
|
{
|
|
1326
1312
|
video: {
|
|
@@ -1344,14 +1330,14 @@ await sanka.sendMessage(
|
|
|
1344
1330
|
)
|
|
1345
1331
|
|
|
1346
1332
|
// If you want to use an document
|
|
1347
|
-
await
|
|
1333
|
+
await suki.sendMessage(
|
|
1348
1334
|
jid,
|
|
1349
1335
|
{
|
|
1350
1336
|
document: {
|
|
1351
1337
|
url: 'https://example.jpg'
|
|
1352
1338
|
},
|
|
1353
1339
|
mimetype: 'image/jpeg',
|
|
1354
|
-
jpegThumbnail: await
|
|
1340
|
+
jpegThumbnail: await suki.resize('https://example.jpg', 320, 320),
|
|
1355
1341
|
caption: 'Body',
|
|
1356
1342
|
title: 'Title',
|
|
1357
1343
|
subtitle: 'Subtitle',
|
|
@@ -1370,7 +1356,7 @@ await sanka.sendMessage(
|
|
|
1370
1356
|
)
|
|
1371
1357
|
|
|
1372
1358
|
// If you want to use an location
|
|
1373
|
-
await
|
|
1359
|
+
await suki.sendMessage(
|
|
1374
1360
|
jid,
|
|
1375
1361
|
{
|
|
1376
1362
|
location: {
|
|
@@ -1396,7 +1382,7 @@ await sanka.sendMessage(
|
|
|
1396
1382
|
)
|
|
1397
1383
|
|
|
1398
1384
|
// if you want to use an product
|
|
1399
|
-
await
|
|
1385
|
+
await suki.sendMessage(
|
|
1400
1386
|
jid,
|
|
1401
1387
|
{
|
|
1402
1388
|
product: {
|
|
@@ -1433,7 +1419,7 @@ await sanka.sendMessage(
|
|
|
1433
1419
|
|
|
1434
1420
|
### Buttons Interactive Message PIX
|
|
1435
1421
|
```ts
|
|
1436
|
-
await
|
|
1422
|
+
await suki.sendMessage(
|
|
1437
1423
|
jid,
|
|
1438
1424
|
{
|
|
1439
1425
|
text: '', // This string is required. Even it's empty.
|
|
@@ -1458,7 +1444,7 @@ await sanka.sendMessage(
|
|
|
1458
1444
|
|
|
1459
1445
|
### Buttons Interactive Message PAY
|
|
1460
1446
|
```ts
|
|
1461
|
-
await
|
|
1447
|
+
await suki.sendMessage(
|
|
1462
1448
|
jid,
|
|
1463
1449
|
{
|
|
1464
1450
|
text: '', // This string is required. Even it's empty.
|
|
@@ -1508,7 +1494,7 @@ await sanka.sendMessage(
|
|
|
1508
1494
|
|
|
1509
1495
|
### Status Mentions Message
|
|
1510
1496
|
```ts
|
|
1511
|
-
await
|
|
1497
|
+
await suki.sendStatusMentions(
|
|
1512
1498
|
jid,
|
|
1513
1499
|
{
|
|
1514
1500
|
image: {
|
|
@@ -1521,7 +1507,7 @@ await sanka.sendStatusMentions(
|
|
|
1521
1507
|
|
|
1522
1508
|
### Send Album Message
|
|
1523
1509
|
```ts
|
|
1524
|
-
await
|
|
1510
|
+
await suki.sendAlbumMessage(
|
|
1525
1511
|
jid,
|
|
1526
1512
|
[
|
|
1527
1513
|
{
|
|
@@ -1549,7 +1535,7 @@ await sanka.sendAlbumMessage(
|
|
|
1549
1535
|
```
|
|
1550
1536
|
### Shop Message
|
|
1551
1537
|
```ts
|
|
1552
|
-
await
|
|
1538
|
+
await suki.sendMessage(
|
|
1553
1539
|
jid,
|
|
1554
1540
|
{
|
|
1555
1541
|
text: 'Body',
|
|
@@ -1565,7 +1551,7 @@ await sanka.sendMessage(
|
|
|
1565
1551
|
)
|
|
1566
1552
|
|
|
1567
1553
|
// Image
|
|
1568
|
-
await
|
|
1554
|
+
await suki.sendMessage(
|
|
1569
1555
|
jid,
|
|
1570
1556
|
{
|
|
1571
1557
|
image: {
|
|
@@ -1585,7 +1571,7 @@ await sanka.sendMessage(
|
|
|
1585
1571
|
)
|
|
1586
1572
|
|
|
1587
1573
|
// Video
|
|
1588
|
-
await
|
|
1574
|
+
await suki.sendMessage(
|
|
1589
1575
|
jid,
|
|
1590
1576
|
{
|
|
1591
1577
|
video: {
|
|
@@ -1605,14 +1591,14 @@ await sanka.sendMessage(
|
|
|
1605
1591
|
)
|
|
1606
1592
|
|
|
1607
1593
|
// Document
|
|
1608
|
-
await
|
|
1594
|
+
await suki.sendMessage(
|
|
1609
1595
|
jid,
|
|
1610
1596
|
{
|
|
1611
1597
|
document: {
|
|
1612
1598
|
url: 'https://example.jpg'
|
|
1613
1599
|
},
|
|
1614
1600
|
mimetype: 'image/jpeg',
|
|
1615
|
-
jpegThumbnail: await
|
|
1601
|
+
jpegThumbnail: await suki.resize('https://example.jpg', 320, 320),
|
|
1616
1602
|
caption: 'Body',
|
|
1617
1603
|
title: 'Title',
|
|
1618
1604
|
subtitle: 'Subtitle',
|
|
@@ -1627,7 +1613,7 @@ await sanka.sendMessage(
|
|
|
1627
1613
|
)
|
|
1628
1614
|
|
|
1629
1615
|
// Location
|
|
1630
|
-
await
|
|
1616
|
+
await suki.sendMessage(
|
|
1631
1617
|
jid,
|
|
1632
1618
|
{
|
|
1633
1619
|
location: {
|
|
@@ -1649,7 +1635,7 @@ await sanka.sendMessage(
|
|
|
1649
1635
|
)
|
|
1650
1636
|
|
|
1651
1637
|
// Product
|
|
1652
|
-
await
|
|
1638
|
+
await suki.sendMessage(
|
|
1653
1639
|
jid,
|
|
1654
1640
|
{
|
|
1655
1641
|
product: {
|
|
@@ -1681,7 +1667,7 @@ await sanka.sendMessage(
|
|
|
1681
1667
|
```
|
|
1682
1668
|
### Collection Message
|
|
1683
1669
|
```ts
|
|
1684
|
-
await
|
|
1670
|
+
await suki.sendMessage(
|
|
1685
1671
|
jid,
|
|
1686
1672
|
{
|
|
1687
1673
|
text: 'Body',
|
|
@@ -1698,7 +1684,7 @@ await sanka.sendMessage(
|
|
|
1698
1684
|
)
|
|
1699
1685
|
|
|
1700
1686
|
// Image
|
|
1701
|
-
await
|
|
1687
|
+
await suki.sendMessage(
|
|
1702
1688
|
jid,
|
|
1703
1689
|
{
|
|
1704
1690
|
image: {
|
|
@@ -1719,7 +1705,7 @@ await sanka.sendMessage(
|
|
|
1719
1705
|
)
|
|
1720
1706
|
|
|
1721
1707
|
// Video
|
|
1722
|
-
await
|
|
1708
|
+
await suki.sendMessage(
|
|
1723
1709
|
jid,
|
|
1724
1710
|
{
|
|
1725
1711
|
video: {
|
|
@@ -1740,14 +1726,14 @@ await sanka.sendMessage(
|
|
|
1740
1726
|
)
|
|
1741
1727
|
|
|
1742
1728
|
// Document
|
|
1743
|
-
await
|
|
1729
|
+
await suki.sendMessage(
|
|
1744
1730
|
jid,
|
|
1745
1731
|
{
|
|
1746
1732
|
document: {
|
|
1747
1733
|
url: 'https://example.jpg'
|
|
1748
1734
|
},
|
|
1749
1735
|
mimetype: 'image/jpeg',
|
|
1750
|
-
jpegThumbnail: await
|
|
1736
|
+
jpegThumbnail: await suki.resize('https://example.jpg', 320, 320),
|
|
1751
1737
|
caption: 'Body',
|
|
1752
1738
|
title: 'Title',
|
|
1753
1739
|
subtitle: 'Subtitle',
|
|
@@ -1763,7 +1749,7 @@ await sanka.sendMessage(
|
|
|
1763
1749
|
)
|
|
1764
1750
|
|
|
1765
1751
|
// Location
|
|
1766
|
-
await
|
|
1752
|
+
await suki.sendMessage(
|
|
1767
1753
|
jid,
|
|
1768
1754
|
{
|
|
1769
1755
|
location: {
|
|
@@ -1786,7 +1772,7 @@ await sanka.sendMessage(
|
|
|
1786
1772
|
)
|
|
1787
1773
|
|
|
1788
1774
|
// Product
|
|
1789
|
-
await
|
|
1775
|
+
await suki.sendMessage(
|
|
1790
1776
|
jid,
|
|
1791
1777
|
{
|
|
1792
1778
|
product: {
|
|
@@ -1825,7 +1811,7 @@ await sanka.sendMessage(
|
|
|
1825
1811
|
3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
|
|
1826
1812
|
4. Send a link:
|
|
1827
1813
|
```ts
|
|
1828
|
-
await
|
|
1814
|
+
await suki.sendMessage(
|
|
1829
1815
|
jid,
|
|
1830
1816
|
{
|
|
1831
1817
|
text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
|
|
@@ -1848,7 +1834,7 @@ Sending media (video, stickers, images) is easier & more efficient than ever.
|
|
|
1848
1834
|
#### Gif Message
|
|
1849
1835
|
- Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
|
|
1850
1836
|
```ts
|
|
1851
|
-
await
|
|
1837
|
+
await suki.sendMessage(
|
|
1852
1838
|
jid,
|
|
1853
1839
|
{
|
|
1854
1840
|
video: fs.readFileSync('Media/ma_gif.mp4'),
|
|
@@ -1860,7 +1846,7 @@ await sanka.sendMessage(
|
|
|
1860
1846
|
|
|
1861
1847
|
#### Video Message
|
|
1862
1848
|
```ts
|
|
1863
|
-
await
|
|
1849
|
+
await suki.sendMessage(
|
|
1864
1850
|
id,
|
|
1865
1851
|
{
|
|
1866
1852
|
video: {
|
|
@@ -1873,7 +1859,7 @@ await sanka.sendMessage(
|
|
|
1873
1859
|
|
|
1874
1860
|
#### Video Ptv Message
|
|
1875
1861
|
```ts
|
|
1876
|
-
await
|
|
1862
|
+
await suki.sendMessage(
|
|
1877
1863
|
id,
|
|
1878
1864
|
{
|
|
1879
1865
|
video: {
|
|
@@ -1897,7 +1883,7 @@ await sanka.sendMessage(
|
|
|
1897
1883
|
ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
|
|
1898
1884
|
```
|
|
1899
1885
|
```ts
|
|
1900
|
-
await
|
|
1886
|
+
await suki.sendMessage(
|
|
1901
1887
|
jid,
|
|
1902
1888
|
{
|
|
1903
1889
|
audio: {
|
|
@@ -1910,7 +1896,7 @@ await sanka.sendMessage(
|
|
|
1910
1896
|
|
|
1911
1897
|
#### Image Message
|
|
1912
1898
|
```ts
|
|
1913
|
-
await
|
|
1899
|
+
await suki.sendMessage(
|
|
1914
1900
|
id,
|
|
1915
1901
|
{
|
|
1916
1902
|
image: {
|
|
@@ -1926,7 +1912,7 @@ await sanka.sendMessage(
|
|
|
1926
1912
|
- You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
|
|
1927
1913
|
|
|
1928
1914
|
```ts
|
|
1929
|
-
await
|
|
1915
|
+
await suki.sendMessage(
|
|
1930
1916
|
id,
|
|
1931
1917
|
{
|
|
1932
1918
|
image: {
|
|
@@ -1943,8 +1929,8 @@ await sanka.sendMessage(
|
|
|
1943
1929
|
### Deleting Messages (for everyone)
|
|
1944
1930
|
|
|
1945
1931
|
```ts
|
|
1946
|
-
const msg = await
|
|
1947
|
-
await
|
|
1932
|
+
const msg = await suki.sendMessage(jid, { text: 'hello word' })
|
|
1933
|
+
await suki.sendMessage(jid, { delete: msg.key })
|
|
1948
1934
|
```
|
|
1949
1935
|
|
|
1950
1936
|
**Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
|
|
@@ -1953,7 +1939,7 @@ await sanka.sendMessage(jid, { delete: msg.key })
|
|
|
1953
1939
|
|
|
1954
1940
|
- You can pass all editable contents here
|
|
1955
1941
|
```ts
|
|
1956
|
-
await
|
|
1942
|
+
await suki.sendMessage(jid, {
|
|
1957
1943
|
text: 'updated text goes here',
|
|
1958
1944
|
edit: response.key,
|
|
1959
1945
|
})
|
|
@@ -1970,9 +1956,9 @@ await sanka.sendMessage(jid, {
|
|
|
1970
1956
|
If you want to save the media you received
|
|
1971
1957
|
```ts
|
|
1972
1958
|
import { createWriteStream } from 'fs'
|
|
1973
|
-
import { downloadMediaMessage, getContentType } from 'Sanka-
|
|
1959
|
+
import { downloadMediaMessage, getContentType } from '@SankaVollereii/Sanka-Bail'
|
|
1974
1960
|
|
|
1975
|
-
|
|
1961
|
+
suki.ev.on('messages.upsert', async ({ [m] }) => {
|
|
1976
1962
|
if (!m.message) return // if there is no text or media message
|
|
1977
1963
|
const messageType = getContentType(m) // get what type of message it is (text, image, video...)
|
|
1978
1964
|
|
|
@@ -1987,7 +1973,7 @@ sanka.ev.on('messages.upsert', async ({ [m] }) => {
|
|
|
1987
1973
|
logger,
|
|
1988
1974
|
// pass this so that baileys can request a reupload of media
|
|
1989
1975
|
// that has been deleted
|
|
1990
|
-
reuploadRequest:
|
|
1976
|
+
reuploadRequest: suki.updateMediaMessage
|
|
1991
1977
|
}
|
|
1992
1978
|
)
|
|
1993
1979
|
// save to file
|
|
@@ -2001,7 +1987,7 @@ sanka.ev.on('messages.upsert', async ({ [m] }) => {
|
|
|
2001
1987
|
|
|
2002
1988
|
- WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
|
|
2003
1989
|
```ts
|
|
2004
|
-
await
|
|
1990
|
+
await suki.updateMediaMessage(msg)
|
|
2005
1991
|
```
|
|
2006
1992
|
|
|
2007
1993
|
## Reject Call
|
|
@@ -2009,7 +1995,7 @@ await sanka.updateMediaMessage(msg)
|
|
|
2009
1995
|
- You can obtain `callId` and `callFrom` from `call` event
|
|
2010
1996
|
|
|
2011
1997
|
```ts
|
|
2012
|
-
await
|
|
1998
|
+
await suki.rejectCall(callId, callFrom)
|
|
2013
1999
|
```
|
|
2014
2000
|
|
|
2015
2001
|
## Send States in Chat
|
|
@@ -2022,7 +2008,7 @@ This means you have to keep track of unread messages.
|
|
|
2022
2008
|
```ts
|
|
2023
2009
|
const key: WAMessageKey
|
|
2024
2010
|
// can pass multiple keys to read multiple messages as well
|
|
2025
|
-
await
|
|
2011
|
+
await suki.readMessages([key])
|
|
2026
2012
|
```
|
|
2027
2013
|
|
|
2028
2014
|
The message ID is the unique identifier of the message that you are marking as read.
|
|
@@ -2035,11 +2021,11 @@ On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.k
|
|
|
2035
2021
|
- This lets the person/group with `jid` know whether you're online, offline, typing etc.
|
|
2036
2022
|
|
|
2037
2023
|
```ts
|
|
2038
|
-
await
|
|
2024
|
+
await suki.sendPresenceUpdate('available', jid)
|
|
2039
2025
|
```
|
|
2040
2026
|
|
|
2041
2027
|
> [!NOTE]
|
|
2042
|
-
> If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `
|
|
2028
|
+
> If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `suki.sendPresenceUpdate('unavailable')`
|
|
2043
2029
|
|
|
2044
2030
|
## Modifying Chats
|
|
2045
2031
|
|
|
@@ -2051,7 +2037,7 @@ WA uses an encrypted form of communication to send chat/app updates. This has be
|
|
|
2051
2037
|
### Archive a Chat
|
|
2052
2038
|
```ts
|
|
2053
2039
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
2054
|
-
await
|
|
2040
|
+
await suki.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
2055
2041
|
```
|
|
2056
2042
|
### Mute/Unmute a Chat
|
|
2057
2043
|
|
|
@@ -2065,20 +2051,20 @@ await sanka.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
|
2065
2051
|
|
|
2066
2052
|
```ts
|
|
2067
2053
|
// mute for 8 hours
|
|
2068
|
-
await
|
|
2054
|
+
await suki.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
|
|
2069
2055
|
// unmute
|
|
2070
|
-
await
|
|
2056
|
+
await suki.chatModify({ mute: null }, jid)
|
|
2071
2057
|
```
|
|
2072
2058
|
### Mark a Chat Read/Unread
|
|
2073
2059
|
```ts
|
|
2074
2060
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
2075
2061
|
// mark it unread
|
|
2076
|
-
await
|
|
2062
|
+
await suki.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
|
|
2077
2063
|
```
|
|
2078
2064
|
|
|
2079
2065
|
### Delete a Message for Me
|
|
2080
2066
|
```ts
|
|
2081
|
-
await
|
|
2067
|
+
await suki.chatModify(
|
|
2082
2068
|
{
|
|
2083
2069
|
clear: {
|
|
2084
2070
|
messages: [
|
|
@@ -2097,7 +2083,7 @@ await sanka.chatModify(
|
|
|
2097
2083
|
### Delete a Chat
|
|
2098
2084
|
```ts
|
|
2099
2085
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
2100
|
-
await
|
|
2086
|
+
await suki.chatModify({
|
|
2101
2087
|
delete: true,
|
|
2102
2088
|
lastMessages: [
|
|
2103
2089
|
{
|
|
@@ -2111,7 +2097,7 @@ await sanka.chatModify({
|
|
|
2111
2097
|
```
|
|
2112
2098
|
### Pin/Unpin a Chat
|
|
2113
2099
|
```ts
|
|
2114
|
-
await
|
|
2100
|
+
await suki.chatModify({
|
|
2115
2101
|
pin: true // or `false` to unpin
|
|
2116
2102
|
},
|
|
2117
2103
|
jid
|
|
@@ -2119,7 +2105,7 @@ await sanka.chatModify({
|
|
|
2119
2105
|
```
|
|
2120
2106
|
### Star/Unstar a Message
|
|
2121
2107
|
```ts
|
|
2122
|
-
await
|
|
2108
|
+
await suki.chatModify({
|
|
2123
2109
|
star: {
|
|
2124
2110
|
messages: [
|
|
2125
2111
|
{
|
|
@@ -2149,17 +2135,17 @@ await sanka.chatModify({
|
|
|
2149
2135
|
|
|
2150
2136
|
```ts
|
|
2151
2137
|
// turn on disappearing messages
|
|
2152
|
-
await
|
|
2138
|
+
await suki.sendMessage(
|
|
2153
2139
|
jid,
|
|
2154
2140
|
// this is 1 week in seconds -- how long you want messages to appear for
|
|
2155
2141
|
{ disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
|
|
2156
2142
|
)
|
|
2157
2143
|
|
|
2158
2144
|
// will send as a disappearing message
|
|
2159
|
-
await
|
|
2145
|
+
await suki.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
|
|
2160
2146
|
|
|
2161
2147
|
// turn off disappearing messages
|
|
2162
|
-
await
|
|
2148
|
+
await suki.sendMessage(
|
|
2163
2149
|
jid,
|
|
2164
2150
|
{ disappearingMessagesInChat: false }
|
|
2165
2151
|
)
|
|
@@ -2167,14 +2153,14 @@ await sanka.sendMessage(
|
|
|
2167
2153
|
|
|
2168
2154
|
### Clear Messages
|
|
2169
2155
|
```ts
|
|
2170
|
-
await
|
|
2156
|
+
await suki.clearMessage(jid, key, timestamps)
|
|
2171
2157
|
```
|
|
2172
2158
|
|
|
2173
2159
|
## User Querys
|
|
2174
2160
|
|
|
2175
2161
|
### Check If ID Exists in Whatsapp
|
|
2176
2162
|
```ts
|
|
2177
|
-
const [result] = await
|
|
2163
|
+
const [result] = await suki.onWhatsApp(jid)
|
|
2178
2164
|
if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
|
|
2179
2165
|
```
|
|
2180
2166
|
|
|
@@ -2183,7 +2169,7 @@ if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid
|
|
|
2183
2169
|
- You need to have oldest message in chat
|
|
2184
2170
|
```ts
|
|
2185
2171
|
const msg = await getOldestMessageInChat(jid)
|
|
2186
|
-
await
|
|
2172
|
+
await suki.fetchMessageHistory(
|
|
2187
2173
|
50, //quantity (max: 50 per query)
|
|
2188
2174
|
msg.key,
|
|
2189
2175
|
msg.messageTimestamp
|
|
@@ -2193,7 +2179,7 @@ await sanka.fetchMessageHistory(
|
|
|
2193
2179
|
|
|
2194
2180
|
### Fetch Status
|
|
2195
2181
|
```ts
|
|
2196
|
-
const status = await
|
|
2182
|
+
const status = await suki.fetchStatus(jid)
|
|
2197
2183
|
console.log('status: ' + status)
|
|
2198
2184
|
```
|
|
2199
2185
|
|
|
@@ -2201,34 +2187,34 @@ console.log('status: ' + status)
|
|
|
2201
2187
|
- To get the display picture of some person, group and channel
|
|
2202
2188
|
```ts
|
|
2203
2189
|
// for low res picture
|
|
2204
|
-
const ppUrl = await
|
|
2190
|
+
const ppUrl = await suki.profilePictureUrl(jid)
|
|
2205
2191
|
console.log(ppUrl)
|
|
2206
2192
|
```
|
|
2207
2193
|
|
|
2208
2194
|
### Fetch Bussines Profile (such as description or category)
|
|
2209
2195
|
```ts
|
|
2210
|
-
const profile = await
|
|
2196
|
+
const profile = await suki.getBusinessProfile(jid)
|
|
2211
2197
|
console.log('business description: ' + profile.description + ', category: ' + profile.category)
|
|
2212
2198
|
```
|
|
2213
2199
|
|
|
2214
2200
|
### Fetch Someone's Presence (if they're typing or online)
|
|
2215
2201
|
```ts
|
|
2216
2202
|
// the presence update is fetched and called here
|
|
2217
|
-
|
|
2203
|
+
suki.ev.on('presence.update', console.log)
|
|
2218
2204
|
|
|
2219
2205
|
// request updates for a chat
|
|
2220
|
-
await
|
|
2206
|
+
await suki.presenceSubscribe(jid)
|
|
2221
2207
|
```
|
|
2222
2208
|
|
|
2223
2209
|
## Change Profile
|
|
2224
2210
|
|
|
2225
2211
|
### Change Profile Status
|
|
2226
2212
|
```ts
|
|
2227
|
-
await
|
|
2213
|
+
await suki.updateProfileStatus('Hello World!')
|
|
2228
2214
|
```
|
|
2229
2215
|
### Change Profile Name
|
|
2230
2216
|
```ts
|
|
2231
|
-
await
|
|
2217
|
+
await suki.updateProfileName('My name')
|
|
2232
2218
|
```
|
|
2233
2219
|
### Change Display Picture (groups too)
|
|
2234
2220
|
- To change your display picture or a group's
|
|
@@ -2237,11 +2223,11 @@ await sanka.updateProfileName('My name')
|
|
|
2237
2223
|
> Like media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://baileys.whiskeysockets.io/types/WAMediaUpload.html)
|
|
2238
2224
|
|
|
2239
2225
|
```ts
|
|
2240
|
-
await
|
|
2226
|
+
await suki.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
|
|
2241
2227
|
```
|
|
2242
2228
|
### Remove display picture (groups too)
|
|
2243
2229
|
```ts
|
|
2244
|
-
await
|
|
2230
|
+
await suki.removeProfilePicture(jid)
|
|
2245
2231
|
```
|
|
2246
2232
|
|
|
2247
2233
|
## Groups
|
|
@@ -2251,14 +2237,14 @@ await sanka.removeProfilePicture(jid)
|
|
|
2251
2237
|
### Create a Group
|
|
2252
2238
|
```ts
|
|
2253
2239
|
// title & participants
|
|
2254
|
-
const group = await
|
|
2240
|
+
const group = await suki.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
|
|
2255
2241
|
console.log('created group with id: ' + group.gid)
|
|
2256
|
-
await
|
|
2242
|
+
await suki.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
|
|
2257
2243
|
```
|
|
2258
2244
|
### Add/Remove or Demote/Promote
|
|
2259
2245
|
```ts
|
|
2260
2246
|
// id & people to add to the group (will throw error if it fails)
|
|
2261
|
-
await
|
|
2247
|
+
await suki.groupParticipantsUpdate(
|
|
2262
2248
|
jid,
|
|
2263
2249
|
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
2264
2250
|
'add' // replace this parameter with 'remove' or 'demote' or 'promote'
|
|
@@ -2266,68 +2252,68 @@ await sanka.groupParticipantsUpdate(
|
|
|
2266
2252
|
```
|
|
2267
2253
|
### Change Subject (name)
|
|
2268
2254
|
```ts
|
|
2269
|
-
await
|
|
2255
|
+
await suki.groupUpdateSubject(jid, 'New Subject!')
|
|
2270
2256
|
```
|
|
2271
2257
|
### Change Description
|
|
2272
2258
|
```ts
|
|
2273
|
-
await
|
|
2259
|
+
await suki.groupUpdateDescription(jid, 'New Description!')
|
|
2274
2260
|
```
|
|
2275
2261
|
### Change Settings
|
|
2276
2262
|
```ts
|
|
2277
2263
|
// only allow admins to send messages
|
|
2278
|
-
await
|
|
2264
|
+
await suki.groupSettingUpdate(jid, 'announcement')
|
|
2279
2265
|
// allow everyone to send messages
|
|
2280
|
-
await
|
|
2266
|
+
await suki.groupSettingUpdate(jid, 'not_announcement')
|
|
2281
2267
|
// allow everyone to modify the group's settings -- like display picture etc.
|
|
2282
|
-
await
|
|
2268
|
+
await suki.groupSettingUpdate(jid, 'unlocked')
|
|
2283
2269
|
// only allow admins to modify the group's settings
|
|
2284
|
-
await
|
|
2270
|
+
await suki.groupSettingUpdate(jid, 'locked')
|
|
2285
2271
|
```
|
|
2286
2272
|
### Leave a Group
|
|
2287
2273
|
```ts
|
|
2288
2274
|
// will throw error if it fails
|
|
2289
|
-
await
|
|
2275
|
+
await suki.groupLeave(jid)
|
|
2290
2276
|
```
|
|
2291
2277
|
### Get Invite Code
|
|
2292
2278
|
- To create link with code use `'https://chat.whatsapp.com/' + code`
|
|
2293
2279
|
```ts
|
|
2294
|
-
const code = await
|
|
2280
|
+
const code = await suki.groupInviteCode(jid)
|
|
2295
2281
|
console.log('group code: ' + code)
|
|
2296
2282
|
```
|
|
2297
2283
|
### Revoke Invite Code
|
|
2298
2284
|
```ts
|
|
2299
|
-
const code = await
|
|
2285
|
+
const code = await suki.groupRevokeInvite(jid)
|
|
2300
2286
|
console.log('New group code: ' + code)
|
|
2301
2287
|
```
|
|
2302
2288
|
### Join Using Invitation Code
|
|
2303
2289
|
- Code can't have `https://chat.whatsapp.com/`, only code
|
|
2304
2290
|
```ts
|
|
2305
|
-
const response = await
|
|
2291
|
+
const response = await suki.groupAcceptInvite(code)
|
|
2306
2292
|
console.log('joined to: ' + response)
|
|
2307
2293
|
```
|
|
2308
2294
|
### Get Group Info by Invite Code
|
|
2309
2295
|
```ts
|
|
2310
|
-
const response = await
|
|
2296
|
+
const response = await suki.groupGetInviteInfo(code)
|
|
2311
2297
|
console.log('group information: ' + response)
|
|
2312
2298
|
```
|
|
2313
2299
|
### Query Metadata (participants, name, description...)
|
|
2314
2300
|
```ts
|
|
2315
|
-
const metadata = await
|
|
2301
|
+
const metadata = await suki.groupMetadata(jid)
|
|
2316
2302
|
console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
|
|
2317
2303
|
```
|
|
2318
2304
|
### Join using `groupInviteMessage`
|
|
2319
2305
|
```ts
|
|
2320
|
-
const response = await
|
|
2306
|
+
const response = await suki.groupAcceptInviteV4(jid, groupInviteMessage)
|
|
2321
2307
|
console.log('joined to: ' + response)
|
|
2322
2308
|
```
|
|
2323
2309
|
### Get Request Join List
|
|
2324
2310
|
```ts
|
|
2325
|
-
const response = await
|
|
2311
|
+
const response = await suki.groupRequestParticipantsList(jid)
|
|
2326
2312
|
console.log(response)
|
|
2327
2313
|
```
|
|
2328
2314
|
### Approve/Reject Request Join
|
|
2329
2315
|
```ts
|
|
2330
|
-
const response = await
|
|
2316
|
+
const response = await suki.groupRequestParticipantsUpdate(
|
|
2331
2317
|
jid, // group id
|
|
2332
2318
|
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
2333
2319
|
'approve' // or 'reject'
|
|
@@ -2336,7 +2322,7 @@ console.log(response)
|
|
|
2336
2322
|
```
|
|
2337
2323
|
### Get All Participating Groups Metadata
|
|
2338
2324
|
```ts
|
|
2339
|
-
const response = await
|
|
2325
|
+
const response = await suki.groupFetchAllParticipating()
|
|
2340
2326
|
console.log(response)
|
|
2341
2327
|
```
|
|
2342
2328
|
### Toggle Ephemeral
|
|
@@ -2351,12 +2337,12 @@ console.log(response)
|
|
|
2351
2337
|
| 90d | 7.776.000 |
|
|
2352
2338
|
|
|
2353
2339
|
```ts
|
|
2354
|
-
await
|
|
2340
|
+
await suki.groupToggleEphemeral(jid, 86400)
|
|
2355
2341
|
```
|
|
2356
2342
|
|
|
2357
2343
|
### Change Add Mode
|
|
2358
2344
|
```ts
|
|
2359
|
-
await
|
|
2345
|
+
await suki.groupMemberAddMode(
|
|
2360
2346
|
jid,
|
|
2361
2347
|
'all_member_add' // or 'admin_add'
|
|
2362
2348
|
)
|
|
@@ -2366,48 +2352,48 @@ await sanka.groupMemberAddMode(
|
|
|
2366
2352
|
|
|
2367
2353
|
### Block/Unblock User
|
|
2368
2354
|
```ts
|
|
2369
|
-
await
|
|
2370
|
-
await
|
|
2355
|
+
await suki.updateBlockStatus(jid, 'block') // Block user
|
|
2356
|
+
await suki.updateBlockStatus(jid, 'unblock') // Unblock user
|
|
2371
2357
|
```
|
|
2372
2358
|
### Get Privacy Settings
|
|
2373
2359
|
```ts
|
|
2374
|
-
const privacySettings = await
|
|
2360
|
+
const privacySettings = await suki.fetchPrivacySettings(true)
|
|
2375
2361
|
console.log('privacy settings: ' + privacySettings)
|
|
2376
2362
|
```
|
|
2377
2363
|
### Get BlockList
|
|
2378
2364
|
```ts
|
|
2379
|
-
const response = await
|
|
2365
|
+
const response = await suki.fetchBlocklist()
|
|
2380
2366
|
console.log(response)
|
|
2381
2367
|
```
|
|
2382
2368
|
### Update LastSeen Privacy
|
|
2383
2369
|
```ts
|
|
2384
2370
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
2385
|
-
await
|
|
2371
|
+
await suki.updateLastSeenPrivacy(value)
|
|
2386
2372
|
```
|
|
2387
2373
|
### Update Online Privacy
|
|
2388
2374
|
```ts
|
|
2389
2375
|
const value = 'all' // 'match_last_seen'
|
|
2390
|
-
await
|
|
2376
|
+
await suki.updateOnlinePrivacy(value)
|
|
2391
2377
|
```
|
|
2392
2378
|
### Update Profile Picture Privacy
|
|
2393
2379
|
```ts
|
|
2394
2380
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
2395
|
-
await
|
|
2381
|
+
await suki.updateProfilePicturePrivacy(value)
|
|
2396
2382
|
```
|
|
2397
2383
|
### Update Status Privacy
|
|
2398
2384
|
```ts
|
|
2399
2385
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
2400
|
-
await
|
|
2386
|
+
await suki.updateStatusPrivacy(value)
|
|
2401
2387
|
```
|
|
2402
2388
|
### Update Read Receipts Privacy
|
|
2403
2389
|
```ts
|
|
2404
2390
|
const value = 'all' // 'none'
|
|
2405
|
-
await
|
|
2391
|
+
await suki.updateReadReceiptsPrivacy(value)
|
|
2406
2392
|
```
|
|
2407
2393
|
### Update Groups Add Privacy
|
|
2408
2394
|
```ts
|
|
2409
2395
|
const value = 'all' // 'contacts' | 'contact_blacklist'
|
|
2410
|
-
await
|
|
2396
|
+
await suki.updateGroupsAddPrivacy(value)
|
|
2411
2397
|
```
|
|
2412
2398
|
### Update Default Disappearing Mode
|
|
2413
2399
|
|
|
@@ -2422,7 +2408,7 @@ await sanka.updateGroupsAddPrivacy(value)
|
|
|
2422
2408
|
|
|
2423
2409
|
```ts
|
|
2424
2410
|
const ephemeral = 86400
|
|
2425
|
-
await
|
|
2411
|
+
await suki.updateDefaultDisappearingMode(ephemeral)
|
|
2426
2412
|
```
|
|
2427
2413
|
|
|
2428
2414
|
## Broadcast Lists & Stories
|
|
@@ -2430,7 +2416,7 @@ await sanka.updateDefaultDisappearingMode(ephemeral)
|
|
|
2430
2416
|
### Send Broadcast & Stories
|
|
2431
2417
|
- Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
|
|
2432
2418
|
```ts
|
|
2433
|
-
await
|
|
2419
|
+
await suki.sendMessage(
|
|
2434
2420
|
jid,
|
|
2435
2421
|
{
|
|
2436
2422
|
image: {
|
|
@@ -2456,7 +2442,7 @@ await sanka.sendMessage(
|
|
|
2456
2442
|
- Broadcast IDs are in the format `12345678@broadcast`
|
|
2457
2443
|
### Query a Broadcast List's Recipients & Name
|
|
2458
2444
|
```ts
|
|
2459
|
-
const bList = await
|
|
2445
|
+
const bList = await suki.getBroadcastListInfo('1234@broadcast')
|
|
2460
2446
|
console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
|
|
2461
2447
|
```
|
|
2462
2448
|
|
|
@@ -2466,7 +2452,7 @@ Baileys is written with custom functionality in mind. Instead of forking the pro
|
|
|
2466
2452
|
### Enabling Debug Level in Baileys Logs
|
|
2467
2453
|
First, enable the logging of unhandled messages from WhatsApp by setting:
|
|
2468
2454
|
```ts
|
|
2469
|
-
const
|
|
2455
|
+
const suki = makeWASocket({
|
|
2470
2456
|
logger: P({ level: 'debug' }),
|
|
2471
2457
|
})
|
|
2472
2458
|
```
|
|
@@ -2521,13 +2507,13 @@ The `'frame'` is what the message received is, it has three components:
|
|
|
2521
2507
|
|
|
2522
2508
|
```ts
|
|
2523
2509
|
// for any message with tag 'edge_routing'
|
|
2524
|
-
|
|
2510
|
+
suki.ws.on('CB:edge_routing', (node: BinaryNode) => { })
|
|
2525
2511
|
|
|
2526
2512
|
// for any message with tag 'edge_routing' and id attribute = abcd
|
|
2527
|
-
|
|
2513
|
+
suki.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
|
|
2528
2514
|
|
|
2529
2515
|
// for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
|
|
2530
|
-
|
|
2516
|
+
suki.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
|
|
2531
2517
|
```
|
|
2532
2518
|
|
|
2533
2519
|
> [!NOTE]
|