sanka-baileyss 1.4.9 → 1.5.0
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 +165 -165
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -219,7 +219,7 @@ WhatsApp provides a multi-device API that allows Baileys to be authenticated as
|
|
|
219
219
|
```ts
|
|
220
220
|
import makeWASocket from '@SankaVollereii/Sanka-Bail'
|
|
221
221
|
|
|
222
|
-
const
|
|
222
|
+
const sanka = makeWASocket({
|
|
223
223
|
// can provide additional config here
|
|
224
224
|
browser: Browsers.ubuntu('My App'),
|
|
225
225
|
printQRInTerminal: true
|
|
@@ -239,14 +239,14 @@ The phone number can't have `+` or `()` or `-`, only numbers, you must provide c
|
|
|
239
239
|
```ts
|
|
240
240
|
import makeWASocket from '@SankaVollereii/Sanka-Bail'
|
|
241
241
|
|
|
242
|
-
const
|
|
242
|
+
const sanka = makeWASocket({
|
|
243
243
|
// can provide additional config here
|
|
244
244
|
printQRInTerminal: false //need to be false
|
|
245
245
|
})
|
|
246
246
|
|
|
247
|
-
if (!
|
|
247
|
+
if (!sanka.authState.creds.registered) {
|
|
248
248
|
const number = 'XXXXXXXXXXX'
|
|
249
|
-
const code = await
|
|
249
|
+
const code = await sanka.requestPairingCode(number) // or await sanka.requestPairingCode(number, 'CODEOTPS') custom your pairing code
|
|
250
250
|
console.log(code)
|
|
251
251
|
}
|
|
252
252
|
```
|
|
@@ -258,7 +258,7 @@ if (!suki.authState.creds.registered) {
|
|
|
258
258
|
- If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
|
|
259
259
|
|
|
260
260
|
```ts
|
|
261
|
-
const
|
|
261
|
+
const sanka = makeWASocket({
|
|
262
262
|
...otherOpts,
|
|
263
263
|
// can use Windows, Ubuntu here too
|
|
264
264
|
browser: Browsers.macOS('Desktop'),
|
|
@@ -274,17 +274,17 @@ const suki = makeWASocket({
|
|
|
274
274
|
```ts
|
|
275
275
|
const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
|
|
276
276
|
|
|
277
|
-
const
|
|
277
|
+
const sanka = makeWASocket({
|
|
278
278
|
cachedGroupMetadata: async (jid) => groupCache.get(jid)
|
|
279
279
|
})
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
const metadata = await
|
|
281
|
+
sanka.ev.on('groups.update', async ([event]) => {
|
|
282
|
+
const metadata = await sanka.groupMetadata(event.id)
|
|
283
283
|
groupCache.set(event.id, metadata)
|
|
284
284
|
})
|
|
285
285
|
|
|
286
|
-
|
|
287
|
-
const metadata = await
|
|
286
|
+
sanka.ev.on('group-participants.update', async (event) => {
|
|
287
|
+
const metadata = await sanka.groupMetadata(event.id)
|
|
288
288
|
groupCache.set(event.id, metadata)
|
|
289
289
|
})
|
|
290
290
|
```
|
|
@@ -292,7 +292,7 @@ const suki = makeWASocket({
|
|
|
292
292
|
### Improve Retry System & Decrypt Poll Votes
|
|
293
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:
|
|
294
294
|
```ts
|
|
295
|
-
const
|
|
295
|
+
const sanka = makeWASocket({
|
|
296
296
|
getMessage: async (key) => await getMessageFromStore(key)
|
|
297
297
|
})
|
|
298
298
|
```
|
|
@@ -300,7 +300,7 @@ const suki = makeWASocket({
|
|
|
300
300
|
### Receive Notifications in Whatsapp App
|
|
301
301
|
- If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
|
|
302
302
|
```ts
|
|
303
|
-
const
|
|
303
|
+
const sanka = makeWASocket({
|
|
304
304
|
markOnlineOnConnect: false
|
|
305
305
|
})
|
|
306
306
|
```
|
|
@@ -316,10 +316,10 @@ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
|
|
|
316
316
|
|
|
317
317
|
// will use the given state to connect
|
|
318
318
|
// so if valid credentials are available -- it'll connect without QR
|
|
319
|
-
const
|
|
319
|
+
const sanka = makeWASocket({ auth: state })
|
|
320
320
|
|
|
321
321
|
// this will be called as soon as the credentials are updated
|
|
322
|
-
|
|
322
|
+
sanka.ev.on('creds.update', saveCreds)
|
|
323
323
|
```
|
|
324
324
|
|
|
325
325
|
> [!IMPORTANT]
|
|
@@ -338,8 +338,8 @@ They're all nicely typed up, so you shouldn't have any issues with an Intellisen
|
|
|
338
338
|
|
|
339
339
|
You can listen to these events like this:
|
|
340
340
|
```ts
|
|
341
|
-
const
|
|
342
|
-
|
|
341
|
+
const sanka = makeWASocket()
|
|
342
|
+
sanka.ev.on('messages.upsert', ({ messages }) => {
|
|
343
343
|
console.log('got messages', messages)
|
|
344
344
|
})
|
|
345
345
|
```
|
|
@@ -355,12 +355,12 @@ import { Boom } from '@hapi/boom'
|
|
|
355
355
|
|
|
356
356
|
async function connectToWhatsApp () {
|
|
357
357
|
const { state, saveCreds } = await useMultiFileAuthState('./auth_info_baileys')
|
|
358
|
-
const
|
|
358
|
+
const sanka = makeWASocket({
|
|
359
359
|
// can provide additional config here
|
|
360
360
|
auth: state,
|
|
361
361
|
printQRInTerminal: true
|
|
362
362
|
})
|
|
363
|
-
|
|
363
|
+
sanka.ev.on('connection.update', (update) => {
|
|
364
364
|
const { connection, lastDisconnect } = update
|
|
365
365
|
if(connection === 'close') {
|
|
366
366
|
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
|
|
@@ -373,17 +373,17 @@ async function connectToWhatsApp () {
|
|
|
373
373
|
console.log('opened connection')
|
|
374
374
|
}
|
|
375
375
|
})
|
|
376
|
-
|
|
376
|
+
sanka.ev.on('messages.upsert', event => {
|
|
377
377
|
for (const m of event.messages) {
|
|
378
378
|
console.log(JSON.stringify(m, undefined, 2))
|
|
379
379
|
|
|
380
380
|
console.log('replying to', m.key.remoteJid)
|
|
381
|
-
await
|
|
381
|
+
await sanka.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
|
|
382
382
|
}
|
|
383
383
|
})
|
|
384
384
|
|
|
385
385
|
// to storage creds (session info) when it updates
|
|
386
|
-
|
|
386
|
+
sanka.ev.on('creds.update', saveCreds)
|
|
387
387
|
}
|
|
388
388
|
// run in main file
|
|
389
389
|
connectToWhatsApp()
|
|
@@ -395,12 +395,12 @@ import makeWASocket, { useSingleFileAuthState, useMongoFileAuthState } from '@Sa
|
|
|
395
395
|
|
|
396
396
|
// Single Auth
|
|
397
397
|
const { state, saveState } = await useSingleFileAuthState('./auth_info_baileys.json')
|
|
398
|
-
const
|
|
398
|
+
const sanka = makeWASocket({
|
|
399
399
|
auth: state,
|
|
400
400
|
printQRInTerminal: true
|
|
401
401
|
})
|
|
402
402
|
|
|
403
|
-
|
|
403
|
+
sanka.ev.on('creds.update', saveState)
|
|
404
404
|
|
|
405
405
|
// Mongo Auth
|
|
406
406
|
import { MongoClient } from "mongodb"
|
|
@@ -422,12 +422,12 @@ const connectAuth = async() => {
|
|
|
422
422
|
|
|
423
423
|
const Authentication = await connectAuth()
|
|
424
424
|
const { state, saveCreds } = await useMongoFileAuthState(Authentication)
|
|
425
|
-
const
|
|
425
|
+
const sanka = makeWASocket({
|
|
426
426
|
auth: state,
|
|
427
427
|
printQRInTerminal: true
|
|
428
428
|
})
|
|
429
429
|
|
|
430
|
-
|
|
430
|
+
sanka.ev.on('creds.update', saveCreds)
|
|
431
431
|
```
|
|
432
432
|
|
|
433
433
|
> [!IMPORTANT]
|
|
@@ -454,7 +454,7 @@ async function getMessage(key){
|
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
|
|
457
|
+
sanka.ev.on("messages.update", async (chatUpdate) => {
|
|
458
458
|
for(const { key, update } of chatUpdate) {
|
|
459
459
|
if(update.pollUpdates && key.fromMe) {
|
|
460
460
|
const pollCreation = await getMessage(key)
|
|
@@ -498,18 +498,18 @@ setInterval(() => {
|
|
|
498
498
|
store.writeToFile('./baileys_store.json')
|
|
499
499
|
}, 10_000)
|
|
500
500
|
|
|
501
|
-
const
|
|
501
|
+
const sanka = makeWASocket({ })
|
|
502
502
|
// will listen from this socket
|
|
503
503
|
// the store can listen from a new socket once the current socket outlives its lifetime
|
|
504
|
-
store.bind(
|
|
504
|
+
store.bind(sanka.ev)
|
|
505
505
|
|
|
506
|
-
|
|
506
|
+
sanka.ev.on('chats.upsert', () => {
|
|
507
507
|
// can use 'store.chats' however you want, even after the socket dies out
|
|
508
508
|
// 'chats' => a KeyedDB instance
|
|
509
509
|
console.log('got chats', store.chats.all())
|
|
510
510
|
})
|
|
511
511
|
|
|
512
|
-
|
|
512
|
+
sanka.ev.on('contacts.upsert', () => {
|
|
513
513
|
console.log('got contacts', Object.values(store.contacts))
|
|
514
514
|
})
|
|
515
515
|
|
|
@@ -544,25 +544,25 @@ The store also provides some simple functions such as `loadMessages` that utiliz
|
|
|
544
544
|
const content: AnyMessageContent
|
|
545
545
|
const options: MiscMessageGenerationOptions
|
|
546
546
|
|
|
547
|
-
|
|
547
|
+
sanka.sendMessage(jid, content, options)
|
|
548
548
|
```
|
|
549
549
|
|
|
550
550
|
### Non-Media Messages
|
|
551
551
|
|
|
552
552
|
#### Text Message
|
|
553
553
|
```ts
|
|
554
|
-
await
|
|
554
|
+
await sanka.sendMessage(jid, { text: 'hello word' })
|
|
555
555
|
```
|
|
556
556
|
|
|
557
557
|
#### Quote Message (works with all types)
|
|
558
558
|
```ts
|
|
559
|
-
await
|
|
559
|
+
await sanka.sendMessage(jid, { text: 'hello word' }, { quoted: message })
|
|
560
560
|
```
|
|
561
561
|
|
|
562
562
|
#### Mention User (works with most types)
|
|
563
563
|
- @number is to mention in text, it's optional
|
|
564
564
|
```ts
|
|
565
|
-
await
|
|
565
|
+
await sanka.sendMessage(
|
|
566
566
|
jid,
|
|
567
567
|
{
|
|
568
568
|
text: '@12345678901',
|
|
@@ -575,12 +575,12 @@ await suki.sendMessage(
|
|
|
575
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
|
|
576
576
|
```ts
|
|
577
577
|
const msg = getMessageFromStore() // implement this on your end
|
|
578
|
-
await
|
|
578
|
+
await sanka.sendMessage(jid, { forward: msg, force: true or number }) // WA forward the message!
|
|
579
579
|
```
|
|
580
580
|
|
|
581
581
|
#### Location Message
|
|
582
582
|
```ts
|
|
583
|
-
await
|
|
583
|
+
await sanka.sendMessage(
|
|
584
584
|
jid,
|
|
585
585
|
{
|
|
586
586
|
location: {
|
|
@@ -593,7 +593,7 @@ await suki.sendMessage(
|
|
|
593
593
|
|
|
594
594
|
#### Live Location Message
|
|
595
595
|
```ts
|
|
596
|
-
await
|
|
596
|
+
await sanka.sendMessage(
|
|
597
597
|
jid,
|
|
598
598
|
{
|
|
599
599
|
location: {
|
|
@@ -613,7 +613,7 @@ const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
|
|
|
613
613
|
+ 'TELtype=CELLtype=VOICEwaid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
|
|
614
614
|
+ 'END:VCARD'
|
|
615
615
|
|
|
616
|
-
await
|
|
616
|
+
await sanka.sendMessage(
|
|
617
617
|
id,
|
|
618
618
|
{
|
|
619
619
|
contacts: {
|
|
@@ -627,7 +627,7 @@ await suki.sendMessage(
|
|
|
627
627
|
#### Reaction Message
|
|
628
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
|
|
629
629
|
```ts
|
|
630
|
-
await
|
|
630
|
+
await sanka.sendMessage(
|
|
631
631
|
jid,
|
|
632
632
|
{
|
|
633
633
|
react: {
|
|
@@ -650,7 +650,7 @@ await suki.sendMessage(
|
|
|
650
650
|
| 30d | 2.592.000 |
|
|
651
651
|
|
|
652
652
|
```ts
|
|
653
|
-
await
|
|
653
|
+
await sanka.sendMessage(
|
|
654
654
|
jid,
|
|
655
655
|
{
|
|
656
656
|
pin: {
|
|
@@ -664,7 +664,7 @@ await suki.sendMessage(
|
|
|
664
664
|
|
|
665
665
|
### Keep Message
|
|
666
666
|
```ts
|
|
667
|
-
await
|
|
667
|
+
await sanka.sendMessage(
|
|
668
668
|
jid,
|
|
669
669
|
{
|
|
670
670
|
keep: {
|
|
@@ -677,7 +677,7 @@ await suki.sendMessage(
|
|
|
677
677
|
|
|
678
678
|
#### Poll Message
|
|
679
679
|
```ts
|
|
680
|
-
await
|
|
680
|
+
await sanka.sendMessage(
|
|
681
681
|
jid,
|
|
682
682
|
{
|
|
683
683
|
poll: {
|
|
@@ -692,7 +692,7 @@ await suki.sendMessage(
|
|
|
692
692
|
|
|
693
693
|
#### Poll Result Message
|
|
694
694
|
```ts
|
|
695
|
-
await
|
|
695
|
+
await sanka.sendMessage(
|
|
696
696
|
jid,
|
|
697
697
|
{
|
|
698
698
|
pollResult: {
|
|
@@ -714,7 +714,7 @@ await suki.sendMessage(
|
|
|
714
714
|
|
|
715
715
|
### Call Message
|
|
716
716
|
```ts
|
|
717
|
-
await
|
|
717
|
+
await sanka.sendMessage(
|
|
718
718
|
jid,
|
|
719
719
|
{
|
|
720
720
|
call: {
|
|
@@ -727,7 +727,7 @@ await suki.sendMessage(
|
|
|
727
727
|
|
|
728
728
|
### Event Message
|
|
729
729
|
```ts
|
|
730
|
-
await
|
|
730
|
+
await sanka.sendMessage(
|
|
731
731
|
jid,
|
|
732
732
|
{
|
|
733
733
|
event: {
|
|
@@ -749,7 +749,7 @@ await suki.sendMessage(
|
|
|
749
749
|
|
|
750
750
|
### Order Message
|
|
751
751
|
```ts
|
|
752
|
-
await
|
|
752
|
+
await sanka.sendMessage(
|
|
753
753
|
jid,
|
|
754
754
|
{
|
|
755
755
|
order: {
|
|
@@ -771,7 +771,7 @@ await suki.sendMessage(
|
|
|
771
771
|
|
|
772
772
|
### Product Message
|
|
773
773
|
```ts
|
|
774
|
-
await
|
|
774
|
+
await sanka.sendMessage(
|
|
775
775
|
jid,
|
|
776
776
|
{
|
|
777
777
|
product: {
|
|
@@ -797,7 +797,7 @@ await suki.sendMessage(
|
|
|
797
797
|
|
|
798
798
|
### Payment Message
|
|
799
799
|
```ts
|
|
800
|
-
await
|
|
800
|
+
await sanka.sendMessage(
|
|
801
801
|
jid,
|
|
802
802
|
{
|
|
803
803
|
payment: {
|
|
@@ -819,7 +819,7 @@ await suki.sendMessage(
|
|
|
819
819
|
|
|
820
820
|
#### Payment Invite Message
|
|
821
821
|
```ts
|
|
822
|
-
await
|
|
822
|
+
await sanka.sendMessage(
|
|
823
823
|
id,
|
|
824
824
|
{
|
|
825
825
|
paymentInvite: {
|
|
@@ -832,7 +832,7 @@ await suki.sendMessage(
|
|
|
832
832
|
|
|
833
833
|
### Admin Invite Message
|
|
834
834
|
```ts
|
|
835
|
-
await
|
|
835
|
+
await sanka.sendMessage(
|
|
836
836
|
jid,
|
|
837
837
|
{
|
|
838
838
|
adminInvite: {
|
|
@@ -848,7 +848,7 @@ await suki.sendMessage(
|
|
|
848
848
|
|
|
849
849
|
### Group Invite Message
|
|
850
850
|
```ts
|
|
851
|
-
await
|
|
851
|
+
await sanka.sendMessage(
|
|
852
852
|
jid,
|
|
853
853
|
{
|
|
854
854
|
groupInvite: {
|
|
@@ -865,7 +865,7 @@ await suki.sendMessage(
|
|
|
865
865
|
|
|
866
866
|
### Share Phone Number Message
|
|
867
867
|
```ts
|
|
868
|
-
await
|
|
868
|
+
await sanka.sendMessage(
|
|
869
869
|
jid,
|
|
870
870
|
{
|
|
871
871
|
sharePhoneNumber: {
|
|
@@ -876,7 +876,7 @@ await suki.sendMessage(
|
|
|
876
876
|
|
|
877
877
|
### Request Phone Number Message
|
|
878
878
|
```ts
|
|
879
|
-
await
|
|
879
|
+
await sanka.sendMessage(
|
|
880
880
|
jid,
|
|
881
881
|
{
|
|
882
882
|
requestPhoneNumber: {
|
|
@@ -888,7 +888,7 @@ await suki.sendMessage(
|
|
|
888
888
|
### Buttons Reply Message
|
|
889
889
|
```ts
|
|
890
890
|
// List
|
|
891
|
-
await
|
|
891
|
+
await sanka.sendMessage(
|
|
892
892
|
jid,
|
|
893
893
|
{
|
|
894
894
|
buttonReply: {
|
|
@@ -900,7 +900,7 @@ await suki.sendMessage(
|
|
|
900
900
|
}
|
|
901
901
|
)
|
|
902
902
|
// Plain
|
|
903
|
-
await
|
|
903
|
+
await sanka.sendMessage(
|
|
904
904
|
jid,
|
|
905
905
|
{
|
|
906
906
|
buttonReply: {
|
|
@@ -912,7 +912,7 @@ await suki.sendMessage(
|
|
|
912
912
|
)
|
|
913
913
|
|
|
914
914
|
// Template
|
|
915
|
-
await
|
|
915
|
+
await sanka.sendMessage(
|
|
916
916
|
jid,
|
|
917
917
|
{
|
|
918
918
|
buttonReply: {
|
|
@@ -925,7 +925,7 @@ await suki.sendMessage(
|
|
|
925
925
|
)
|
|
926
926
|
|
|
927
927
|
// Interactive
|
|
928
|
-
await
|
|
928
|
+
await sanka.sendMessage(
|
|
929
929
|
jid,
|
|
930
930
|
{
|
|
931
931
|
buttonReply: {
|
|
@@ -943,7 +943,7 @@ await suki.sendMessage(
|
|
|
943
943
|
|
|
944
944
|
### Buttons Message
|
|
945
945
|
```ts
|
|
946
|
-
await
|
|
946
|
+
await sanka.sendMessage(
|
|
947
947
|
jid,
|
|
948
948
|
{
|
|
949
949
|
text: 'This is a button message!', // image: buffer or // image: { url: url } If you want to use images
|
|
@@ -974,7 +974,7 @@ await suki.sendMessage(
|
|
|
974
974
|
### Buttons List Message
|
|
975
975
|
```ts
|
|
976
976
|
// Just working in a private chat
|
|
977
|
-
await
|
|
977
|
+
await sanka.sendMessage(
|
|
978
978
|
jid,
|
|
979
979
|
{
|
|
980
980
|
text: 'This is a list!',
|
|
@@ -1013,7 +1013,7 @@ await suki.sendMessage(
|
|
|
1013
1013
|
### Buttons Product List Message
|
|
1014
1014
|
```ts
|
|
1015
1015
|
// Just working in a private chat
|
|
1016
|
-
await
|
|
1016
|
+
await sanka.sendMessage(
|
|
1017
1017
|
jid,
|
|
1018
1018
|
{
|
|
1019
1019
|
text: 'This is a list!',
|
|
@@ -1039,7 +1039,7 @@ await suki.sendMessage(
|
|
|
1039
1039
|
|
|
1040
1040
|
### Buttons Cards Message
|
|
1041
1041
|
```ts
|
|
1042
|
-
await
|
|
1042
|
+
await sanka.sendMessage(
|
|
1043
1043
|
jid,
|
|
1044
1044
|
{
|
|
1045
1045
|
text: 'Body Message',
|
|
@@ -1098,7 +1098,7 @@ await suki.sendMessage(
|
|
|
1098
1098
|
|
|
1099
1099
|
### Buttons Template Message
|
|
1100
1100
|
```ts
|
|
1101
|
-
await
|
|
1101
|
+
await sanka.sendMessage(
|
|
1102
1102
|
jid,
|
|
1103
1103
|
{
|
|
1104
1104
|
text: 'This is a template message!',
|
|
@@ -1130,7 +1130,7 @@ await suki.sendMessage(
|
|
|
1130
1130
|
|
|
1131
1131
|
### Buttons Interactive Message
|
|
1132
1132
|
```ts
|
|
1133
|
-
await
|
|
1133
|
+
await sanka.sendMessage(
|
|
1134
1134
|
jid,
|
|
1135
1135
|
{
|
|
1136
1136
|
text: 'This is an Interactive message!',
|
|
@@ -1282,7 +1282,7 @@ await suki.sendMessage(
|
|
|
1282
1282
|
)
|
|
1283
1283
|
|
|
1284
1284
|
// If you want to use an image
|
|
1285
|
-
await
|
|
1285
|
+
await sanka.sendMessage(
|
|
1286
1286
|
jid,
|
|
1287
1287
|
{
|
|
1288
1288
|
image: {
|
|
@@ -1306,7 +1306,7 @@ await suki.sendMessage(
|
|
|
1306
1306
|
)
|
|
1307
1307
|
|
|
1308
1308
|
// If you want to use an video
|
|
1309
|
-
await
|
|
1309
|
+
await sanka.sendMessage(
|
|
1310
1310
|
jid,
|
|
1311
1311
|
{
|
|
1312
1312
|
video: {
|
|
@@ -1330,14 +1330,14 @@ await suki.sendMessage(
|
|
|
1330
1330
|
)
|
|
1331
1331
|
|
|
1332
1332
|
// If you want to use an document
|
|
1333
|
-
await
|
|
1333
|
+
await sanka.sendMessage(
|
|
1334
1334
|
jid,
|
|
1335
1335
|
{
|
|
1336
1336
|
document: {
|
|
1337
1337
|
url: 'https://example.jpg'
|
|
1338
1338
|
},
|
|
1339
1339
|
mimetype: 'image/jpeg',
|
|
1340
|
-
jpegThumbnail: await
|
|
1340
|
+
jpegThumbnail: await sanka.resize('https://example.jpg', 320, 320),
|
|
1341
1341
|
caption: 'Body',
|
|
1342
1342
|
title: 'Title',
|
|
1343
1343
|
subtitle: 'Subtitle',
|
|
@@ -1356,7 +1356,7 @@ await suki.sendMessage(
|
|
|
1356
1356
|
)
|
|
1357
1357
|
|
|
1358
1358
|
// If you want to use an location
|
|
1359
|
-
await
|
|
1359
|
+
await sanka.sendMessage(
|
|
1360
1360
|
jid,
|
|
1361
1361
|
{
|
|
1362
1362
|
location: {
|
|
@@ -1382,7 +1382,7 @@ await suki.sendMessage(
|
|
|
1382
1382
|
)
|
|
1383
1383
|
|
|
1384
1384
|
// if you want to use an product
|
|
1385
|
-
await
|
|
1385
|
+
await sanka.sendMessage(
|
|
1386
1386
|
jid,
|
|
1387
1387
|
{
|
|
1388
1388
|
product: {
|
|
@@ -1419,7 +1419,7 @@ await suki.sendMessage(
|
|
|
1419
1419
|
|
|
1420
1420
|
### Buttons Interactive Message PIX
|
|
1421
1421
|
```ts
|
|
1422
|
-
await
|
|
1422
|
+
await sanka.sendMessage(
|
|
1423
1423
|
jid,
|
|
1424
1424
|
{
|
|
1425
1425
|
text: '', // This string is required. Even it's empty.
|
|
@@ -1444,7 +1444,7 @@ await suki.sendMessage(
|
|
|
1444
1444
|
|
|
1445
1445
|
### Buttons Interactive Message PAY
|
|
1446
1446
|
```ts
|
|
1447
|
-
await
|
|
1447
|
+
await sanka.sendMessage(
|
|
1448
1448
|
jid,
|
|
1449
1449
|
{
|
|
1450
1450
|
text: '', // This string is required. Even it's empty.
|
|
@@ -1494,7 +1494,7 @@ await suki.sendMessage(
|
|
|
1494
1494
|
|
|
1495
1495
|
### Status Mentions Message
|
|
1496
1496
|
```ts
|
|
1497
|
-
await
|
|
1497
|
+
await sanka.sendStatusMentions(
|
|
1498
1498
|
jid,
|
|
1499
1499
|
{
|
|
1500
1500
|
image: {
|
|
@@ -1507,7 +1507,7 @@ await suki.sendStatusMentions(
|
|
|
1507
1507
|
|
|
1508
1508
|
### Send Album Message
|
|
1509
1509
|
```ts
|
|
1510
|
-
await
|
|
1510
|
+
await sanka.sendAlbumMessage(
|
|
1511
1511
|
jid,
|
|
1512
1512
|
[
|
|
1513
1513
|
{
|
|
@@ -1535,7 +1535,7 @@ await suki.sendAlbumMessage(
|
|
|
1535
1535
|
```
|
|
1536
1536
|
### Shop Message
|
|
1537
1537
|
```ts
|
|
1538
|
-
await
|
|
1538
|
+
await sanka.sendMessage(
|
|
1539
1539
|
jid,
|
|
1540
1540
|
{
|
|
1541
1541
|
text: 'Body',
|
|
@@ -1551,7 +1551,7 @@ await suki.sendMessage(
|
|
|
1551
1551
|
)
|
|
1552
1552
|
|
|
1553
1553
|
// Image
|
|
1554
|
-
await
|
|
1554
|
+
await sanka.sendMessage(
|
|
1555
1555
|
jid,
|
|
1556
1556
|
{
|
|
1557
1557
|
image: {
|
|
@@ -1571,7 +1571,7 @@ await suki.sendMessage(
|
|
|
1571
1571
|
)
|
|
1572
1572
|
|
|
1573
1573
|
// Video
|
|
1574
|
-
await
|
|
1574
|
+
await sanka.sendMessage(
|
|
1575
1575
|
jid,
|
|
1576
1576
|
{
|
|
1577
1577
|
video: {
|
|
@@ -1591,14 +1591,14 @@ await suki.sendMessage(
|
|
|
1591
1591
|
)
|
|
1592
1592
|
|
|
1593
1593
|
// Document
|
|
1594
|
-
await
|
|
1594
|
+
await sanka.sendMessage(
|
|
1595
1595
|
jid,
|
|
1596
1596
|
{
|
|
1597
1597
|
document: {
|
|
1598
1598
|
url: 'https://example.jpg'
|
|
1599
1599
|
},
|
|
1600
1600
|
mimetype: 'image/jpeg',
|
|
1601
|
-
jpegThumbnail: await
|
|
1601
|
+
jpegThumbnail: await sanka.resize('https://example.jpg', 320, 320),
|
|
1602
1602
|
caption: 'Body',
|
|
1603
1603
|
title: 'Title',
|
|
1604
1604
|
subtitle: 'Subtitle',
|
|
@@ -1613,7 +1613,7 @@ await suki.sendMessage(
|
|
|
1613
1613
|
)
|
|
1614
1614
|
|
|
1615
1615
|
// Location
|
|
1616
|
-
await
|
|
1616
|
+
await sanka.sendMessage(
|
|
1617
1617
|
jid,
|
|
1618
1618
|
{
|
|
1619
1619
|
location: {
|
|
@@ -1635,7 +1635,7 @@ await suki.sendMessage(
|
|
|
1635
1635
|
)
|
|
1636
1636
|
|
|
1637
1637
|
// Product
|
|
1638
|
-
await
|
|
1638
|
+
await sanka.sendMessage(
|
|
1639
1639
|
jid,
|
|
1640
1640
|
{
|
|
1641
1641
|
product: {
|
|
@@ -1667,7 +1667,7 @@ await suki.sendMessage(
|
|
|
1667
1667
|
```
|
|
1668
1668
|
### Collection Message
|
|
1669
1669
|
```ts
|
|
1670
|
-
await
|
|
1670
|
+
await sanka.sendMessage(
|
|
1671
1671
|
jid,
|
|
1672
1672
|
{
|
|
1673
1673
|
text: 'Body',
|
|
@@ -1684,7 +1684,7 @@ await suki.sendMessage(
|
|
|
1684
1684
|
)
|
|
1685
1685
|
|
|
1686
1686
|
// Image
|
|
1687
|
-
await
|
|
1687
|
+
await sanka.sendMessage(
|
|
1688
1688
|
jid,
|
|
1689
1689
|
{
|
|
1690
1690
|
image: {
|
|
@@ -1705,7 +1705,7 @@ await suki.sendMessage(
|
|
|
1705
1705
|
)
|
|
1706
1706
|
|
|
1707
1707
|
// Video
|
|
1708
|
-
await
|
|
1708
|
+
await sanka.sendMessage(
|
|
1709
1709
|
jid,
|
|
1710
1710
|
{
|
|
1711
1711
|
video: {
|
|
@@ -1726,14 +1726,14 @@ await suki.sendMessage(
|
|
|
1726
1726
|
)
|
|
1727
1727
|
|
|
1728
1728
|
// Document
|
|
1729
|
-
await
|
|
1729
|
+
await sanka.sendMessage(
|
|
1730
1730
|
jid,
|
|
1731
1731
|
{
|
|
1732
1732
|
document: {
|
|
1733
1733
|
url: 'https://example.jpg'
|
|
1734
1734
|
},
|
|
1735
1735
|
mimetype: 'image/jpeg',
|
|
1736
|
-
jpegThumbnail: await
|
|
1736
|
+
jpegThumbnail: await sanka.resize('https://example.jpg', 320, 320),
|
|
1737
1737
|
caption: 'Body',
|
|
1738
1738
|
title: 'Title',
|
|
1739
1739
|
subtitle: 'Subtitle',
|
|
@@ -1749,7 +1749,7 @@ await suki.sendMessage(
|
|
|
1749
1749
|
)
|
|
1750
1750
|
|
|
1751
1751
|
// Location
|
|
1752
|
-
await
|
|
1752
|
+
await sanka.sendMessage(
|
|
1753
1753
|
jid,
|
|
1754
1754
|
{
|
|
1755
1755
|
location: {
|
|
@@ -1772,7 +1772,7 @@ await suki.sendMessage(
|
|
|
1772
1772
|
)
|
|
1773
1773
|
|
|
1774
1774
|
// Product
|
|
1775
|
-
await
|
|
1775
|
+
await sanka.sendMessage(
|
|
1776
1776
|
jid,
|
|
1777
1777
|
{
|
|
1778
1778
|
product: {
|
|
@@ -1811,7 +1811,7 @@ await suki.sendMessage(
|
|
|
1811
1811
|
3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
|
|
1812
1812
|
4. Send a link:
|
|
1813
1813
|
```ts
|
|
1814
|
-
await
|
|
1814
|
+
await sanka.sendMessage(
|
|
1815
1815
|
jid,
|
|
1816
1816
|
{
|
|
1817
1817
|
text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
|
|
@@ -1834,7 +1834,7 @@ Sending media (video, stickers, images) is easier & more efficient than ever.
|
|
|
1834
1834
|
#### Gif Message
|
|
1835
1835
|
- Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
|
|
1836
1836
|
```ts
|
|
1837
|
-
await
|
|
1837
|
+
await sanka.sendMessage(
|
|
1838
1838
|
jid,
|
|
1839
1839
|
{
|
|
1840
1840
|
video: fs.readFileSync('Media/ma_gif.mp4'),
|
|
@@ -1846,7 +1846,7 @@ await suki.sendMessage(
|
|
|
1846
1846
|
|
|
1847
1847
|
#### Video Message
|
|
1848
1848
|
```ts
|
|
1849
|
-
await
|
|
1849
|
+
await sanka.sendMessage(
|
|
1850
1850
|
id,
|
|
1851
1851
|
{
|
|
1852
1852
|
video: {
|
|
@@ -1859,7 +1859,7 @@ await suki.sendMessage(
|
|
|
1859
1859
|
|
|
1860
1860
|
#### Video Ptv Message
|
|
1861
1861
|
```ts
|
|
1862
|
-
await
|
|
1862
|
+
await sanka.sendMessage(
|
|
1863
1863
|
id,
|
|
1864
1864
|
{
|
|
1865
1865
|
video: {
|
|
@@ -1883,7 +1883,7 @@ await suki.sendMessage(
|
|
|
1883
1883
|
ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
|
|
1884
1884
|
```
|
|
1885
1885
|
```ts
|
|
1886
|
-
await
|
|
1886
|
+
await sanka.sendMessage(
|
|
1887
1887
|
jid,
|
|
1888
1888
|
{
|
|
1889
1889
|
audio: {
|
|
@@ -1896,7 +1896,7 @@ await suki.sendMessage(
|
|
|
1896
1896
|
|
|
1897
1897
|
#### Image Message
|
|
1898
1898
|
```ts
|
|
1899
|
-
await
|
|
1899
|
+
await sanka.sendMessage(
|
|
1900
1900
|
id,
|
|
1901
1901
|
{
|
|
1902
1902
|
image: {
|
|
@@ -1912,7 +1912,7 @@ await suki.sendMessage(
|
|
|
1912
1912
|
- You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
|
|
1913
1913
|
|
|
1914
1914
|
```ts
|
|
1915
|
-
await
|
|
1915
|
+
await sanka.sendMessage(
|
|
1916
1916
|
id,
|
|
1917
1917
|
{
|
|
1918
1918
|
image: {
|
|
@@ -1929,8 +1929,8 @@ await suki.sendMessage(
|
|
|
1929
1929
|
### Deleting Messages (for everyone)
|
|
1930
1930
|
|
|
1931
1931
|
```ts
|
|
1932
|
-
const msg = await
|
|
1933
|
-
await
|
|
1932
|
+
const msg = await sanka.sendMessage(jid, { text: 'hello word' })
|
|
1933
|
+
await sanka.sendMessage(jid, { delete: msg.key })
|
|
1934
1934
|
```
|
|
1935
1935
|
|
|
1936
1936
|
**Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
|
|
@@ -1939,7 +1939,7 @@ await suki.sendMessage(jid, { delete: msg.key })
|
|
|
1939
1939
|
|
|
1940
1940
|
- You can pass all editable contents here
|
|
1941
1941
|
```ts
|
|
1942
|
-
await
|
|
1942
|
+
await sanka.sendMessage(jid, {
|
|
1943
1943
|
text: 'updated text goes here',
|
|
1944
1944
|
edit: response.key,
|
|
1945
1945
|
})
|
|
@@ -1958,7 +1958,7 @@ If you want to save the media you received
|
|
|
1958
1958
|
import { createWriteStream } from 'fs'
|
|
1959
1959
|
import { downloadMediaMessage, getContentType } from '@SankaVollereii/Sanka-Bail'
|
|
1960
1960
|
|
|
1961
|
-
|
|
1961
|
+
sanka.ev.on('messages.upsert', async ({ [m] }) => {
|
|
1962
1962
|
if (!m.message) return // if there is no text or media message
|
|
1963
1963
|
const messageType = getContentType(m) // get what type of message it is (text, image, video...)
|
|
1964
1964
|
|
|
@@ -1973,7 +1973,7 @@ suki.ev.on('messages.upsert', async ({ [m] }) => {
|
|
|
1973
1973
|
logger,
|
|
1974
1974
|
// pass this so that baileys can request a reupload of media
|
|
1975
1975
|
// that has been deleted
|
|
1976
|
-
reuploadRequest:
|
|
1976
|
+
reuploadRequest: sanka.updateMediaMessage
|
|
1977
1977
|
}
|
|
1978
1978
|
)
|
|
1979
1979
|
// save to file
|
|
@@ -1987,7 +1987,7 @@ suki.ev.on('messages.upsert', async ({ [m] }) => {
|
|
|
1987
1987
|
|
|
1988
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:
|
|
1989
1989
|
```ts
|
|
1990
|
-
await
|
|
1990
|
+
await sanka.updateMediaMessage(msg)
|
|
1991
1991
|
```
|
|
1992
1992
|
|
|
1993
1993
|
## Reject Call
|
|
@@ -1995,7 +1995,7 @@ await suki.updateMediaMessage(msg)
|
|
|
1995
1995
|
- You can obtain `callId` and `callFrom` from `call` event
|
|
1996
1996
|
|
|
1997
1997
|
```ts
|
|
1998
|
-
await
|
|
1998
|
+
await sanka.rejectCall(callId, callFrom)
|
|
1999
1999
|
```
|
|
2000
2000
|
|
|
2001
2001
|
## Send States in Chat
|
|
@@ -2008,7 +2008,7 @@ This means you have to keep track of unread messages.
|
|
|
2008
2008
|
```ts
|
|
2009
2009
|
const key: WAMessageKey
|
|
2010
2010
|
// can pass multiple keys to read multiple messages as well
|
|
2011
|
-
await
|
|
2011
|
+
await sanka.readMessages([key])
|
|
2012
2012
|
```
|
|
2013
2013
|
|
|
2014
2014
|
The message ID is the unique identifier of the message that you are marking as read.
|
|
@@ -2021,11 +2021,11 @@ On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.k
|
|
|
2021
2021
|
- This lets the person/group with `jid` know whether you're online, offline, typing etc.
|
|
2022
2022
|
|
|
2023
2023
|
```ts
|
|
2024
|
-
await
|
|
2024
|
+
await sanka.sendPresenceUpdate('available', jid)
|
|
2025
2025
|
```
|
|
2026
2026
|
|
|
2027
2027
|
> [!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 `
|
|
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 `sanka.sendPresenceUpdate('unavailable')`
|
|
2029
2029
|
|
|
2030
2030
|
## Modifying Chats
|
|
2031
2031
|
|
|
@@ -2037,7 +2037,7 @@ WA uses an encrypted form of communication to send chat/app updates. This has be
|
|
|
2037
2037
|
### Archive a Chat
|
|
2038
2038
|
```ts
|
|
2039
2039
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
2040
|
-
await
|
|
2040
|
+
await sanka.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
2041
2041
|
```
|
|
2042
2042
|
### Mute/Unmute a Chat
|
|
2043
2043
|
|
|
@@ -2051,20 +2051,20 @@ await suki.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
|
2051
2051
|
|
|
2052
2052
|
```ts
|
|
2053
2053
|
// mute for 8 hours
|
|
2054
|
-
await
|
|
2054
|
+
await sanka.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
|
|
2055
2055
|
// unmute
|
|
2056
|
-
await
|
|
2056
|
+
await sanka.chatModify({ mute: null }, jid)
|
|
2057
2057
|
```
|
|
2058
2058
|
### Mark a Chat Read/Unread
|
|
2059
2059
|
```ts
|
|
2060
2060
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
2061
2061
|
// mark it unread
|
|
2062
|
-
await
|
|
2062
|
+
await sanka.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
|
|
2063
2063
|
```
|
|
2064
2064
|
|
|
2065
2065
|
### Delete a Message for Me
|
|
2066
2066
|
```ts
|
|
2067
|
-
await
|
|
2067
|
+
await sanka.chatModify(
|
|
2068
2068
|
{
|
|
2069
2069
|
clear: {
|
|
2070
2070
|
messages: [
|
|
@@ -2083,7 +2083,7 @@ await suki.chatModify(
|
|
|
2083
2083
|
### Delete a Chat
|
|
2084
2084
|
```ts
|
|
2085
2085
|
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
2086
|
-
await
|
|
2086
|
+
await sanka.chatModify({
|
|
2087
2087
|
delete: true,
|
|
2088
2088
|
lastMessages: [
|
|
2089
2089
|
{
|
|
@@ -2097,7 +2097,7 @@ await suki.chatModify({
|
|
|
2097
2097
|
```
|
|
2098
2098
|
### Pin/Unpin a Chat
|
|
2099
2099
|
```ts
|
|
2100
|
-
await
|
|
2100
|
+
await sanka.chatModify({
|
|
2101
2101
|
pin: true // or `false` to unpin
|
|
2102
2102
|
},
|
|
2103
2103
|
jid
|
|
@@ -2105,7 +2105,7 @@ await suki.chatModify({
|
|
|
2105
2105
|
```
|
|
2106
2106
|
### Star/Unstar a Message
|
|
2107
2107
|
```ts
|
|
2108
|
-
await
|
|
2108
|
+
await sanka.chatModify({
|
|
2109
2109
|
star: {
|
|
2110
2110
|
messages: [
|
|
2111
2111
|
{
|
|
@@ -2135,17 +2135,17 @@ await suki.chatModify({
|
|
|
2135
2135
|
|
|
2136
2136
|
```ts
|
|
2137
2137
|
// turn on disappearing messages
|
|
2138
|
-
await
|
|
2138
|
+
await sanka.sendMessage(
|
|
2139
2139
|
jid,
|
|
2140
2140
|
// this is 1 week in seconds -- how long you want messages to appear for
|
|
2141
2141
|
{ disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
|
|
2142
2142
|
)
|
|
2143
2143
|
|
|
2144
2144
|
// will send as a disappearing message
|
|
2145
|
-
await
|
|
2145
|
+
await sanka.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
|
|
2146
2146
|
|
|
2147
2147
|
// turn off disappearing messages
|
|
2148
|
-
await
|
|
2148
|
+
await sanka.sendMessage(
|
|
2149
2149
|
jid,
|
|
2150
2150
|
{ disappearingMessagesInChat: false }
|
|
2151
2151
|
)
|
|
@@ -2153,14 +2153,14 @@ await suki.sendMessage(
|
|
|
2153
2153
|
|
|
2154
2154
|
### Clear Messages
|
|
2155
2155
|
```ts
|
|
2156
|
-
await
|
|
2156
|
+
await sanka.clearMessage(jid, key, timestamps)
|
|
2157
2157
|
```
|
|
2158
2158
|
|
|
2159
2159
|
## User Querys
|
|
2160
2160
|
|
|
2161
2161
|
### Check If ID Exists in Whatsapp
|
|
2162
2162
|
```ts
|
|
2163
|
-
const [result] = await
|
|
2163
|
+
const [result] = await sanka.onWhatsApp(jid)
|
|
2164
2164
|
if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
|
|
2165
2165
|
```
|
|
2166
2166
|
|
|
@@ -2169,7 +2169,7 @@ if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid
|
|
|
2169
2169
|
- You need to have oldest message in chat
|
|
2170
2170
|
```ts
|
|
2171
2171
|
const msg = await getOldestMessageInChat(jid)
|
|
2172
|
-
await
|
|
2172
|
+
await sanka.fetchMessageHistory(
|
|
2173
2173
|
50, //quantity (max: 50 per query)
|
|
2174
2174
|
msg.key,
|
|
2175
2175
|
msg.messageTimestamp
|
|
@@ -2179,7 +2179,7 @@ await suki.fetchMessageHistory(
|
|
|
2179
2179
|
|
|
2180
2180
|
### Fetch Status
|
|
2181
2181
|
```ts
|
|
2182
|
-
const status = await
|
|
2182
|
+
const status = await sanka.fetchStatus(jid)
|
|
2183
2183
|
console.log('status: ' + status)
|
|
2184
2184
|
```
|
|
2185
2185
|
|
|
@@ -2187,34 +2187,34 @@ console.log('status: ' + status)
|
|
|
2187
2187
|
- To get the display picture of some person, group and channel
|
|
2188
2188
|
```ts
|
|
2189
2189
|
// for low res picture
|
|
2190
|
-
const ppUrl = await
|
|
2190
|
+
const ppUrl = await sanka.profilePictureUrl(jid)
|
|
2191
2191
|
console.log(ppUrl)
|
|
2192
2192
|
```
|
|
2193
2193
|
|
|
2194
2194
|
### Fetch Bussines Profile (such as description or category)
|
|
2195
2195
|
```ts
|
|
2196
|
-
const profile = await
|
|
2196
|
+
const profile = await sanka.getBusinessProfile(jid)
|
|
2197
2197
|
console.log('business description: ' + profile.description + ', category: ' + profile.category)
|
|
2198
2198
|
```
|
|
2199
2199
|
|
|
2200
2200
|
### Fetch Someone's Presence (if they're typing or online)
|
|
2201
2201
|
```ts
|
|
2202
2202
|
// the presence update is fetched and called here
|
|
2203
|
-
|
|
2203
|
+
sanka.ev.on('presence.update', console.log)
|
|
2204
2204
|
|
|
2205
2205
|
// request updates for a chat
|
|
2206
|
-
await
|
|
2206
|
+
await sanka.presenceSubscribe(jid)
|
|
2207
2207
|
```
|
|
2208
2208
|
|
|
2209
2209
|
## Change Profile
|
|
2210
2210
|
|
|
2211
2211
|
### Change Profile Status
|
|
2212
2212
|
```ts
|
|
2213
|
-
await
|
|
2213
|
+
await sanka.updateProfileStatus('Hello World!')
|
|
2214
2214
|
```
|
|
2215
2215
|
### Change Profile Name
|
|
2216
2216
|
```ts
|
|
2217
|
-
await
|
|
2217
|
+
await sanka.updateProfileName('My name')
|
|
2218
2218
|
```
|
|
2219
2219
|
### Change Display Picture (groups too)
|
|
2220
2220
|
- To change your display picture or a group's
|
|
@@ -2223,11 +2223,11 @@ await suki.updateProfileName('My name')
|
|
|
2223
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)
|
|
2224
2224
|
|
|
2225
2225
|
```ts
|
|
2226
|
-
await
|
|
2226
|
+
await sanka.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
|
|
2227
2227
|
```
|
|
2228
2228
|
### Remove display picture (groups too)
|
|
2229
2229
|
```ts
|
|
2230
|
-
await
|
|
2230
|
+
await sanka.removeProfilePicture(jid)
|
|
2231
2231
|
```
|
|
2232
2232
|
|
|
2233
2233
|
## Groups
|
|
@@ -2237,14 +2237,14 @@ await suki.removeProfilePicture(jid)
|
|
|
2237
2237
|
### Create a Group
|
|
2238
2238
|
```ts
|
|
2239
2239
|
// title & participants
|
|
2240
|
-
const group = await
|
|
2240
|
+
const group = await sanka.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
|
|
2241
2241
|
console.log('created group with id: ' + group.gid)
|
|
2242
|
-
await
|
|
2242
|
+
await sanka.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
|
|
2243
2243
|
```
|
|
2244
2244
|
### Add/Remove or Demote/Promote
|
|
2245
2245
|
```ts
|
|
2246
2246
|
// id & people to add to the group (will throw error if it fails)
|
|
2247
|
-
await
|
|
2247
|
+
await sanka.groupParticipantsUpdate(
|
|
2248
2248
|
jid,
|
|
2249
2249
|
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
2250
2250
|
'add' // replace this parameter with 'remove' or 'demote' or 'promote'
|
|
@@ -2252,68 +2252,68 @@ await suki.groupParticipantsUpdate(
|
|
|
2252
2252
|
```
|
|
2253
2253
|
### Change Subject (name)
|
|
2254
2254
|
```ts
|
|
2255
|
-
await
|
|
2255
|
+
await sanka.groupUpdateSubject(jid, 'New Subject!')
|
|
2256
2256
|
```
|
|
2257
2257
|
### Change Description
|
|
2258
2258
|
```ts
|
|
2259
|
-
await
|
|
2259
|
+
await sanka.groupUpdateDescription(jid, 'New Description!')
|
|
2260
2260
|
```
|
|
2261
2261
|
### Change Settings
|
|
2262
2262
|
```ts
|
|
2263
2263
|
// only allow admins to send messages
|
|
2264
|
-
await
|
|
2264
|
+
await sanka.groupSettingUpdate(jid, 'announcement')
|
|
2265
2265
|
// allow everyone to send messages
|
|
2266
|
-
await
|
|
2266
|
+
await sanka.groupSettingUpdate(jid, 'not_announcement')
|
|
2267
2267
|
// allow everyone to modify the group's settings -- like display picture etc.
|
|
2268
|
-
await
|
|
2268
|
+
await sanka.groupSettingUpdate(jid, 'unlocked')
|
|
2269
2269
|
// only allow admins to modify the group's settings
|
|
2270
|
-
await
|
|
2270
|
+
await sanka.groupSettingUpdate(jid, 'locked')
|
|
2271
2271
|
```
|
|
2272
2272
|
### Leave a Group
|
|
2273
2273
|
```ts
|
|
2274
2274
|
// will throw error if it fails
|
|
2275
|
-
await
|
|
2275
|
+
await sanka.groupLeave(jid)
|
|
2276
2276
|
```
|
|
2277
2277
|
### Get Invite Code
|
|
2278
2278
|
- To create link with code use `'https://chat.whatsapp.com/' + code`
|
|
2279
2279
|
```ts
|
|
2280
|
-
const code = await
|
|
2280
|
+
const code = await sanka.groupInviteCode(jid)
|
|
2281
2281
|
console.log('group code: ' + code)
|
|
2282
2282
|
```
|
|
2283
2283
|
### Revoke Invite Code
|
|
2284
2284
|
```ts
|
|
2285
|
-
const code = await
|
|
2285
|
+
const code = await sanka.groupRevokeInvite(jid)
|
|
2286
2286
|
console.log('New group code: ' + code)
|
|
2287
2287
|
```
|
|
2288
2288
|
### Join Using Invitation Code
|
|
2289
2289
|
- Code can't have `https://chat.whatsapp.com/`, only code
|
|
2290
2290
|
```ts
|
|
2291
|
-
const response = await
|
|
2291
|
+
const response = await sanka.groupAcceptInvite(code)
|
|
2292
2292
|
console.log('joined to: ' + response)
|
|
2293
2293
|
```
|
|
2294
2294
|
### Get Group Info by Invite Code
|
|
2295
2295
|
```ts
|
|
2296
|
-
const response = await
|
|
2296
|
+
const response = await sanka.groupGetInviteInfo(code)
|
|
2297
2297
|
console.log('group information: ' + response)
|
|
2298
2298
|
```
|
|
2299
2299
|
### Query Metadata (participants, name, description...)
|
|
2300
2300
|
```ts
|
|
2301
|
-
const metadata = await
|
|
2301
|
+
const metadata = await sanka.groupMetadata(jid)
|
|
2302
2302
|
console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
|
|
2303
2303
|
```
|
|
2304
2304
|
### Join using `groupInviteMessage`
|
|
2305
2305
|
```ts
|
|
2306
|
-
const response = await
|
|
2306
|
+
const response = await sanka.groupAcceptInviteV4(jid, groupInviteMessage)
|
|
2307
2307
|
console.log('joined to: ' + response)
|
|
2308
2308
|
```
|
|
2309
2309
|
### Get Request Join List
|
|
2310
2310
|
```ts
|
|
2311
|
-
const response = await
|
|
2311
|
+
const response = await sanka.groupRequestParticipantsList(jid)
|
|
2312
2312
|
console.log(response)
|
|
2313
2313
|
```
|
|
2314
2314
|
### Approve/Reject Request Join
|
|
2315
2315
|
```ts
|
|
2316
|
-
const response = await
|
|
2316
|
+
const response = await sanka.groupRequestParticipantsUpdate(
|
|
2317
2317
|
jid, // group id
|
|
2318
2318
|
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
2319
2319
|
'approve' // or 'reject'
|
|
@@ -2322,7 +2322,7 @@ console.log(response)
|
|
|
2322
2322
|
```
|
|
2323
2323
|
### Get All Participating Groups Metadata
|
|
2324
2324
|
```ts
|
|
2325
|
-
const response = await
|
|
2325
|
+
const response = await sanka.groupFetchAllParticipating()
|
|
2326
2326
|
console.log(response)
|
|
2327
2327
|
```
|
|
2328
2328
|
### Toggle Ephemeral
|
|
@@ -2337,12 +2337,12 @@ console.log(response)
|
|
|
2337
2337
|
| 90d | 7.776.000 |
|
|
2338
2338
|
|
|
2339
2339
|
```ts
|
|
2340
|
-
await
|
|
2340
|
+
await sanka.groupToggleEphemeral(jid, 86400)
|
|
2341
2341
|
```
|
|
2342
2342
|
|
|
2343
2343
|
### Change Add Mode
|
|
2344
2344
|
```ts
|
|
2345
|
-
await
|
|
2345
|
+
await sanka.groupMemberAddMode(
|
|
2346
2346
|
jid,
|
|
2347
2347
|
'all_member_add' // or 'admin_add'
|
|
2348
2348
|
)
|
|
@@ -2352,48 +2352,48 @@ await suki.groupMemberAddMode(
|
|
|
2352
2352
|
|
|
2353
2353
|
### Block/Unblock User
|
|
2354
2354
|
```ts
|
|
2355
|
-
await
|
|
2356
|
-
await
|
|
2355
|
+
await sanka.updateBlockStatus(jid, 'block') // Block user
|
|
2356
|
+
await sanka.updateBlockStatus(jid, 'unblock') // Unblock user
|
|
2357
2357
|
```
|
|
2358
2358
|
### Get Privacy Settings
|
|
2359
2359
|
```ts
|
|
2360
|
-
const privacySettings = await
|
|
2360
|
+
const privacySettings = await sanka.fetchPrivacySettings(true)
|
|
2361
2361
|
console.log('privacy settings: ' + privacySettings)
|
|
2362
2362
|
```
|
|
2363
2363
|
### Get BlockList
|
|
2364
2364
|
```ts
|
|
2365
|
-
const response = await
|
|
2365
|
+
const response = await sanka.fetchBlocklist()
|
|
2366
2366
|
console.log(response)
|
|
2367
2367
|
```
|
|
2368
2368
|
### Update LastSeen Privacy
|
|
2369
2369
|
```ts
|
|
2370
2370
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
2371
|
-
await
|
|
2371
|
+
await sanka.updateLastSeenPrivacy(value)
|
|
2372
2372
|
```
|
|
2373
2373
|
### Update Online Privacy
|
|
2374
2374
|
```ts
|
|
2375
2375
|
const value = 'all' // 'match_last_seen'
|
|
2376
|
-
await
|
|
2376
|
+
await sanka.updateOnlinePrivacy(value)
|
|
2377
2377
|
```
|
|
2378
2378
|
### Update Profile Picture Privacy
|
|
2379
2379
|
```ts
|
|
2380
2380
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
2381
|
-
await
|
|
2381
|
+
await sanka.updateProfilePicturePrivacy(value)
|
|
2382
2382
|
```
|
|
2383
2383
|
### Update Status Privacy
|
|
2384
2384
|
```ts
|
|
2385
2385
|
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
2386
|
-
await
|
|
2386
|
+
await sanka.updateStatusPrivacy(value)
|
|
2387
2387
|
```
|
|
2388
2388
|
### Update Read Receipts Privacy
|
|
2389
2389
|
```ts
|
|
2390
2390
|
const value = 'all' // 'none'
|
|
2391
|
-
await
|
|
2391
|
+
await sanka.updateReadReceiptsPrivacy(value)
|
|
2392
2392
|
```
|
|
2393
2393
|
### Update Groups Add Privacy
|
|
2394
2394
|
```ts
|
|
2395
2395
|
const value = 'all' // 'contacts' | 'contact_blacklist'
|
|
2396
|
-
await
|
|
2396
|
+
await sanka.updateGroupsAddPrivacy(value)
|
|
2397
2397
|
```
|
|
2398
2398
|
### Update Default Disappearing Mode
|
|
2399
2399
|
|
|
@@ -2408,7 +2408,7 @@ await suki.updateGroupsAddPrivacy(value)
|
|
|
2408
2408
|
|
|
2409
2409
|
```ts
|
|
2410
2410
|
const ephemeral = 86400
|
|
2411
|
-
await
|
|
2411
|
+
await sanka.updateDefaultDisappearingMode(ephemeral)
|
|
2412
2412
|
```
|
|
2413
2413
|
|
|
2414
2414
|
## Broadcast Lists & Stories
|
|
@@ -2416,7 +2416,7 @@ await suki.updateDefaultDisappearingMode(ephemeral)
|
|
|
2416
2416
|
### Send Broadcast & Stories
|
|
2417
2417
|
- Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
|
|
2418
2418
|
```ts
|
|
2419
|
-
await
|
|
2419
|
+
await sanka.sendMessage(
|
|
2420
2420
|
jid,
|
|
2421
2421
|
{
|
|
2422
2422
|
image: {
|
|
@@ -2442,7 +2442,7 @@ await suki.sendMessage(
|
|
|
2442
2442
|
- Broadcast IDs are in the format `12345678@broadcast`
|
|
2443
2443
|
### Query a Broadcast List's Recipients & Name
|
|
2444
2444
|
```ts
|
|
2445
|
-
const bList = await
|
|
2445
|
+
const bList = await sanka.getBroadcastListInfo('1234@broadcast')
|
|
2446
2446
|
console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
|
|
2447
2447
|
```
|
|
2448
2448
|
|
|
@@ -2452,7 +2452,7 @@ Baileys is written with custom functionality in mind. Instead of forking the pro
|
|
|
2452
2452
|
### Enabling Debug Level in Baileys Logs
|
|
2453
2453
|
First, enable the logging of unhandled messages from WhatsApp by setting:
|
|
2454
2454
|
```ts
|
|
2455
|
-
const
|
|
2455
|
+
const sanka = makeWASocket({
|
|
2456
2456
|
logger: P({ level: 'debug' }),
|
|
2457
2457
|
})
|
|
2458
2458
|
```
|
|
@@ -2507,13 +2507,13 @@ The `'frame'` is what the message received is, it has three components:
|
|
|
2507
2507
|
|
|
2508
2508
|
```ts
|
|
2509
2509
|
// for any message with tag 'edge_routing'
|
|
2510
|
-
|
|
2510
|
+
sanka.ws.on('CB:edge_routing', (node: BinaryNode) => { })
|
|
2511
2511
|
|
|
2512
2512
|
// for any message with tag 'edge_routing' and id attribute = abcd
|
|
2513
|
-
|
|
2513
|
+
sanka.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
|
|
2514
2514
|
|
|
2515
2515
|
// for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
|
|
2516
|
-
|
|
2516
|
+
sanka.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
|
|
2517
2517
|
```
|
|
2518
2518
|
|
|
2519
2519
|
> [!NOTE]
|