@systemzero/baileys 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,1020 @@
1
+ <div align="center">
2
+
3
+ <img src="https://files.catbox.moe/w1m2q4.jpg" width="120" style="border-radius:16px" />
4
+
5
+ # @systemzero/baileys
6
+
7
+ **v1.0.5** · Fork avançado do Baileys com suporte nativo a todos os tipos de mensagens do WhatsApp
8
+
9
+ [![NPM](https://img.shields.io/npm/v/@systemzero/baileys?color=7c3aed&style=flat-square&label=npm)](https://www.npmjs.com/package/@systemzero/baileys)
10
+ [![License](https://img.shields.io/badge/license-MIT-6366f1?style=flat-square)](LICENSE)
11
+ [![Author](https://img.shields.io/badge/by-Josué%20%3C%2F%3E-ec4899?style=flat-square)](https://t.me/blackhzx)
12
+
13
+ </div>
14
+
15
+ ---
16
+
17
+ ## Instalação
18
+
19
+ ```bash
20
+ npm i @systemzero/baileys
21
+ ```
22
+
23
+ Dependências opcionais para sticker pack e thumbnail:
24
+ ```bash
25
+ npm i sharp
26
+ # ou
27
+ npm i @napi-rs/image
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Índice
33
+
34
+ 1. [Conexão](#1-conexão)
35
+ 2. [Mensagens de mídia](#2-mensagens-de-mídia)
36
+ 3. [Mensagens especiais](#3-mensagens-especiais)
37
+ 4. [Botões e interativos](#4-botões-e-interativos)
38
+ 5. [Sticker Pack nativo](#5-sticker-pack-nativo)
39
+ 6. [Canais Newsletter](#6-canais-newsletter)
40
+ 7. [Enquetes com decrypt](#7-enquetes-com-decrypt)
41
+ 8. [AI Rich](#8-ai-rich)
42
+ 9. [Grupos](#9-grupos)
43
+ 10. [Perfil e privacidade](#10-perfil-e-privacidade)
44
+ 11. [Eventos do socket](#11-eventos-do-socket)
45
+ 12. [Utilitários](#12-utilitários)
46
+
47
+ ---
48
+
49
+ ## 1. Conexão
50
+
51
+ ### Setup básico
52
+
53
+ ```js
54
+ const {
55
+ default: makeWASocket,
56
+ useMultiFileAuthState,
57
+ DisconnectReason,
58
+ Browsers,
59
+ fetchLatestWaWebVersion
60
+ } = require('@systemzero/baileys')
61
+
62
+ const { state, saveCreds } = await useMultiFileAuthState('./session')
63
+ const { version } = await fetchLatestWaWebVersion()
64
+
65
+ const sock = makeWASocket({
66
+ version,
67
+ auth: state,
68
+ browser: Browsers.ubuntu('Chrome'),
69
+ printQRInTerminal: false,
70
+ logger: require('pino')({ level: 'silent' }),
71
+ getMessage: async (key) => {
72
+ const msg = await store.loadMessage(key.remoteJid, key.id)
73
+ return msg?.message || undefined
74
+ }
75
+ })
76
+
77
+ sock.ev.on('creds.update', saveCreds)
78
+
79
+ sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
80
+ if (connection === 'close') {
81
+ const code = lastDisconnect?.error?.output?.statusCode
82
+ if (code !== DisconnectReason.loggedOut) startBot()
83
+ }
84
+ })
85
+ ```
86
+
87
+ ### Pairing Code
88
+
89
+ ```js
90
+ // Código gerado automaticamente (ex: ABCD-EFGH)
91
+ const code = await sock.requestPairingCode('5511999999999')
92
+
93
+ // Código personalizado — exatamente 8 caracteres
94
+ const code = await sock.requestPairingCode('5511999999999', 'MYBOT001')
95
+ ```
96
+
97
+ ### Store em memória
98
+
99
+ ```js
100
+ const store = {
101
+ messages: {},
102
+ bind: (ev) => {
103
+ ev.on('messages.upsert', ({ messages }) => {
104
+ for (const msg of messages) {
105
+ if (!msg.key?.remoteJid) continue
106
+ store.messages[msg.key.remoteJid] ??= {}
107
+ store.messages[msg.key.remoteJid][msg.key.id] = msg
108
+ }
109
+ })
110
+ },
111
+ loadMessage: async (jid, id) => store.messages[jid]?.[id] || null
112
+ }
113
+
114
+ store.bind(sock.ev)
115
+ ```
116
+
117
+ ---
118
+
119
+ ## 2. Mensagens de mídia
120
+
121
+ Todos os campos de mídia aceitam `Buffer`, `{ url: 'https://...' }` ou `{ stream: ReadableStream }`.
122
+
123
+ ### Texto
124
+
125
+ ```js
126
+ await sock.sendMessage(jid, { text: 'Olá!' })
127
+
128
+ // Com menção
129
+ await sock.sendMessage(jid, {
130
+ text: '@55119...!',
131
+ mentions: ['5511999999999@s.whatsapp.net']
132
+ })
133
+ ```
134
+
135
+ ### Imagem
136
+
137
+ ```js
138
+ await sock.sendMessage(jid, {
139
+ image: { url: 'https://exemplo.com/foto.jpg' },
140
+ caption: 'Legenda'
141
+ })
142
+ ```
143
+
144
+ ### Vídeo
145
+
146
+ ```js
147
+ await sock.sendMessage(jid, {
148
+ video: { url: 'https://exemplo.com/video.mp4' },
149
+ caption: 'Legenda',
150
+ gifPlayback: false // true envia como GIF silencioso
151
+ })
152
+ ```
153
+
154
+ ### Áudio
155
+
156
+ ```js
157
+ // Música
158
+ await sock.sendMessage(jid, {
159
+ audio: buffer,
160
+ mimetype: 'audio/mpeg',
161
+ ptt: false
162
+ })
163
+
164
+ // Nota de voz (PTT)
165
+ await sock.sendMessage(jid, {
166
+ audio: buffer,
167
+ mimetype: 'audio/ogg; codecs=opus',
168
+ ptt: true
169
+ })
170
+ ```
171
+
172
+ ### Documento
173
+
174
+ ```js
175
+ await sock.sendMessage(jid, {
176
+ document: buffer,
177
+ mimetype: 'application/pdf',
178
+ fileName: 'relatorio.pdf',
179
+ caption: 'Segue o relatório'
180
+ })
181
+ ```
182
+
183
+ ### Figurinha
184
+
185
+ ```js
186
+ await sock.sendMessage(jid, { sticker: buffer })
187
+ ```
188
+
189
+ ### Album (múltiplas mídias agrupadas)
190
+
191
+ Mínimo 2 itens.
192
+
193
+ ```js
194
+ await sock.sendMessage(jid, {
195
+ album: [
196
+ { image: buffer1 },
197
+ { image: buffer2, caption: 'Segunda foto' },
198
+ { video: bufferVideo },
199
+ ]
200
+ })
201
+ ```
202
+
203
+ ### Contato
204
+
205
+ ```js
206
+ await sock.sendMessage(jid, {
207
+ contacts: {
208
+ displayName: 'João',
209
+ contacts: [{
210
+ vcard: `BEGIN:VCARD\nVERSION:3.0\nFN:João Silva\nTEL:+5511999999999\nEND:VCARD`
211
+ }]
212
+ }
213
+ })
214
+ ```
215
+
216
+ ### Localização
217
+
218
+ ```js
219
+ await sock.sendMessage(jid, {
220
+ location: {
221
+ degreesLatitude: -23.550520,
222
+ degreesLongitude: -46.633308,
223
+ name: 'São Paulo',
224
+ address: 'SP, Brasil'
225
+ }
226
+ })
227
+ ```
228
+
229
+ ---
230
+
231
+ ## 3. Mensagens especiais
232
+
233
+ ### Reação
234
+
235
+ ```js
236
+ await sock.sendMessage(jid, {
237
+ react: { text: '❤️', key: message.key }
238
+ // text: '' remove a reação
239
+ })
240
+ ```
241
+
242
+ ### Deletar mensagem
243
+
244
+ ```js
245
+ await sock.sendMessage(jid, { delete: message.key })
246
+ ```
247
+
248
+ ### Editar mensagem
249
+
250
+ ```js
251
+ await sock.sendMessage(jid, {
252
+ edit: message.key,
253
+ text: 'Texto editado'
254
+ })
255
+ ```
256
+
257
+ ### Fixar mensagem
258
+
259
+ ```js
260
+ await sock.sendMessage(jid, {
261
+ pin: {
262
+ type: 1, // 1 = fixar, 2 = desfixar
263
+ time: 86400, // duração em segundos
264
+ messageKey: message.key
265
+ }
266
+ })
267
+ ```
268
+
269
+ ### Encaminhar
270
+
271
+ ```js
272
+ const { generateForwardMessageContent, generateWAMessageFromContent } = require('@systemzero/baileys')
273
+
274
+ const content = generateForwardMessageContent(message, false)
275
+ const msg = generateWAMessageFromContent(jid, content, { quoted: m })
276
+ await sock.relayMessage(jid, msg.message, { messageId: msg.key.id })
277
+ ```
278
+
279
+ ### View Once
280
+
281
+ ```js
282
+ await sock.sendMessage(jid, { image: buffer, viewOnce: true })
283
+
284
+ // V2
285
+ await sock.sendMessage(jid, { image: buffer, viewOnceV2: true })
286
+
287
+ // V2 Extension
288
+ await sock.sendMessage(jid, { image: buffer, viewOnceV2Extension: true })
289
+ ```
290
+
291
+ ### Spoiler
292
+
293
+ ```js
294
+ await sock.sendMessage(jid, {
295
+ image: buffer,
296
+ caption: 'Spoiler!',
297
+ spoiler: true
298
+ })
299
+ ```
300
+
301
+ ### Status de grupo
302
+
303
+ ```js
304
+ await sock.sendMessage(jid, {
305
+ image: buffer,
306
+ caption: 'Status do grupo',
307
+ groupStatus: true
308
+ })
309
+ ```
310
+
311
+ ### Mensagem efêmera
312
+
313
+ ```js
314
+ await sock.sendMessage(jid, {
315
+ image: buffer,
316
+ ephemeral: true
317
+ })
318
+ ```
319
+
320
+ ### Lottie (sticker animado especial)
321
+
322
+ ```js
323
+ await sock.sendMessage(jid, {
324
+ sticker: buffer,
325
+ isLottie: true
326
+ })
327
+ ```
328
+
329
+ ### Keep (salvar mensagem)
330
+
331
+ ```js
332
+ await sock.sendMessage(jid, {
333
+ keep: message.key,
334
+ type: 1 // 1 = salvar, 2 = remover
335
+ })
336
+ ```
337
+
338
+ ### Evento
339
+
340
+ ```js
341
+ await sock.sendMessage(jid, {
342
+ event: {
343
+ isCanceled: false,
344
+ name: 'Reunião',
345
+ description: 'Alinhamento',
346
+ location: { name: 'Sala 3', address: 'Rua X, 100' },
347
+ startTime: Math.floor(Date.now() / 1000) + 3600,
348
+ endTime: Math.floor(Date.now() / 1000) + 7200,
349
+ }
350
+ })
351
+ ```
352
+
353
+ ### Enquete
354
+
355
+ ```js
356
+ await sock.sendMessage(jid, {
357
+ poll: {
358
+ name: 'Qual seu time?',
359
+ values: ['Flamengo', 'Corinthians', 'Palmeiras'],
360
+ selectableCount: 1 // 0 = múltipla escolha
361
+ }
362
+ })
363
+ ```
364
+
365
+ ### Invoice (nota fiscal)
366
+
367
+ ```js
368
+ await sock.sendMessage(jid, {
369
+ image: buffer,
370
+ invoiceNote: 'Pagamento pedido #1234'
371
+ })
372
+ ```
373
+
374
+ ### External Ad Reply
375
+
376
+ ```js
377
+ await sock.sendMessage(jid, {
378
+ text: 'Confira!',
379
+ externalAdReply: {
380
+ title: 'System Zero',
381
+ body: 'Descrição do produto',
382
+ thumbnail: bufferImagem,
383
+ mediaType: 1,
384
+ sourceUrl: 'https://systemzone.store',
385
+ renderLargerThumbnail: true
386
+ }
387
+ })
388
+ ```
389
+
390
+ ### Mention All
391
+
392
+ ```js
393
+ await sock.sendMessage(jid, {
394
+ text: '👋 @all',
395
+ mentionAll: true
396
+ })
397
+ ```
398
+
399
+ ### Convite de pagamento
400
+
401
+ ```js
402
+ await sock.sendMessage(jid, {
403
+ paymentInviteServiceType: 3
404
+ })
405
+ ```
406
+
407
+ ### Resultado de enquete (snapshot)
408
+
409
+ ```js
410
+ await sock.sendMessage(jid, {
411
+ pollResult: {
412
+ name: 'Pergunta?',
413
+ pollType: 0, // 0 = poll, 1 = quiz
414
+ votes: [
415
+ { name: 'Opção A', voteCount: 12 },
416
+ { name: 'Opção B', voteCount: 7 },
417
+ ]
418
+ }
419
+ })
420
+ ```
421
+
422
+ ---
423
+
424
+ ## 4. Botões e interativos
425
+
426
+ ### Estrutura base
427
+
428
+ ```js
429
+ const { generateWAMessageFromContent, proto } = require('@systemzero/baileys')
430
+
431
+ const msg = generateWAMessageFromContent(jid, {
432
+ viewOnceMessage: {
433
+ message: {
434
+ interactiveMessage: proto.Message.InteractiveMessage.create({
435
+ header: { title: 'Título', hasMediaAttachment: false },
436
+ body: { text: 'Texto do corpo' },
437
+ footer: { text: 'Rodapé' },
438
+ nativeFlowMessage: {
439
+ buttons: [ /* tipos abaixo */ ]
440
+ }
441
+ })
442
+ }
443
+ }
444
+ }, { quoted: m })
445
+
446
+ await sock.relayMessage(jid, msg.message, { messageId: msg.key.id })
447
+ ```
448
+
449
+ ### Tipos de botão
450
+
451
+ ```js
452
+ // Resposta rápida
453
+ { name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: 'Confirmar', id: 'confirmar' }) }
454
+
455
+ // Link externo
456
+ { name: 'cta_url', buttonParamsJson: JSON.stringify({ display_text: 'Abrir', url: 'https://systemzone.store' }) }
457
+
458
+ // Copiar texto
459
+ { name: 'cta_copy', buttonParamsJson: JSON.stringify({ display_text: 'Copiar código', copy_code: 'PROMO2025' }) }
460
+
461
+ // Ligar
462
+ { name: 'cta_call', buttonParamsJson: JSON.stringify({ display_text: 'Ligar', phone_number: '5511999999999' }) }
463
+
464
+ // Webview interno
465
+ { name: 'cta_webview', buttonParamsJson: JSON.stringify({ title: 'Painel', url: 'https://systemzone.store' }) }
466
+
467
+ // Lista dropdown com seções
468
+ {
469
+ name: 'single_select',
470
+ buttonParamsJson: JSON.stringify({
471
+ title: 'Escolher',
472
+ sections: [{
473
+ title: 'Categoria',
474
+ rows: [
475
+ { header: 'Op 1', title: 'Opção 1', description: 'Desc', id: 'op1' },
476
+ { header: 'Op 2', title: 'Opção 2', description: 'Desc', id: 'op2' },
477
+ ]
478
+ }]
479
+ })
480
+ }
481
+ ```
482
+
483
+ ### Header com imagem
484
+
485
+ Upload da imagem antes de usar no header:
486
+
487
+ ```js
488
+ const { generateWAMessage, generateMessageIDV2 } = require('@systemzero/baileys')
489
+
490
+ const uploaded = await generateWAMessage(jid, { image: buffer }, {
491
+ upload: sock.waUploadToServer,
492
+ userJid: sock.user.id,
493
+ messageId: generateMessageIDV2(sock.user.id),
494
+ })
495
+ const img = uploaded.message?.imageMessage
496
+
497
+ // No header:
498
+ header: {
499
+ title: '',
500
+ hasMediaAttachment: true,
501
+ imageMessage: {
502
+ url: img.url,
503
+ mimetype: img.mimetype,
504
+ fileSha256: img.fileSha256,
505
+ fileLength: img.fileLength,
506
+ mediaKey: img.mediaKey,
507
+ fileEncSha256: img.fileEncSha256,
508
+ directPath: img.directPath,
509
+ mediaKeyTimestamp: img.mediaKeyTimestamp,
510
+ jpegThumbnail: img.jpegThumbnail,
511
+ }
512
+ }
513
+ ```
514
+
515
+ ### Catálogo (product no header)
516
+
517
+ ```js
518
+ header: {
519
+ title: 'Produto',
520
+ hasMediaAttachment: true,
521
+ productMessage: proto.Message.ProductMessage.create({
522
+ product: proto.Message.ProductMessage.ProductSnapshot.create({
523
+ productImage: proto.Message.ImageMessage.create({ ...img }),
524
+ productId: 'ID-001',
525
+ title: 'Nome do Produto',
526
+ description: 'Descrição completa',
527
+ currencyCode: 'BRL',
528
+ priceAmount1000: 29990, // R$ 29,99
529
+ retailerId: 'minha-loja',
530
+ url: 'https://loja.com/produto',
531
+ productImageCount: 1,
532
+ }),
533
+ businessOwnerJid: sock.user.id
534
+ })
535
+ }
536
+ ```
537
+
538
+ ### Carousel
539
+
540
+ ```js
541
+ await sock.sendMessage(jid, {
542
+ cards: [
543
+ {
544
+ image: buffer1,
545
+ caption: 'Texto do card 1',
546
+ title: 'Card 1',
547
+ nativeFlow: [
548
+ { text: 'Ver mais', id: 'card1' },
549
+ { text: 'Site', url: 'https://systemzone.store' }
550
+ ]
551
+ },
552
+ {
553
+ image: buffer2,
554
+ caption: 'Texto do card 2',
555
+ nativeFlow: [{ text: 'Clique', id: 'card2' }]
556
+ }
557
+ ],
558
+ footer: 'Rodapé'
559
+ })
560
+ ```
561
+
562
+ ### Template Buttons
563
+
564
+ ```js
565
+ await sock.sendMessage(jid, {
566
+ text: 'Escolha:',
567
+ templateButtons: [
568
+ { text: 'Resposta', id: 'res1' },
569
+ { text: 'Site', url: 'https://systemzone.store' },
570
+ { text: 'Ligar', call: '5511999999999' },
571
+ ]
572
+ })
573
+ ```
574
+
575
+ ### Sections (lista clássica)
576
+
577
+ ```js
578
+ await sock.sendMessage(jid, {
579
+ text: 'Selecione',
580
+ buttonText: 'Ver opções',
581
+ sections: [{
582
+ title: 'Categoria',
583
+ rows: [
584
+ { title: 'Item 1', description: 'Desc', id: 'item1' },
585
+ { title: 'Item 2', description: 'Desc', id: 'item2' },
586
+ ]
587
+ }]
588
+ })
589
+ ```
590
+
591
+ ### Interactive como Template
592
+
593
+ ```js
594
+ await sock.sendMessage(jid, {
595
+ nativeFlow: [{ text: 'Clique', id: 'btn' }],
596
+ text: 'Mensagem',
597
+ interactiveAsTemplate: true
598
+ })
599
+ ```
600
+
601
+ ### Botões com imagem no corpo (não no header)
602
+
603
+ ```js
604
+ await sock.sendMessage(jid, {
605
+ image: buffer,
606
+ caption: 'Escolha:',
607
+ buttons: [
608
+ { text: 'Opção 1', id: 'op1' },
609
+ { text: 'Link', url: 'https://systemzone.store' },
610
+ ]
611
+ })
612
+ ```
613
+
614
+ ### Áudio no rodapé de interativo
615
+
616
+ ```js
617
+ await sock.sendMessage(jid, {
618
+ text: 'Ouça e escolha:',
619
+ nativeFlow: [{ text: 'Opção', id: 'op' }],
620
+ audioFooter: bufferAudio
621
+ })
622
+ ```
623
+
624
+ ---
625
+
626
+ ## 5. Sticker Pack nativo
627
+
628
+ Envia um pack de figurinhas que aparece na aba de stickers do WhatsApp, igual a um pack real.
629
+
630
+ ```js
631
+ await sock.sendMessage(jid, {
632
+ cover: { url: 'https://exemplo.com/capa.webp' },
633
+ stickers: [
634
+ { data: buffer1, emojis: ['😂'] },
635
+ { data: bufferAnimado, emojis: ['🔥', '💀'] },
636
+ { data: bufferPng, emojis: ['🐱'] }, // PNG converte automaticamente
637
+ ],
638
+ name: 'Nome do Pack',
639
+ publisher: 'Autor',
640
+ description: 'Descrição opcional'
641
+ })
642
+ ```
643
+
644
+ `cover` aceita `Buffer`, `{ url }` ou `{ stream }`. O mesmo vale para cada `sticker.data`.
645
+
646
+ Limites: máximo **60 figurinhas** por pack, cada uma com até **1MB**.
647
+
648
+ Requer `sharp` ou `@napi-rs/image` para conversão de PNG e geração de thumbnail. Sem eles, apenas WebP é aceito.
649
+
650
+ ---
651
+
652
+ ## 6. Canais Newsletter
653
+
654
+ ### Enviar texto
655
+
656
+ ```js
657
+ await sock.sendMessage('120363...@newsletter', { text: 'Novidade!' })
658
+ ```
659
+
660
+ ### Enviar mídia
661
+
662
+ `sendMessage` não passa pelo `encodeNewsletterMessage` corretamente para mídia. Use sempre `generateWAMessage` + `relayMessage`:
663
+
664
+ ```js
665
+ const { generateWAMessage, generateMessageIDV2 } = require('@systemzero/baileys')
666
+
667
+ const canalJid = '120363...@newsletter'
668
+
669
+ const fullMsg = await generateWAMessage(canalJid, {
670
+ image: buffer,
671
+ caption: 'Legenda'
672
+ }, {
673
+ upload: sock.waUploadToServer,
674
+ userJid: sock.user.id,
675
+ messageId: generateMessageIDV2(sock.user.id),
676
+ })
677
+
678
+ await sock.relayMessage(canalJid, fullMsg.message, {
679
+ messageId: fullMsg.key.id,
680
+ })
681
+ ```
682
+
683
+ Funciona para `image`, `video`, `audio`, `sticker`, `document`.
684
+
685
+ ### Gerenciar canais
686
+
687
+ ```js
688
+ // Criar
689
+ const canal = await sock.newsletterCreate('Nome do Canal', 'Descrição')
690
+
691
+ // Seguir / deixar
692
+ await sock.newsletterFollow(jid)
693
+ await sock.newsletterUnfollow(jid)
694
+
695
+ // Silenciar
696
+ await sock.newsletterMute(jid)
697
+ await sock.newsletterUnmute(jid)
698
+
699
+ // Metadata
700
+ const meta = await sock.newsletterMetadata('jid', jid)
701
+ const meta = await sock.newsletterMetadata('invite', 'CODIGO')
702
+
703
+ // Atualizar
704
+ await sock.newsletterUpdateName(jid, 'Novo Nome')
705
+ await sock.newsletterUpdateDescription(jid, 'Nova descrição')
706
+ await sock.newsletterUpdatePicture(jid, buffer)
707
+ await sock.newsletterRemovePicture(jid)
708
+
709
+ // Reagir a mensagem
710
+ await sock.newsletterReactMessage(jid, serverId, '❤️')
711
+
712
+ // Listar mensagens
713
+ const msgs = await sock.newsletterFetchMessages(jid, 30, 0, 0)
714
+
715
+ // Admin
716
+ const count = await sock.newsletterAdminCount(jid)
717
+ await sock.newsletterChangeOwner(jid, novoDonoJid)
718
+ await sock.newsletterDemote(jid, usuarioJid)
719
+ await sock.newsletterDelete(jid)
720
+
721
+ // Seguidores
722
+ const { subscribers } = await sock.newsletterSubscribers(jid)
723
+ ```
724
+
725
+ ---
726
+
727
+ ## 7. Enquetes com decrypt
728
+
729
+ ### Criar enquete
730
+
731
+ ```js
732
+ await sock.sendMessage(jid, {
733
+ poll: {
734
+ name: 'Pergunta?',
735
+ values: ['A', 'B', 'C'],
736
+ selectableCount: 1 // 0 = múltipla escolha
737
+ }
738
+ })
739
+ ```
740
+
741
+ ### Receber e descriptografar votos
742
+
743
+ No `connect.js`, após `saveCreds`:
744
+
745
+ ```js
746
+ const { getAggregateVotesInPollMessage } = require('@systemzero/baileys/lib/Utils/messages.js')
747
+
748
+ sock.ev.on('messages.update', async (updates) => {
749
+ for (const { key, update } of updates) {
750
+ if (!update.pollUpdates) continue
751
+
752
+ const pollMsg = await store.loadMessage(key.remoteJid, key.id)
753
+ if (!pollMsg?.message) continue
754
+
755
+ const result = getAggregateVotesInPollMessage({
756
+ message: pollMsg.message,
757
+ pollUpdates: update.pollUpdates,
758
+ })
759
+
760
+ // [{ name: 'Opção A', voters: ['5511...@s.whatsapp.net'] }]
761
+ console.log(result)
762
+
763
+ if (!global.pollResults) global.pollResults = {}
764
+ global.pollResults[key.id] = { options: result, jid: key.remoteJid }
765
+ }
766
+ })
767
+ ```
768
+
769
+ O `getMessage` precisa estar configurado no `makeWASocket` (veja seção 1).
770
+
771
+ ---
772
+
773
+ ## 8. AI Rich
774
+
775
+ Mensagens com formatação avançada: markdown, código, tabelas, hyperlinks clicáveis no texto.
776
+
777
+ ### Direto pelo socket
778
+
779
+ ```js
780
+ // Texto com hyperlink
781
+ await sock.sendRich(jid, [
782
+ sock.makeText('Acesse [nosso site](https://systemzone.store).')
783
+ ], quotedMsg)
784
+
785
+ // Código
786
+ await sock.sendRich(jid, [
787
+ sock.makeCode('bash', 'npm i @systemzero/baileys')
788
+ ], null, ['RICH_RESPONSE_CODE'])
789
+
790
+ // Tabela
791
+ await sock.sendRich(jid, [
792
+ sock.makeTable([
793
+ ['Nome', 'Status'],
794
+ ['Botões', '✅'],
795
+ ['Canais', '✅'],
796
+ ])
797
+ ], null, ['RICH_RESPONSE_TABLE'])
798
+
799
+ // Lista
800
+ await sock.sendRich(jid, [
801
+ sock.makeList(['Item 1', 'Item 2', 'Item 3'])
802
+ ])
803
+
804
+ // Tudo junto
805
+ await sock.sendRich(jid, [
806
+ sock.makeText('# Título\nConteúdo com [link](https://systemzone.store)'),
807
+ sock.makeCode('javascript', 'const x = require("@systemzero/baileys")'),
808
+ sock.makeTable([['Col A', 'Col B'], ['val1', 'val2']]),
809
+ ], quotedMsg, ['RICH_RESPONSE_CODE', 'RICH_RESPONSE_TABLE'])
810
+ ```
811
+
812
+ ### Atalhos
813
+
814
+ ```js
815
+ await sock.sendRichText(jid, 'Texto com [link](https://systemzone.store)', quotedMsg)
816
+ await sock.sendRichCode(jid, 'Título', 'javascript', 'console.log("hi")', quotedMsg)
817
+ await sock.sendRichList(jid, 'Lista', ['A', 'B', 'C'], quotedMsg)
818
+ ```
819
+
820
+ ### Usando a classe AIRich
821
+
822
+ ```js
823
+ const { AIRich } = require('@systemzero/baileys/lib/MB.cjs')
824
+
825
+ const msg = new AIRich(sock)
826
+ msg.addText('Texto com [link](https://systemzone.store)')
827
+ msg.addCode('javascript', 'const x = 1')
828
+ msg.addTable([['Col', 'Valor'], ['linha', 'dado']])
829
+ await msg.send(jid, { quoted: m })
830
+ ```
831
+
832
+ ---
833
+
834
+ ## 9. Grupos
835
+
836
+ ```js
837
+ // Criar
838
+ const grupo = await sock.groupCreate('Nome', ['5511...@s.whatsapp.net'])
839
+
840
+ // Participantes
841
+ await sock.groupParticipantsUpdate(jid, ['5511...@s.whatsapp.net'], 'add')
842
+ await sock.groupParticipantsUpdate(jid, ['5511...@s.whatsapp.net'], 'remove')
843
+ await sock.groupParticipantsUpdate(jid, ['5511...@s.whatsapp.net'], 'promote')
844
+ await sock.groupParticipantsUpdate(jid, ['5511...@s.whatsapp.net'], 'demote')
845
+
846
+ // Sair
847
+ await sock.groupLeave(jid)
848
+
849
+ // Nome e descrição
850
+ await sock.groupUpdateSubject(jid, 'Novo Nome')
851
+ await sock.groupUpdateDescription(jid, 'Nova descrição')
852
+
853
+ // Convite
854
+ const code = await sock.groupInviteCode(jid)
855
+ await sock.groupRevokeInvite(jid)
856
+ await sock.groupAcceptInvite('CODIGO')
857
+
858
+ // Mensagens efêmeras (0 = desativar)
859
+ await sock.groupToggleEphemeral(jid, 86400)
860
+
861
+ // Metadata
862
+ const meta = await sock.groupMetadata(jid)
863
+ const grupos = await sock.groupFetchAllParticipating()
864
+ ```
865
+
866
+ ---
867
+
868
+ ## 10. Perfil e privacidade
869
+
870
+ ```js
871
+ // Foto de perfil
872
+ const url = await sock.profilePictureUrl(jid, 'image')
873
+ await sock.updateProfilePicture(jid, buffer)
874
+
875
+ // Bio
876
+ await sock.updateProfileStatus('🤖 Bot ativo')
877
+
878
+ // Verificar número
879
+ const [result] = await sock.onWhatsApp('5511999999999')
880
+ // { exists: true, jid: '5511...@s.whatsapp.net' }
881
+
882
+ // Bloquear / desbloquear
883
+ await sock.updateBlockStatus(jid, 'block')
884
+ await sock.updateBlockStatus(jid, 'unblock')
885
+
886
+ // Presence
887
+ await sock.sendPresenceUpdate('composing', jid) // digitando
888
+ await sock.sendPresenceUpdate('recording', jid) // gravando
889
+ await sock.sendPresenceUpdate('available', jid) // online
890
+ await sock.sendPresenceUpdate('unavailable') // offline
891
+ await sock.presenceSubscribe(jid) // receber presence de contato
892
+
893
+ // Marcar como lido
894
+ await sock.readMessages([message.key])
895
+
896
+ // Privacidade da foto
897
+ await sock.updateProfilePicturePrivacy('all') // 'all' | 'contacts' | 'none'
898
+
899
+ // Modificar chat
900
+ await sock.chatModify({ archive: true }, jid)
901
+ await sock.chatModify({ pin: true }, jid)
902
+ await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
903
+ await sock.chatModify({ star: { messages: [{ id, fromMe }], star: true } }, jid)
904
+ await sock.chatModify({ clear: { messages: [{ id, fromMe, timestamp }] } }, jid)
905
+
906
+ // Desconectar
907
+ await sock.logout()
908
+ ```
909
+
910
+ ---
911
+
912
+ ## 11. Eventos do socket
913
+
914
+ ```js
915
+ sock.ev.on('messages.upsert', ({ messages, type }) => {})
916
+ sock.ev.on('messages.update', (updates) => {})
917
+ sock.ev.on('messages.delete', (item) => {})
918
+ sock.ev.on('messages.reaction', (reactions) => {})
919
+ sock.ev.on('presence.update', ({ id, presences }) => {})
920
+ sock.ev.on('groups.update', (updates) => {})
921
+ sock.ev.on('group-participants.update', ({ id, participants, action }) => {})
922
+ sock.ev.on('contacts.update', (contacts) => {})
923
+ sock.ev.on('chats.update', (chats) => {})
924
+ sock.ev.on('connection.update', ({ connection, lastDisconnect, qr }) => {})
925
+ sock.ev.on('creds.update', saveCreds)
926
+
927
+ // Chamadas
928
+ sock.ev.on('call', (calls) => {
929
+ for (const call of calls) {
930
+ if (call.status === 'offer') {
931
+ sock.rejectCall(call.id, call.from)
932
+ }
933
+ }
934
+ })
935
+ ```
936
+
937
+ ---
938
+
939
+ ## 12. Utilitários
940
+
941
+ ### Download de mídia
942
+
943
+ ```js
944
+ const { downloadMediaMessage } = require('@systemzero/baileys')
945
+
946
+ const buffer = await downloadMediaMessage(message, 'buffer', {})
947
+ const stream = await downloadMediaMessage(message, 'stream', {})
948
+ ```
949
+
950
+ ### Download manual por stream
951
+
952
+ ```js
953
+ const { downloadContentFromMessage } = require('@systemzero/baileys')
954
+
955
+ const stream = await downloadContentFromMessage(
956
+ { mediaKey, directPath, url },
957
+ 'image' // 'image' | 'video' | 'audio' | 'sticker' | 'document'
958
+ )
959
+ const chunks = []
960
+ for await (const chunk of stream) chunks.push(chunk)
961
+ const buffer = Buffer.concat(chunks)
962
+ ```
963
+
964
+ ### Geração de mensagem manual
965
+
966
+ ```js
967
+ const {
968
+ generateWAMessage,
969
+ generateWAMessageFromContent,
970
+ generateMessageIDV2,
971
+ generateForwardMessageContent
972
+ } = require('@systemzero/baileys')
973
+
974
+ // Com upload automático de mídia
975
+ const msg = await generateWAMessage(jid, { image: buffer }, {
976
+ upload: sock.waUploadToServer,
977
+ userJid: sock.user.id,
978
+ messageId: generateMessageIDV2(sock.user.id),
979
+ })
980
+
981
+ // Sem upload (proto manual)
982
+ const msg = generateWAMessageFromContent(jid, { ... }, { quoted: m })
983
+
984
+ // Enviar o proto
985
+ await sock.relayMessage(jid, msg.message, { messageId: msg.key.id })
986
+ ```
987
+
988
+ ### Detectar dispositivo
989
+
990
+ ```js
991
+ const { getDevice } = require('@systemzero/baileys')
992
+ const device = getDevice(message.key.id)
993
+ // 'android' | 'ios' | 'web' | 'unknown'
994
+ ```
995
+
996
+ ### JID utils
997
+
998
+ ```js
999
+ const {
1000
+ jidNormalizedUser,
1001
+ isJidGroup,
1002
+ isJidNewsletter,
1003
+ jidEncode,
1004
+ jidDecode
1005
+ } = require('@systemzero/baileys')
1006
+
1007
+ jidNormalizedUser('5511999999999@s.whatsapp.net')
1008
+ isJidGroup('120363...@g.us') // true
1009
+ isJidNewsletter('120363...@newsletter') // true
1010
+ ```
1011
+
1012
+ ---
1013
+
1014
+ <div align="center">
1015
+
1016
+ **@systemzero/baileys v1.0.5**
1017
+
1018
+ Desenvolvido por [Josué </>](https://t.me/blackhzx) · [Canal WhatsApp](https://whatsapp.com/channel/0029VaqUb9aGk1FxqeKKOd2i) · [systemzone.store](https://systemzone.store)
1019
+
1020
+ </div>