@dylsx/baileys-br 1.0.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/LICENSE +21 -0
- package/README.md +307 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.js +169661 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +118 -0
- package/lib/Defaults/wileys-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.js +174 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +111 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.js +915 -0
- package/lib/Socket/groups.js +332 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.js +1054 -0
- package/lib/Socket/messages-send.js +872 -0
- package/lib/Socket/newsletter.js +250 -0
- package/lib/Socket/socket.js +654 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-in-memory-store.js +439 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.js +199 -0
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.js +730 -0
- package/lib/Utils/crypto.js +193 -0
- package/lib/Utils/decode-wa-message.js +207 -0
- package/lib/Utils/event-buffer.js +518 -0
- package/lib/Utils/generics.js +467 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.js +35 -0
- package/lib/Utils/link-preview.js +126 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +879 -0
- package/lib/Utils/messages.js +1049 -0
- package/lib/Utils/noise-handler.js +150 -0
- package/lib/Utils/process-message.js +404 -0
- package/lib/Utils/signal.js +153 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/wileys-event-stream.js +63 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +265 -0
- package/lib/WABinary/encode.js +250 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.js +85 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +54 -0
- package/package.json +117 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 nstar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# <div align='center'>🇧🇷 Baileys BR - WhatsApp API Multi-Device</div>
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="https://i.ibb.co/93c0VgP7/shamika-wa-baileys.jpg" />
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
|
|
9
|
+
### ⚡ A mais poderosa implementação WhatsApp Multi-Device para Node.js ⚡
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/@dylsx/baileys-br)
|
|
12
|
+
[](https://www.npmjs.com/package/@dylsx/baileys-br)
|
|
13
|
+
[](https://www.npmjs.com/package/@dylsx/baileys-br)
|
|
14
|
+
[](MIT)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 📋 Sobre o Projeto
|
|
21
|
+
|
|
22
|
+
**Baileys BR** é uma implementação robusta e completa da API do WhatsApp Web Multi-Device para Node.js. Baseado no excelente trabalho da comunidade [WhiskeySockets](https://github.com/WhiskeySockets), este pacote traz melhorias significativas e funcionalidades extras para tornar sua experiência de desenvolvimento ainda mais produtiva.
|
|
23
|
+
|
|
24
|
+
### ✨ O que torna o Baileys BR especial?
|
|
25
|
+
|
|
26
|
+
- ✅ **Completamente em Português** - Documentação e exemplos localizados
|
|
27
|
+
- ✅ **Exemplos em CJS e ESM** - Suporte para ambos os sistemas de módulos
|
|
28
|
+
- ✅ **Recursos exclusivos** - Funcionalidades extras não disponíveis no original
|
|
29
|
+
- ✅ **Totalmente tipado** - TypeScript com tipos precisos
|
|
30
|
+
- ✅ **Atualizado constantemente** - Sempre seguindo as últimas atualizações do WhatsApp
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🚀 Instalação
|
|
35
|
+
|
|
36
|
+
### NPM
|
|
37
|
+
```bash
|
|
38
|
+
npm install @dylsx/baileys-br
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Yarn
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
yarn add @dylsx/baileys-br
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
PNPM
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pnpm add @dylsx/baileys-br
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
📖 Exemplos de Uso
|
|
56
|
+
|
|
57
|
+
Exemplo Básico com CommonJS (CJS)
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const { default: makeWASocket, useMultiFileAuthState } = require('@dylsx/baileys-br');
|
|
61
|
+
const { Boom } = require('@hapi/boom');
|
|
62
|
+
const P = require('pino');
|
|
63
|
+
|
|
64
|
+
async function connectToWhatsApp() {
|
|
65
|
+
// Carrega estado de autenticação
|
|
66
|
+
const { state, saveCreds } = await useMultiFileAuthState('auth_info');
|
|
67
|
+
|
|
68
|
+
// Cria a conexão
|
|
69
|
+
const sock = makeWASocket({
|
|
70
|
+
auth: state,
|
|
71
|
+
printQRInTerminal: true,
|
|
72
|
+
logger: P({ level: 'silent' }),
|
|
73
|
+
browser: ['Baileys BR', 'Chrome', '1.0.0'],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Evento quando as credenciais são atualizadas
|
|
77
|
+
sock.ev.on('creds.update', saveCreds);
|
|
78
|
+
|
|
79
|
+
// Evento quando a conexão é atualizada
|
|
80
|
+
sock.ev.on('connection.update', (update) => {
|
|
81
|
+
const { connection, lastDisconnect } = update;
|
|
82
|
+
|
|
83
|
+
if (connection === 'close') {
|
|
84
|
+
const shouldReconnect = (lastDisconnect?.error)?.output?.statusCode !== 401;
|
|
85
|
+
console.log('Conexão fechada, reconectando:', shouldReconnect);
|
|
86
|
+
|
|
87
|
+
if (shouldReconnect) {
|
|
88
|
+
connectToWhatsApp();
|
|
89
|
+
}
|
|
90
|
+
} else if (connection === 'open') {
|
|
91
|
+
console.log('✅ Conectado com sucesso!');
|
|
92
|
+
console.log('📱 Número:', sock.user?.id.split(':')[0]);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Evento para receber mensagens
|
|
97
|
+
sock.ev.on('messages.upsert', async ({ messages, type }) => {
|
|
98
|
+
const msg = messages[0];
|
|
99
|
+
|
|
100
|
+
if (!msg.message || msg.key.fromMe) return;
|
|
101
|
+
|
|
102
|
+
const text = msg.message.conversation ||
|
|
103
|
+
msg.message.extendedTextMessage?.text ||
|
|
104
|
+
'';
|
|
105
|
+
|
|
106
|
+
const sender = msg.key.remoteJid;
|
|
107
|
+
console.log(`📩 Mensagem de ${sender}: ${text}`);
|
|
108
|
+
|
|
109
|
+
// Responde a comandos
|
|
110
|
+
if (text === '!ping') {
|
|
111
|
+
await sock.sendMessage(sender, { text: '🏓 Pong!' });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (text === '!hora') {
|
|
115
|
+
const agora = new Date().toLocaleString('pt-BR');
|
|
116
|
+
await sock.sendMessage(sender, { text: `🕐 ${agora}` });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Inicia o bot
|
|
122
|
+
connectToWhatsApp().catch(console.error);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Exemplo com TypeScript (ESM)
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import makeWASocket, {
|
|
129
|
+
useMultiFileAuthState,
|
|
130
|
+
DisconnectReason,
|
|
131
|
+
downloadMediaMessage,
|
|
132
|
+
} from '@dylsx/baileys-br';
|
|
133
|
+
import { Boom } from '@hapi/boom';
|
|
134
|
+
import * as fs from 'fs/promises';
|
|
135
|
+
|
|
136
|
+
async function startBot() {
|
|
137
|
+
const { state, saveCreds } = await useMultiFileAuthState('./auth');
|
|
138
|
+
|
|
139
|
+
const sock = makeWASocket({
|
|
140
|
+
auth: state,
|
|
141
|
+
printQRInTerminal: true,
|
|
142
|
+
browser: ['Baileys BR', 'Safari', '1.0.0'],
|
|
143
|
+
syncFullHistory: true,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
sock.ev.on('creds.update', saveCreds);
|
|
147
|
+
|
|
148
|
+
sock.ev.on('connection.update', (update) => {
|
|
149
|
+
const { connection, lastDisconnect, qr } = update;
|
|
150
|
+
|
|
151
|
+
if (qr) {
|
|
152
|
+
console.log('📱 Escaneie o QR Code acima');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (connection === 'close') {
|
|
156
|
+
const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut;
|
|
157
|
+
|
|
158
|
+
if (shouldReconnect) {
|
|
159
|
+
console.log('🔄 Reconectando...');
|
|
160
|
+
startBot();
|
|
161
|
+
} else {
|
|
162
|
+
console.log('❌ Deslogado permanentemente');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
sock.ev.on('messages.upsert', async ({ messages }) => {
|
|
168
|
+
const m = messages[0];
|
|
169
|
+
|
|
170
|
+
if (!m.message || m.key.fromMe) return;
|
|
171
|
+
|
|
172
|
+
// Download de mídia
|
|
173
|
+
if (m.message.imageMessage) {
|
|
174
|
+
const buffer = await downloadMediaMessage(m, 'buffer', {});
|
|
175
|
+
await fs.writeFile(`./downloads/${Date.now()}.jpg`, buffer);
|
|
176
|
+
console.log('📸 Imagem salva!');
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return sock;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
startBot();
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
✨ Funcionalidades Exclusivas do Baileys BR
|
|
189
|
+
|
|
190
|
+
Além de todas as funcionalidades do Baileys original, adicionamos:
|
|
191
|
+
|
|
192
|
+
🆕 Mensagens para Canais
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
// Enviar mensagem para canal
|
|
196
|
+
await sock.sendMessage(channelJid, {
|
|
197
|
+
text: 'Olá canal!',
|
|
198
|
+
isForwarded: true
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
🆕 Botões e Mensagens Interativas
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
// Enviar botões
|
|
206
|
+
await sock.sendMessage(jid, {
|
|
207
|
+
text: 'Escolha uma opção:',
|
|
208
|
+
buttons: [
|
|
209
|
+
{ buttonId: '1', buttonText: { displayText: '✅ Sim' } },
|
|
210
|
+
{ buttonId: '2', buttonText: { displayText: '❌ Não' } }
|
|
211
|
+
],
|
|
212
|
+
viewOnce: true
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
🆕 Código de Pareamento Customizado
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
// Gerar código de pareamento
|
|
220
|
+
const code = await sock.requestPairingCode('5511999999999');
|
|
221
|
+
console.log(`🔑 Código: ${code}`);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
🆕 Ícone de IA nas Mensagens
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
// Mensagem com ícone de IA
|
|
228
|
+
await sock.sendMessage(jid, {
|
|
229
|
+
text: 'Resposta gerada por IA 🤖',
|
|
230
|
+
aiMessage: true
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
📚 Documentação
|
|
237
|
+
|
|
238
|
+
Para documentação completa e detalhada, visite:
|
|
239
|
+
|
|
240
|
+
👉 https://baileys.wiki 👈
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
🛠️ Requisitos
|
|
245
|
+
|
|
246
|
+
· Node.js 20.0.0 ou superior
|
|
247
|
+
· Sistema operacional: Windows, Linux, macOS
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
📦 Estrutura do Projeto
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
@dylsx/baileys-br/
|
|
255
|
+
├── lib/ # Código compilado
|
|
256
|
+
├── WAProto/ # Protocol buffers do WhatsApp
|
|
257
|
+
├── examples/ # Exemplos de uso
|
|
258
|
+
└── docs/ # Documentação
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
🤝 Contribuindo
|
|
264
|
+
|
|
265
|
+
Contribuições são sempre bem-vindas! Veja como ajudar:
|
|
266
|
+
|
|
267
|
+
1. Faça um fork do projeto
|
|
268
|
+
2. Crie sua branch (git checkout -b feature/NovaFeature)
|
|
269
|
+
3. Commit suas mudanças (git commit -m 'Adiciona nova feature')
|
|
270
|
+
4. Push para a branch (git push origin feature/NovaFeature)
|
|
271
|
+
5. Abra um Pull Request
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
📄 Licença
|
|
276
|
+
|
|
277
|
+
Este projeto está sob a licença MIT. Veja o arquivo LICENSE para mais detalhes.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
⚠️ Aviso Importante
|
|
282
|
+
|
|
283
|
+
[!CAUTION]
|
|
284
|
+
NOTA SOBRE MUDANÇAS CRÍTICAS
|
|
285
|
+
|
|
286
|
+
A partir da versão 7.0.0, várias mudanças significativas foram introduzidas.
|
|
287
|
+
Consulte https://whiskey.so/migrate-latest para mais informações.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
🌟 Créditos
|
|
292
|
+
|
|
293
|
+
Este projeto é baseado no excelente trabalho de:
|
|
294
|
+
|
|
295
|
+
· WhiskeySockets - Mantenedores do Baileys original
|
|
296
|
+
· adiwajshing - Criador original do Baileys
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
<div align="center">
|
|
301
|
+
|
|
302
|
+
Desenvolvido com ❤️ para a comunidade brasileira
|
|
303
|
+
|
|
304
|
+
https://img.shields.io/github/stars/dylsx/baileys-br?style=social
|
|
305
|
+
https://img.shields.io/github/forks/dylsx/baileys-br?style=social
|
|
306
|
+
|
|
307
|
+
</div>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
yarn pbjs -t static-module -w commonjs -o ./WAProto/index.js ./WAProto/WAProto.proto;
|
|
2
|
+
yarn pbts -o ./WAProto/index.d.ts ./WAProto/index.js;
|
|
3
|
+
|
|
4
|
+
#protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=env=node,useOptionals=true,forceLong=long --ts_proto_out=. ./src/Binary/WAMessage.proto;
|