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