@fer2809fl/baileys 1.4.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/LICENSE +674 -0
- package/README.md +424 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +55057 -0
- package/WAProto/index.js +169661 -0
- package/WAProto/index.ts.ts +53473 -0
- package/WAProto/n +1 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +62 -0
- package/lib/Defaults/index.js +117 -0
- package/lib/Defaults/n +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +174 -0
- package/lib/Signal/n +1 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/n +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +111 -0
- package/lib/Socket/business.d.ts +172 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +82 -0
- package/lib/Socket/chats.js +871 -0
- package/lib/Socket/groups.d.ts +124 -0
- package/lib/Socket/groups.js +332 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1054 -0
- package/lib/Socket/messages-send.d.ts +151 -0
- package/lib/Socket/messages-send.js +1057 -0
- package/lib/Socket/n +1 -0
- package/lib/Socket/newsletter.d.ts +136 -0
- package/lib/Socket/newsletter.js +268 -0
- package/lib/Socket/setup.js +480 -0
- package/lib/Socket/setup.ts +622 -0
- package/lib/Socket/socket.d.ts +270 -0
- package/lib/Socket/socket.js +534 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +2 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +439 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/n +1 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +103 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +109 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +23 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +199 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +64 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +400 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +64 -0
- package/lib/Types/index.js +42 -0
- package/lib/Types/n +1 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +199 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +730 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +193 -0
- package/lib/Utils/decode-wa-message.d.ts +35 -0
- package/lib/Utils/decode-wa-message.js +207 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +518 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +441 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +126 -0
- package/lib/Utils/logger.d.ts +11 -0
- package/lib/Utils/logger.js +10 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +120 -0
- package/lib/Utils/messages-media.js +980 -0
- package/lib/Utils/messages.d.ts +80 -0
- package/lib/Utils/messages.js +1101 -0
- package/lib/Utils/n +1 -0
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/noise-handler.js +150 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/process-message.js +404 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +153 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/validate-connection.d.ts +10 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +265 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +250 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +37 -0
- package/lib/WABinary/jid-utils.js +85 -0
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WABinary/n +1 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAM/n +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/Protocols/n +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/WAUSync/n +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +48 -0
- package/lib/n +1 -0
- package/package.json +103 -0
package/README.md
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://nexy-ar7z.b-cdn.net/storage/b99a0660.jpg" alt="Baileys" width="200" style="border-radius: 20px;"/>
|
|
4
|
+
|
|
5
|
+
# @Fer280809/Baileys
|
|
6
|
+
### API de WhatsApp Web para Node.js
|
|
7
|
+
|
|
8
|
+
[](https://github.com/Fer280809/Baileys)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://nodejs.org)
|
|
11
|
+
[](https://www.typescriptlang.org)
|
|
12
|
+
|
|
13
|
+
*Conéctate a WhatsApp Web directamente desde Node.js sin navegadores ni Selenium*
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ⚠️ Nota Importante
|
|
20
|
+
|
|
21
|
+
ꕤ Esta librería está basada en Baileys. No está afiliada ni aprobada oficialmente por WhatsApp.
|
|
22
|
+
|
|
23
|
+
> **@Fer280809/Baileys** y su desarrollador no se hacen responsables por el mal uso de esta librería.
|
|
24
|
+
> Úsala de forma responsable — nada de spam ni actividades maliciosas.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 📦 Instalación
|
|
29
|
+
|
|
30
|
+
Puedes instalarla de dos formas, ambas funcionan igual:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Con el paquete de este repo
|
|
34
|
+
npm install @fer280809/Baileys
|
|
35
|
+
yarn add @fer280809/Baileys
|
|
36
|
+
|
|
37
|
+
# Con el paquete original de whiskeysockets
|
|
38
|
+
npm install @whiskeysockets/baileys
|
|
39
|
+
yarn add @whiskeysockets/baileys
|
|
40
|
+
|
|
41
|
+
# Versión de desarrollo (última del repo)
|
|
42
|
+
npm install github:Fer280809/Baileys
|
|
43
|
+
yarn add github:Fer280809/Baileys
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## ⚡ Inicio Rápido
|
|
49
|
+
|
|
50
|
+
### JavaScript
|
|
51
|
+
```javascript
|
|
52
|
+
const { makeWASocket, useMultiFileAuthState } = require('@Fer280809/Baileys')
|
|
53
|
+
|
|
54
|
+
async function startBot() {
|
|
55
|
+
const { state, saveCreds } = await useMultiFileAuthState('session-mymelody')
|
|
56
|
+
|
|
57
|
+
const melody = makeWASocket({
|
|
58
|
+
auth: state,
|
|
59
|
+
printQRInTerminal: true
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
melody.ev.on('connection.update', ({ connection }) => {
|
|
63
|
+
if (connection === 'open') console.log('✅ ¡Conectado con éxito!')
|
|
64
|
+
if (connection === 'close') console.log('❌ Conexión cerrada, reconectando...')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
melody.ev.on('messages.upsert', async ({ messages }) => {
|
|
68
|
+
const m = messages[0]
|
|
69
|
+
if (!m.message) return
|
|
70
|
+
|
|
71
|
+
await melody.sendMessage(m.key.remoteJid, {
|
|
72
|
+
text: '¡Hola! Soy un bot de Delta!'
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
melody.ev.on('creds.update', saveCreds)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
startBot()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### TypeScript
|
|
83
|
+
```typescript
|
|
84
|
+
import makeWASocket, { useMultiFileAuthState, DisconnectReason } from '@Fer280809/Baileys'
|
|
85
|
+
import { Boom } from '@hapi/boom'
|
|
86
|
+
|
|
87
|
+
async function startBot(): Promise<void> {
|
|
88
|
+
const { state, saveCreds } = await useMultiFileAuthState('session-mymelody')
|
|
89
|
+
|
|
90
|
+
const melody = makeWASocket({
|
|
91
|
+
auth: state,
|
|
92
|
+
printQRInTerminal: true
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
melody.ev.on('connection.update', ({ connection, lastDisconnect }) => {
|
|
96
|
+
if (connection === 'close') {
|
|
97
|
+
const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
|
|
98
|
+
if (shouldReconnect) startBot()
|
|
99
|
+
}
|
|
100
|
+
if (connection === 'open') console.log('✅ ¡Conectado!')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
melody.ev.on('messages.upsert', async ({ messages }) => {
|
|
104
|
+
const m = messages[0]
|
|
105
|
+
if (!m.message) return
|
|
106
|
+
|
|
107
|
+
await melody.sendMessage(m.key.remoteJid!, {
|
|
108
|
+
text: '¡Hola! Soy un bot de Delta!'
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
melody.ev.on('creds.update', saveCreds)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
startBot()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## ✨ Características
|
|
121
|
+
|
|
122
|
+
### General
|
|
123
|
+
- 🚀 Optimizado para mayor velocidad y estabilidad
|
|
124
|
+
- 📸 Mensajes multimedia (imágenes, video, audio, documentos)
|
|
125
|
+
- 🤖 Comandos personalizados fáciles de implementar
|
|
126
|
+
- 👥 Soporte para grupos y chats privados
|
|
127
|
+
- 🔘 Mensajes interactivos con botones y listas
|
|
128
|
+
|
|
129
|
+
### Técnicas
|
|
130
|
+
- ⚡ Sin Selenium — Conexión directa vía WebSocket
|
|
131
|
+
- 💾 Super eficiente — Bajo consumo de RAM
|
|
132
|
+
- 📱 Soporte multi-dispositivo — Compatible con WhatsApp Web
|
|
133
|
+
- 🔷 Totalmente tipado — TypeScript y JavaScript
|
|
134
|
+
- 🔄 Reconexión automática ante desconexiones
|
|
135
|
+
- 🔐 Sesiones persistentes guardadas localmente
|
|
136
|
+
- 🌐 API completa de WhatsApp Web
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 📖 Uso Básico
|
|
141
|
+
|
|
142
|
+
### Inicializar el bot
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
// JavaScript
|
|
146
|
+
const { makeWASocket, useMultiFileAuthState } = require('@Fer280809/Baileys')
|
|
147
|
+
|
|
148
|
+
const { state, saveCreds } = await useMultiFileAuthState('session-mymelody')
|
|
149
|
+
const melody = makeWASocket({ auth: state, printQRInTerminal: true })
|
|
150
|
+
melody.ev.on('creds.update', saveCreds)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// TypeScript
|
|
155
|
+
import makeWASocket, { useMultiFileAuthState } from '@Fer280809/Baileys'
|
|
156
|
+
|
|
157
|
+
const { state, saveCreds } = await useMultiFileAuthState('session-mymelody')
|
|
158
|
+
const melody = makeWASocket({ auth: state, printQRInTerminal: true })
|
|
159
|
+
melody.ev.on('creds.update', saveCreds)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Enviar mensajes
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
// Texto simple
|
|
166
|
+
await melody.sendMessage(jid, { text: '¡Hola mundo!' })
|
|
167
|
+
|
|
168
|
+
// Imagen con caption
|
|
169
|
+
await melody.sendMessage(jid, {
|
|
170
|
+
image: { url: './images/mymelody.jpg' },
|
|
171
|
+
caption: '¡Mira mi nueva foto!'
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
// Video con caption
|
|
175
|
+
await melody.sendMessage(jid, {
|
|
176
|
+
video: { url: './videos/clip.mp4' },
|
|
177
|
+
caption: '¡Nuevo video!'
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
// Audio (PTT = nota de voz)
|
|
181
|
+
await melody.sendMessage(jid, {
|
|
182
|
+
audio: { url: './audio/nota.mp3' },
|
|
183
|
+
mimetype: 'audio/mp4',
|
|
184
|
+
ptt: true
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
// Sticker
|
|
188
|
+
await melody.sendMessage(jid, {
|
|
189
|
+
sticker: { url: './stickers/melody.webp' }
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
// Documento
|
|
193
|
+
await melody.sendMessage(jid, {
|
|
194
|
+
document: { url: './archivo.pdf' },
|
|
195
|
+
mimetype: 'application/pdf',
|
|
196
|
+
fileName: 'archivo.pdf'
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
// Reaccionar a un mensaje
|
|
200
|
+
await melody.sendMessage(jid, {
|
|
201
|
+
react: { text: '💖', key: m.key }
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 🤖 Comandos Personalizados
|
|
208
|
+
|
|
209
|
+
### JavaScript
|
|
210
|
+
```javascript
|
|
211
|
+
melody.ev.on('messages.upsert', async ({ messages }) => {
|
|
212
|
+
const m = messages[0]
|
|
213
|
+
const body = m.message?.conversation
|
|
214
|
+
|| m.message?.extendedTextMessage?.text
|
|
215
|
+
|| ''
|
|
216
|
+
|
|
217
|
+
const prefix = '!'
|
|
218
|
+
if (!body.startsWith(prefix)) return
|
|
219
|
+
|
|
220
|
+
const [cmd, ...args] = body.slice(prefix.length).trim().split(' ')
|
|
221
|
+
|
|
222
|
+
switch (cmd.toLowerCase()) {
|
|
223
|
+
case 'hola':
|
|
224
|
+
await melody.sendMessage(m.key.remoteJid, {
|
|
225
|
+
text: '¡Hola! Soy Delta, ¿en qué puedo ayudarte?'
|
|
226
|
+
})
|
|
227
|
+
break
|
|
228
|
+
|
|
229
|
+
case 'ping':
|
|
230
|
+
await melody.sendMessage(m.key.remoteJid, {
|
|
231
|
+
text: '🏓 Pong!'
|
|
232
|
+
})
|
|
233
|
+
break
|
|
234
|
+
|
|
235
|
+
case 'stickers':
|
|
236
|
+
await melody.sendMessage(m.key.remoteJid, {
|
|
237
|
+
text: '¡Aquí tienes stickers lindos!'
|
|
238
|
+
})
|
|
239
|
+
break
|
|
240
|
+
|
|
241
|
+
default:
|
|
242
|
+
await melody.sendMessage(m.key.remoteJid, {
|
|
243
|
+
text: `Comando desconocido: ${cmd}`
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### TypeScript
|
|
250
|
+
```typescript
|
|
251
|
+
melody.ev.on('messages.upsert', async ({ messages }) => {
|
|
252
|
+
const m = messages[0]
|
|
253
|
+
const body: string = m.message?.conversation
|
|
254
|
+
?? m.message?.extendedTextMessage?.text
|
|
255
|
+
?? ''
|
|
256
|
+
|
|
257
|
+
const prefix = '!'
|
|
258
|
+
if (!body.startsWith(prefix)) return
|
|
259
|
+
|
|
260
|
+
const [cmd, ...args]: string[] = body.slice(prefix.length).trim().split(' ')
|
|
261
|
+
|
|
262
|
+
const commands: Record<string, () => Promise<void>> = {
|
|
263
|
+
hola: async () => {
|
|
264
|
+
await melody.sendMessage(m.key.remoteJid!, {
|
|
265
|
+
text: '¡Hola! Soy My Melody, ¿en qué puedo ayudarte?'
|
|
266
|
+
})
|
|
267
|
+
},
|
|
268
|
+
ping: async () => {
|
|
269
|
+
await melody.sendMessage(m.key.remoteJid!, { text: '🏓 Pong!' })
|
|
270
|
+
},
|
|
271
|
+
info: async () => {
|
|
272
|
+
await melody.sendMessage(m.key.remoteJid!, {
|
|
273
|
+
text: `📌 JID: ${m.key.remoteJid}\n👤 Sender: ${m.key.participant ?? m.key.remoteJid}`
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
await commands[cmd.toLowerCase()]?.()
|
|
279
|
+
})
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## ⚙️ Configuración Avanzada
|
|
285
|
+
|
|
286
|
+
### JavaScript
|
|
287
|
+
```javascript
|
|
288
|
+
const melody = makeWASocket({
|
|
289
|
+
auth: state,
|
|
290
|
+
printQRInTerminal: true,
|
|
291
|
+
markOnlineOnConnect: false,
|
|
292
|
+
browser: ["Delta", "Chrome", "1.0.0"],
|
|
293
|
+
logger: require('pino')({ level: 'silent' }),
|
|
294
|
+
syncFullHistory: false,
|
|
295
|
+
generateHighQualityLinkPreview: true
|
|
296
|
+
})
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### TypeScript
|
|
300
|
+
```typescript
|
|
301
|
+
import pino from 'pino'
|
|
302
|
+
|
|
303
|
+
const melody = makeWASocket({
|
|
304
|
+
auth: state,
|
|
305
|
+
printQRInTerminal: true,
|
|
306
|
+
markOnlineOnConnect: false,
|
|
307
|
+
browser: ["Delta", "Chrome", "1.0.0"] as [string, string, string],
|
|
308
|
+
logger: pino({ level: 'silent' }),
|
|
309
|
+
syncFullHistory: false,
|
|
310
|
+
generateHighQualityLinkPreview: true
|
|
311
|
+
})
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## 🛠️ Funciones Útiles
|
|
317
|
+
|
|
318
|
+
### Broadcast a múltiples chats
|
|
319
|
+
```javascript
|
|
320
|
+
async function broadcastMessage(jids, message) {
|
|
321
|
+
for (const jid of jids) {
|
|
322
|
+
await melody.sendMessage(jid, { text: message })
|
|
323
|
+
await new Promise(r => setTimeout(r, 1000)) // delay para evitar ban
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Descargar medios recibidos
|
|
329
|
+
```javascript
|
|
330
|
+
const { downloadMediaMessage } = require('@Fer280809/Baileys')
|
|
331
|
+
|
|
332
|
+
melody.ev.on('messages.upsert', async ({ messages }) => {
|
|
333
|
+
const m = messages[0]
|
|
334
|
+
if (!m.message?.imageMessage) return
|
|
335
|
+
|
|
336
|
+
const buffer = await downloadMediaMessage(m, 'buffer', {})
|
|
337
|
+
require('fs').writeFileSync('./imagen_recibida.jpg', buffer)
|
|
338
|
+
console.log('✅ Imagen guardada')
|
|
339
|
+
})
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Obtener info de un grupo
|
|
343
|
+
```javascript
|
|
344
|
+
const metadata = await melody.groupMetadata(jid)
|
|
345
|
+
console.log('Nombre:', metadata.subject)
|
|
346
|
+
console.log('Participantes:', metadata.participants.length)
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Mencionar usuarios en un grupo
|
|
350
|
+
```javascript
|
|
351
|
+
await melody.sendMessage(jid, {
|
|
352
|
+
text: '@1234567890 ¡Hola!',
|
|
353
|
+
mentions: ['1234567890@s.whatsapp.net']
|
|
354
|
+
})
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## 📘 TypeScript — Tipos Personalizados
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
import makeWASocket, { WASocket, proto } from '@Fer280809/Baileys'
|
|
363
|
+
|
|
364
|
+
// Tipo para un mensaje con datos del remitente
|
|
365
|
+
type MessageWithSender = proto.IWebMessageInfo & {
|
|
366
|
+
senderName?: string
|
|
367
|
+
isGroup?: boolean
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Función tipada para procesar mensajes
|
|
371
|
+
async function processMessage(
|
|
372
|
+
sock: WASocket,
|
|
373
|
+
msg: MessageWithSender
|
|
374
|
+
): Promise<void> {
|
|
375
|
+
const jid = msg.key.remoteJid!
|
|
376
|
+
const text = msg.message?.conversation ?? ''
|
|
377
|
+
|
|
378
|
+
if (text === '!tipo') {
|
|
379
|
+
await sock.sendMessage(jid, {
|
|
380
|
+
text: `Tipo de chat: ${msg.isGroup ? 'Grupo' : 'Privado'}`
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## 📁 Estructura Recomendada del Proyecto
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
mi-bot/
|
|
392
|
+
├── index.js # Entrada principal
|
|
393
|
+
├── config.js # Configuración general
|
|
394
|
+
├── commands/
|
|
395
|
+
│ ├── hola.js
|
|
396
|
+
│ ├── ping.js
|
|
397
|
+
│ └── stickers.js
|
|
398
|
+
├── events/
|
|
399
|
+
│ ├── messages.js
|
|
400
|
+
│ └── connection.js
|
|
401
|
+
├── utils/
|
|
402
|
+
│ └── helpers.js
|
|
403
|
+
└── session-mymelody/ # Sesión guardada automáticamente
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
## 🔗 Links
|
|
409
|
+
|
|
410
|
+
- 📦 Repositorio: [github.com/Fer280809/Baileys](https://github.com/Fer280809/Baileys)
|
|
411
|
+
- 🐛 Issues: [github.com/Fer280809/Baileys/issues](https://github.com/Fer280809/Baileys/issues)
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
<div align="center">
|
|
416
|
+
|
|
417
|
+
Desarrollado con 🤍 por [Fer280809](https://github.com/Fer280809)
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
## Creditos a Melody-Xz
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
</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;
|