@arcaelas/whatsapp 4.4.0 → 5.1.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/build/cjs/index.d.ts +6 -4
- package/build/cjs/index.js +22 -2
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/lib/bot/decorator.d.ts +2 -0
- package/build/cjs/lib/bot/decorator.js +6 -0
- package/build/cjs/lib/bot/decorator.js.map +1 -1
- package/build/cjs/lib/chat/index.d.ts +340 -204
- package/build/cjs/lib/chat/index.js +225 -213
- package/build/cjs/lib/chat/index.js.map +1 -1
- package/build/cjs/lib/contact/index.d.ts +162 -179
- package/build/cjs/lib/contact/index.js +96 -190
- package/build/cjs/lib/contact/index.js.map +1 -1
- package/build/cjs/lib/internal.d.ts +40 -0
- package/build/cjs/lib/internal.js +39 -0
- package/build/cjs/lib/internal.js.map +1 -0
- package/build/cjs/lib/message/index.d.ts +463 -278
- package/build/cjs/lib/message/index.js +830 -710
- package/build/cjs/lib/message/index.js.map +1 -1
- package/build/cjs/lib/status/index.d.ts +60 -70
- package/build/cjs/lib/status/index.js +106 -111
- package/build/cjs/lib/status/index.js.map +1 -1
- package/build/cjs/lib/store/engine/index.d.ts +21 -7
- package/build/cjs/lib/store/engine/index.js +6 -3
- package/build/cjs/lib/store/engine/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +38 -8
- package/build/cjs/lib/store/engine/lib/file_system/index.js +92 -67
- package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/index.d.ts +112 -0
- package/build/cjs/lib/store/engine/lib/index.js +213 -0
- package/build/cjs/lib/store/engine/lib/index.js.map +1 -0
- package/build/cjs/lib/store/engine/lib/redis/index.d.ts +28 -13
- package/build/cjs/lib/store/engine/lib/redis/index.js +56 -42
- package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/cjs/lib/store/engine/lib/s3/index.js +112 -64
- package/build/cjs/lib/store/engine/lib/s3/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +98 -0
- package/build/cjs/lib/store/engine/lib/sqlite/index.js +114 -0
- package/build/cjs/lib/store/engine/lib/sqlite/index.js.map +1 -0
- package/build/cjs/lib/store/index.d.ts +7 -3
- package/build/cjs/lib/store/index.js +14 -4
- package/build/cjs/lib/store/index.js.map +1 -1
- package/build/cjs/lib/whatsapp/index.d.ts +117 -63
- package/build/cjs/lib/whatsapp/index.js +404 -184
- package/build/cjs/lib/whatsapp/index.js.map +1 -1
- package/build/cjs/test.d.ts +1 -0
- package/build/cjs/test.js +72 -0
- package/build/cjs/test.js.map +1 -0
- package/build/esm/index.d.ts +6 -4
- package/build/esm/index.js +5 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/lib/bot/decorator.d.ts +2 -0
- package/build/esm/lib/bot/decorator.js +6 -0
- package/build/esm/lib/bot/decorator.js.map +1 -1
- package/build/esm/lib/chat/index.d.ts +340 -204
- package/build/esm/lib/chat/index.js +225 -213
- package/build/esm/lib/chat/index.js.map +1 -1
- package/build/esm/lib/contact/index.d.ts +162 -179
- package/build/esm/lib/contact/index.js +96 -189
- package/build/esm/lib/contact/index.js.map +1 -1
- package/build/esm/lib/internal.d.ts +40 -0
- package/build/esm/lib/internal.js +35 -0
- package/build/esm/lib/internal.js.map +1 -0
- package/build/esm/lib/message/index.d.ts +463 -278
- package/build/esm/lib/message/index.js +825 -705
- package/build/esm/lib/message/index.js.map +1 -1
- package/build/esm/lib/status/index.d.ts +60 -70
- package/build/esm/lib/status/index.js +105 -110
- package/build/esm/lib/status/index.js.map +1 -1
- package/build/esm/lib/store/engine/index.d.ts +21 -7
- package/build/esm/lib/store/engine/index.js +4 -2
- package/build/esm/lib/store/engine/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/file_system/index.d.ts +38 -8
- package/build/esm/lib/store/engine/lib/file_system/index.js +92 -67
- package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/index.d.ts +112 -0
- package/build/esm/lib/store/engine/lib/index.js +206 -0
- package/build/esm/lib/store/engine/lib/index.js.map +1 -0
- package/build/esm/lib/store/engine/lib/redis/index.d.ts +28 -13
- package/build/esm/lib/store/engine/lib/redis/index.js +54 -40
- package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/esm/lib/store/engine/lib/s3/index.js +111 -63
- package/build/esm/lib/store/engine/lib/s3/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +98 -0
- package/build/esm/lib/store/engine/lib/sqlite/index.js +110 -0
- package/build/esm/lib/store/engine/lib/sqlite/index.js.map +1 -0
- package/build/esm/lib/store/index.d.ts +7 -3
- package/build/esm/lib/store/index.js +13 -4
- package/build/esm/lib/store/index.js.map +1 -1
- package/build/esm/lib/whatsapp/index.d.ts +117 -63
- package/build/esm/lib/whatsapp/index.js +406 -186
- package/build/esm/lib/whatsapp/index.js.map +1 -1
- package/build/esm/test.d.ts +1 -0
- package/build/esm/test.js +67 -0
- package/build/esm/test.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file message/index.ts
|
|
3
|
-
* @description Entidad Message —
|
|
4
|
-
*
|
|
3
|
+
* @description Entidad Message — clase base con getters puros y subclases por tipo
|
|
4
|
+
* (Text, Image, Video, Audio, Sticker, Document, Location, Poll, VCard, Event);
|
|
5
|
+
* `message(wa, raw)` evalúa el tipo y retorna la instancia correcta.
|
|
6
|
+
* Message entity — pure-getter base class with per-type subclasses;
|
|
7
|
+
* `message(wa, raw)` evaluates the type and returns the right instance.
|
|
5
8
|
*/
|
|
6
9
|
import { aesEncryptGCM, downloadMediaMessage, generateForwardMessageContent, generateMessageID, generateWAMessageFromContent, getAggregateVotesInPollMessage, getContentType, getKeyAuthor, hmacSign, jidNormalizedUser, proto, sha256, updateMessageWithPollUpdate, } from 'baileys';
|
|
7
10
|
import { randomBytes } from 'node:crypto';
|
|
8
11
|
import { Readable } from 'node:stream';
|
|
12
|
+
import { internals } from '../../lib/internal.js';
|
|
9
13
|
import { Chat } from '../../lib/chat/index.js';
|
|
10
14
|
import { deserialize, serialize } from '../../lib/store/index.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
MessageStatus[MessageStatus["ERROR"] = 0] = "ERROR";
|
|
14
|
-
MessageStatus[MessageStatus["PENDING"] = 1] = "PENDING";
|
|
15
|
-
MessageStatus[MessageStatus["SERVER_ACK"] = 2] = "SERVER_ACK";
|
|
16
|
-
MessageStatus[MessageStatus["DELIVERED"] = 3] = "DELIVERED";
|
|
17
|
-
MessageStatus[MessageStatus["READ"] = 4] = "READ";
|
|
18
|
-
MessageStatus[MessageStatus["PLAYED"] = 5] = "PLAYED";
|
|
19
|
-
})(MessageStatus || (MessageStatus = {}));
|
|
15
|
+
/** Estados legibles indexados por el status numérico de baileys. / Readable states indexed by the baileys numeric status. */
|
|
16
|
+
const STATUS = ['error', 'pending', 'sent', 'delivered', 'read', 'played'];
|
|
20
17
|
const MESSAGE_TYPE_MAP = {
|
|
21
18
|
conversation: 'text',
|
|
22
19
|
extendedTextMessage: 'text',
|
|
23
20
|
imageMessage: 'image',
|
|
24
21
|
videoMessage: 'video',
|
|
25
22
|
audioMessage: 'audio',
|
|
23
|
+
stickerMessage: 'sticker',
|
|
26
24
|
locationMessage: 'location',
|
|
27
25
|
liveLocationMessage: 'location',
|
|
28
26
|
pollCreationMessage: 'poll',
|
|
@@ -35,292 +33,407 @@ const MESSAGE_TYPE_MAP = {
|
|
|
35
33
|
eventMessage: 'event',
|
|
36
34
|
};
|
|
37
35
|
/**
|
|
38
|
-
*
|
|
36
|
+
* Desenvuelve los wrappers de contenido (view-once, documento con caption).
|
|
37
|
+
* Unwraps content wrappers (view-once, captioned document).
|
|
39
38
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const msg = raw.message ?? {};
|
|
43
|
-
const unwrapped = msg.viewOnceMessage?.message ??
|
|
39
|
+
function unwrap(msg) {
|
|
40
|
+
return (msg.viewOnceMessage?.message ??
|
|
44
41
|
msg.viewOnceMessageV2?.message ??
|
|
45
42
|
msg.viewOnceMessageV2Extension?.message ??
|
|
46
43
|
msg.documentWithCaptionMessage?.message ??
|
|
47
|
-
msg;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
44
|
+
msg);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Convierte un número o Long del proto a number plano.
|
|
48
|
+
* Converts a proto number or Long into a plain number.
|
|
49
|
+
*/
|
|
50
|
+
function to_number(value) {
|
|
51
|
+
return Number(value?.toString() ?? 0);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Convierte los bytes del proto (Uint8Array runtime o base64 post-engine) a Buffer.
|
|
55
|
+
* Converts proto bytes (runtime Uint8Array or post-engine base64) into a Buffer.
|
|
56
|
+
*/
|
|
57
|
+
function to_buffer(value) {
|
|
58
|
+
if (value instanceof Uint8Array && value.length > 0)
|
|
59
|
+
return Buffer.from(value);
|
|
60
|
+
if (typeof value === 'string' && value.length > 0)
|
|
61
|
+
return Buffer.from(value, 'base64');
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Envío base: resuelve el destino, cita si hay `mid`, marca view-once, persiste el doc
|
|
66
|
+
* (con su binario cuando aplica) y retorna la instancia del mensaje enviado.
|
|
67
|
+
* Base send: resolves the target, quotes when `mid` is given, flags view-once, persists
|
|
68
|
+
* the doc (with its binary when it applies) and returns the sent message instance.
|
|
69
|
+
*/
|
|
70
|
+
async function send(wa, cid, content, binary, extra = {}, doc_overrides) {
|
|
71
|
+
let result = null;
|
|
72
|
+
const jid = await internals(wa).resolve_jid(cid);
|
|
73
|
+
const socket = internals(wa).socket;
|
|
74
|
+
if (jid && socket) {
|
|
75
|
+
const quoted = extra.mid
|
|
76
|
+
? (deserialize(await wa.engine.get(`/chat/${jid}/message/${extra.mid}`))?.raw ?? undefined)
|
|
77
|
+
: undefined;
|
|
78
|
+
const raw = await socket.sendMessage(jid, {
|
|
79
|
+
...content,
|
|
80
|
+
...(extra.once && { viewOnce: true }),
|
|
81
|
+
...(quoted && { quoted }),
|
|
82
|
+
});
|
|
83
|
+
const sent_id = raw?.key?.id;
|
|
84
|
+
if (raw && sent_id) {
|
|
85
|
+
const instance = message(wa, raw);
|
|
86
|
+
if (doc_overrides) {
|
|
87
|
+
Object.assign(instance._raw, doc_overrides);
|
|
88
|
+
}
|
|
89
|
+
await wa.engine.set(`/chat/${jid}/message/${sent_id}`, serialize(instance._raw), instance._raw.created_at);
|
|
90
|
+
if (binary) {
|
|
91
|
+
await wa.engine.set(`/chat/${jid}/message/${sent_id}/content`, serialize({ data: binary.toString('base64') }));
|
|
92
|
+
}
|
|
93
|
+
result = instance;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Stream del binario del mensaje: cache del engine o descarga de baileys.
|
|
100
|
+
* Message binary stream: engine cache or baileys download.
|
|
101
|
+
*/
|
|
102
|
+
async function media_stream(wa, doc) {
|
|
103
|
+
const cached = deserialize(await wa.engine.get(`/chat/${doc.cid}/message/${doc.id}/content`));
|
|
104
|
+
if (cached?.data) {
|
|
105
|
+
return Readable.from(Buffer.from(cached.data, 'base64'));
|
|
106
|
+
}
|
|
107
|
+
const socket = internals(wa).socket;
|
|
108
|
+
if (socket) {
|
|
109
|
+
try {
|
|
110
|
+
return (await downloadMediaMessage(doc.raw, 'stream', {}));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
/* media may be expired */
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return Readable.from(Buffer.alloc(0));
|
|
102
117
|
}
|
|
103
118
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
119
|
+
* Acumula un Readable en Buffer.
|
|
120
|
+
* Drains a Readable into a Buffer.
|
|
121
|
+
*/
|
|
122
|
+
async function drain(readable) {
|
|
123
|
+
const chunks = [];
|
|
124
|
+
for await (const chunk of readable) {
|
|
125
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
126
|
+
}
|
|
127
|
+
return Buffer.concat(chunks);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Clase base del mensaje: recibe el cliente y el raw, deriva el estado con getters y
|
|
131
|
+
* opera contra WhatsApp con sus métodos. Los estáticos reciben el cliente como primer
|
|
132
|
+
* argumento (`Message.text(wa, cid, …)`).
|
|
133
|
+
* Base message class: receives the client and the raw, derives state via getters and
|
|
134
|
+
* operates against WhatsApp with its methods. Statics take the client as their first
|
|
135
|
+
* argument (`Message.text(wa, cid, …)`).
|
|
106
136
|
*/
|
|
107
137
|
export class Message {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
138
|
+
/**
|
|
139
|
+
* @internal Cliente dueño y documento persistido. `status`, `created_at` y
|
|
140
|
+
* `deleted_at` guardan los valores numéricos del protocolo; los getters los
|
|
141
|
+
* presentan legibles. `viewed` existe únicamente en los status broadcast (Feed).
|
|
142
|
+
* Owner client and persisted document. `status`, `created_at` and `deleted_at`
|
|
143
|
+
* keep the protocol numeric values; getters expose them readable. `viewed` only
|
|
144
|
+
* exists on status broadcasts (Feed).
|
|
145
|
+
*/
|
|
146
|
+
constructor(_wa, _raw) {
|
|
147
|
+
this._wa = _wa;
|
|
148
|
+
this._raw = _raw;
|
|
115
149
|
}
|
|
150
|
+
/** Identificador del mensaje. / Message identifier. */
|
|
116
151
|
get id() {
|
|
117
|
-
return this.
|
|
152
|
+
return this._raw.id;
|
|
118
153
|
}
|
|
154
|
+
/** Identificador del chat del mensaje. / Message chat identifier. */
|
|
119
155
|
get cid() {
|
|
120
|
-
return this.
|
|
156
|
+
return this._raw.cid;
|
|
121
157
|
}
|
|
122
|
-
|
|
123
|
-
|
|
158
|
+
/** Identificador del mensaje citado, o null. / Quoted message identifier, or null. */
|
|
159
|
+
get mid() {
|
|
160
|
+
return this._raw.mid;
|
|
124
161
|
}
|
|
125
|
-
/** JID del autor
|
|
162
|
+
/** JID del autor, para acceso síncrono. / Author JID, for sync access. */
|
|
126
163
|
get from() {
|
|
127
|
-
return this.
|
|
128
|
-
}
|
|
129
|
-
/** MIME type del contenido. `text/plain` para texto, `application/json` para location/poll, mimetype real para media. */
|
|
130
|
-
get mime() {
|
|
131
|
-
return this._doc.mime;
|
|
132
|
-
}
|
|
133
|
-
get mid() {
|
|
134
|
-
return this._doc.mid;
|
|
164
|
+
return this._raw.author;
|
|
135
165
|
}
|
|
166
|
+
/** true si soy el autor. / true when I am the author. */
|
|
136
167
|
get me() {
|
|
137
|
-
return this.
|
|
168
|
+
return this._raw.me;
|
|
169
|
+
}
|
|
170
|
+
/** Tipo del mensaje. / Message type. */
|
|
171
|
+
get type() {
|
|
172
|
+
return this._raw.type;
|
|
138
173
|
}
|
|
174
|
+
/** MIME: text/plain en texto, text/json en poll/location/vcard/event, real en media. / MIME: text/plain for text, text/json for poll/location/vcard/event, actual for media. */
|
|
175
|
+
get mime() {
|
|
176
|
+
const { type } = this._raw;
|
|
177
|
+
if (type === 'text')
|
|
178
|
+
return 'text/plain';
|
|
179
|
+
if (type === 'poll' || type === 'location' || type === 'vcard' || type === 'event')
|
|
180
|
+
return 'text/json';
|
|
181
|
+
return this._raw.mime;
|
|
182
|
+
}
|
|
183
|
+
/** Texto del mensaje o caption del media. / Message text or media caption. */
|
|
139
184
|
get caption() {
|
|
140
|
-
return this.
|
|
185
|
+
return this._raw.caption;
|
|
186
|
+
}
|
|
187
|
+
/** Estado legible del mensaje. / Readable message state. */
|
|
188
|
+
get status() {
|
|
189
|
+
return STATUS[this._raw.status] ?? 'pending';
|
|
190
|
+
}
|
|
191
|
+
/** true si el mensaje fue visto. / true when the message was seen. */
|
|
192
|
+
get read() {
|
|
193
|
+
return this._raw.status >= 4;
|
|
141
194
|
}
|
|
195
|
+
/** true si está destacado. / true when starred. */
|
|
142
196
|
get starred() {
|
|
143
|
-
return this.
|
|
197
|
+
return this._raw.starred;
|
|
144
198
|
}
|
|
199
|
+
/** true si fue reenviado. / true when forwarded. */
|
|
145
200
|
get forwarded() {
|
|
146
|
-
return this.
|
|
201
|
+
return this._raw.forwarded;
|
|
147
202
|
}
|
|
203
|
+
/** true si fue editado. / true when edited. */
|
|
204
|
+
get edited() {
|
|
205
|
+
return this._raw.edited;
|
|
206
|
+
}
|
|
207
|
+
/** true si es de una sola lectura (view-once). / true when view-once. */
|
|
148
208
|
get once() {
|
|
149
|
-
|
|
209
|
+
const msg = this._raw.raw.message;
|
|
210
|
+
return Boolean(msg?.viewOnceMessage ?? msg?.viewOnceMessageV2 ?? msg?.viewOnceMessageV2Extension);
|
|
150
211
|
}
|
|
212
|
+
/** Fecha de creación en ISO UTC. / Creation date as ISO UTC. */
|
|
151
213
|
get created_at() {
|
|
152
|
-
return this.
|
|
153
|
-
}
|
|
154
|
-
get deleted_at() {
|
|
155
|
-
return this._doc.deleted_at;
|
|
156
|
-
}
|
|
157
|
-
get status() {
|
|
158
|
-
return this._doc.status;
|
|
214
|
+
return new Date(this._raw.created_at).toISOString();
|
|
159
215
|
}
|
|
160
|
-
|
|
161
|
-
|
|
216
|
+
/** Vencimiento del mensaje temporal en ISO UTC, o null. / Ephemeral expiration as ISO UTC, or null. */
|
|
217
|
+
get expires_at() {
|
|
218
|
+
return this._raw.deleted_at != null ? new Date(this._raw.deleted_at).toISOString() : null;
|
|
162
219
|
}
|
|
163
220
|
/**
|
|
164
|
-
* Contacto del
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* Instance-memoized: first call hits the engine; subsequent calls reuse the
|
|
169
|
-
* same promise without further round-trips.
|
|
221
|
+
* Contacto autor del mensaje, desde el engine (ficha mínima si no está persistido).
|
|
222
|
+
* Message author contact, from the engine (minimal card when not persisted).
|
|
223
|
+
*
|
|
224
|
+
* @returns Contacto / Contact
|
|
170
225
|
*/
|
|
171
226
|
async author() {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const fetched = _doc.author ? await _wa.Contact.get(_doc.author) : null;
|
|
175
|
-
return (fetched ??
|
|
176
|
-
new _wa.Contact({
|
|
177
|
-
id: _doc.author,
|
|
178
|
-
lid: null,
|
|
179
|
-
name: null,
|
|
180
|
-
notify: null,
|
|
181
|
-
verified_name: null,
|
|
182
|
-
img_url: null,
|
|
183
|
-
status: null,
|
|
184
|
-
}, new _wa.Chat({ id: _doc.author, name: _doc.author.split('@')[0] })));
|
|
185
|
-
})());
|
|
227
|
+
const cached = deserialize(await this._wa.engine.get(`/contact/${this._raw.author}`));
|
|
228
|
+
return new this._wa.Contact(cached ?? { id: this._raw.author });
|
|
186
229
|
}
|
|
187
230
|
/**
|
|
188
|
-
* Chat al que pertenece el mensaje.
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
231
|
+
* Chat al que pertenece el mensaje.
|
|
232
|
+
* Chat the message belongs to.
|
|
233
|
+
*
|
|
234
|
+
* @returns Chat / Chat
|
|
192
235
|
*/
|
|
193
236
|
async chat() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
237
|
+
const cached = deserialize(await this._wa.engine.get(`/chat/${this._raw.cid}`));
|
|
238
|
+
return new this._wa.Chat(cached ?? { id: this._raw.cid });
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Mensaje citado cuando hay `mid`, o null.
|
|
242
|
+
* Quoted message when `mid` exists, or null.
|
|
243
|
+
*
|
|
244
|
+
* @returns Mensaje citado o null / Quoted message or null
|
|
245
|
+
*/
|
|
246
|
+
async message() {
|
|
247
|
+
return this._raw.mid ? Message.get(this._wa, this._raw.cid, this._raw.mid) : null;
|
|
198
248
|
}
|
|
199
|
-
/**
|
|
249
|
+
/**
|
|
250
|
+
* Contenido del mensaje: texto como su caption, media como binario, y
|
|
251
|
+
* poll/location/vcard/event como JSON.
|
|
252
|
+
* Message content: text as its caption, media as binary, and
|
|
253
|
+
* poll/location/vcard/event as JSON.
|
|
254
|
+
*
|
|
255
|
+
* @returns Buffer del contenido / Content buffer
|
|
256
|
+
*/
|
|
200
257
|
async content() {
|
|
201
|
-
const cached = deserialize(await this._wa.engine.get(`/chat/${this.
|
|
258
|
+
const cached = deserialize(await this._wa.engine.get(`/chat/${this._raw.cid}/message/${this._raw.id}/content`));
|
|
202
259
|
return cached?.data ? Buffer.from(cached.data, 'base64') : Buffer.alloc(0);
|
|
203
260
|
}
|
|
204
261
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* from the engine cache or, if missing, downloads from baileys. For text/location/poll
|
|
210
|
-
* it wraps the `content()` buffer in a Readable.
|
|
262
|
+
* Stream del contenido; para media descarga de baileys si el cache falta.
|
|
263
|
+
* Content stream; media falls back to a baileys download when the cache is missing.
|
|
264
|
+
*
|
|
265
|
+
* @returns Readable del contenido / Content readable
|
|
211
266
|
*/
|
|
212
267
|
async stream() {
|
|
213
|
-
return
|
|
268
|
+
return media_stream(this._wa, this._raw);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Reacciones del mensaje agrupadas por emoji con su conteo.
|
|
272
|
+
* Message reactions grouped by emoji with their count.
|
|
273
|
+
*
|
|
274
|
+
* @returns Conteo por emoji / Per-emoji count
|
|
275
|
+
*/
|
|
276
|
+
async reactions() {
|
|
277
|
+
const counts = new Map();
|
|
278
|
+
for (const { emoji } of this._raw.reactions ?? []) {
|
|
279
|
+
counts.set(emoji, (counts.get(emoji) ?? 0) + 1);
|
|
280
|
+
}
|
|
281
|
+
return [...counts.entries()].map(([emoji, count]) => ({ emoji, count }));
|
|
214
282
|
}
|
|
215
|
-
/**
|
|
283
|
+
/**
|
|
284
|
+
* Reacciona al mensaje; el emoji vacío retira la reacción.
|
|
285
|
+
* Reacts to the message; an empty emoji removes the reaction.
|
|
286
|
+
*
|
|
287
|
+
* @param emoji - Emoji o '' / Emoji or ''
|
|
288
|
+
* @returns true si se envió / true when sent
|
|
289
|
+
*/
|
|
216
290
|
async react(emoji) {
|
|
217
|
-
const { _wa, _doc } = this;
|
|
218
291
|
let ok = false;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
292
|
+
const socket = internals(this._wa).socket;
|
|
293
|
+
if (socket) {
|
|
294
|
+
const { cid, id, me, author } = this._raw;
|
|
295
|
+
await socket.sendMessage(cid, {
|
|
296
|
+
react: {
|
|
297
|
+
text: emoji,
|
|
298
|
+
key: { remoteJid: cid, id, fromMe: me, ...(cid.endsWith('@g.us') && !me && { participant: author }) },
|
|
299
|
+
},
|
|
222
300
|
});
|
|
223
301
|
ok = true;
|
|
224
302
|
}
|
|
225
303
|
return ok;
|
|
226
304
|
}
|
|
227
|
-
/**
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
305
|
+
/**
|
|
306
|
+
* Destaca o quita el destacado del mensaje.
|
|
307
|
+
* Stars or unstars the message.
|
|
308
|
+
*
|
|
309
|
+
* @param value - true destaca / true stars
|
|
310
|
+
* @returns true si se envió / true when sent
|
|
311
|
+
*/
|
|
312
|
+
async star(value) {
|
|
235
313
|
let ok = false;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
await _wa._socket.relayMessage(jid, wa_msg.message, { messageId: wa_msg.key.id });
|
|
244
|
-
ok = true;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch {
|
|
248
|
-
/* fallback below */
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if (!ok) {
|
|
252
|
-
const buf = await this.content();
|
|
253
|
-
if (buf.length > 0) {
|
|
254
|
-
if (_doc.type === 'text') {
|
|
255
|
-
ok = (await _wa.Message.text(jid, buf.toString())) !== null;
|
|
256
|
-
}
|
|
257
|
-
else if (_doc.type === 'image') {
|
|
258
|
-
ok =
|
|
259
|
-
(await _wa.Message.image(jid, buf, { caption: _doc.caption || undefined })) !==
|
|
260
|
-
null;
|
|
261
|
-
}
|
|
262
|
-
else if (_doc.type === 'video') {
|
|
263
|
-
ok =
|
|
264
|
-
(await _wa.Message.video(jid, buf, { caption: _doc.caption || undefined })) !==
|
|
265
|
-
null;
|
|
266
|
-
}
|
|
267
|
-
else if (_doc.type === 'audio') {
|
|
268
|
-
ok = (await _wa.Message.audio(jid, buf)) !== null;
|
|
269
|
-
}
|
|
270
|
-
else if (_doc.type === 'location') {
|
|
271
|
-
try {
|
|
272
|
-
ok =
|
|
273
|
-
(await _wa.Message.location(jid, JSON.parse(buf.toString()))) !== null;
|
|
274
|
-
}
|
|
275
|
-
catch {
|
|
276
|
-
/* invalid payload */
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
314
|
+
const socket = internals(this._wa).socket;
|
|
315
|
+
if (socket) {
|
|
316
|
+
const doc = this._raw;
|
|
317
|
+
await socket.chatModify({ star: { messages: [{ id: doc.id, fromMe: doc.me }], star: value } }, doc.cid);
|
|
318
|
+
doc.starred = value;
|
|
319
|
+
await this._wa.engine.set(`/chat/${doc.cid}/message/${doc.id}`, serialize(doc), doc.created_at);
|
|
320
|
+
ok = true;
|
|
282
321
|
}
|
|
283
322
|
return ok;
|
|
284
323
|
}
|
|
285
|
-
/**
|
|
324
|
+
/**
|
|
325
|
+
* Marca el mensaje como leído.
|
|
326
|
+
* Marks the message as read.
|
|
327
|
+
*
|
|
328
|
+
* @returns true si se envió / true when sent
|
|
329
|
+
*/
|
|
286
330
|
async seen() {
|
|
287
|
-
const { _wa, _doc } = this;
|
|
288
331
|
let ok = false;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
332
|
+
const socket = internals(this._wa).socket;
|
|
333
|
+
if (socket) {
|
|
334
|
+
const { cid, id, author } = this._raw;
|
|
335
|
+
await socket.readMessages([
|
|
336
|
+
{ remoteJid: cid, id, participant: cid.endsWith('@g.us') ? author : undefined },
|
|
293
337
|
]);
|
|
294
338
|
ok = true;
|
|
295
339
|
}
|
|
296
340
|
return ok;
|
|
297
341
|
}
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Edita el caption del mensaje propio (texto, imagen o video).
|
|
344
|
+
* Edits the own message caption (text, image or video).
|
|
345
|
+
*
|
|
346
|
+
* @param caption - Texto nuevo / New text
|
|
347
|
+
* @returns true si se editó / true when edited
|
|
348
|
+
*/
|
|
349
|
+
async edit(caption) {
|
|
350
|
+
const doc = this._raw;
|
|
301
351
|
let ok = false;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
352
|
+
const socket = internals(this._wa).socket;
|
|
353
|
+
if (socket && doc.me) {
|
|
354
|
+
if (doc.type === 'text') {
|
|
355
|
+
await socket.sendMessage(doc.cid, {
|
|
356
|
+
text: caption,
|
|
357
|
+
edit: { remoteJid: doc.cid, id: doc.id, fromMe: true },
|
|
358
|
+
});
|
|
359
|
+
const content_type = getContentType(doc.raw.message ?? {});
|
|
360
|
+
doc.raw.message =
|
|
361
|
+
content_type === 'conversation' ? { conversation: caption } : { extendedTextMessage: { text: caption } };
|
|
362
|
+
ok = true;
|
|
363
|
+
}
|
|
364
|
+
else if (doc.type === 'image' || doc.type === 'video') {
|
|
365
|
+
const media_key = doc.type === 'image' ? 'imageMessage' : 'videoMessage';
|
|
366
|
+
const media = doc.raw.message?.[media_key];
|
|
367
|
+
if (media) {
|
|
368
|
+
const edited = { [media_key]: { ...media, caption } };
|
|
369
|
+
await socket.relayMessage(doc.cid, {
|
|
370
|
+
protocolMessage: {
|
|
371
|
+
key: { remoteJid: doc.cid, id: doc.id, fromMe: true },
|
|
372
|
+
type: proto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
|
|
373
|
+
editedMessage: edited,
|
|
374
|
+
timestampMs: Date.now(),
|
|
375
|
+
},
|
|
376
|
+
}, { messageId: generateMessageID() });
|
|
377
|
+
doc.raw.message = { ...doc.raw.message, ...edited };
|
|
378
|
+
ok = true;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (ok) {
|
|
382
|
+
doc.caption = caption;
|
|
383
|
+
doc.edited = true;
|
|
384
|
+
await this._wa.engine.set(`/chat/${doc.cid}/message/${doc.id}`, serialize(doc), doc.created_at);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return ok;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Reenvía el mensaje a otro chat.
|
|
391
|
+
* Forwards the message to another chat.
|
|
392
|
+
*
|
|
393
|
+
* @param target - CID, Chat o Contact destino / Target CID, Chat or Contact
|
|
394
|
+
* @returns true si se reenvió / true when forwarded
|
|
395
|
+
*/
|
|
396
|
+
async forward(target) {
|
|
397
|
+
const doc = this._raw;
|
|
398
|
+
const to_cid = typeof target === 'string' ? target : target instanceof Chat ? target._raw.id : (target.jid ?? target.lid ?? '');
|
|
399
|
+
let ok = false;
|
|
400
|
+
const socket = internals(this._wa).socket;
|
|
401
|
+
if (socket && to_cid) {
|
|
402
|
+
const jid = await internals(this._wa).resolve_jid(to_cid);
|
|
403
|
+
if (jid && doc.raw.message) {
|
|
404
|
+
try {
|
|
405
|
+
const wa_msg = generateWAMessageFromContent(jid, generateForwardMessageContent(doc.raw, false), {
|
|
406
|
+
userJid: socket.user?.id ?? '',
|
|
407
|
+
});
|
|
408
|
+
if (wa_msg.message && wa_msg.key?.id) {
|
|
409
|
+
await socket.relayMessage(jid, wa_msg.message, { messageId: wa_msg.key.id });
|
|
410
|
+
ok = true;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
/* forward content may be unsupported */
|
|
415
|
+
}
|
|
416
|
+
}
|
|
309
417
|
}
|
|
310
418
|
return ok;
|
|
311
419
|
}
|
|
312
|
-
/**
|
|
313
|
-
|
|
314
|
-
|
|
420
|
+
/**
|
|
421
|
+
* Elimina el mensaje: solo en mi dispositivo por defecto, para todos con `true`.
|
|
422
|
+
* Deletes the message: this device only by default, for everyone with `true`.
|
|
423
|
+
*
|
|
424
|
+
* @param all - true elimina para todos / true deletes for everyone
|
|
425
|
+
* @returns true si se eliminó / true when deleted
|
|
426
|
+
*/
|
|
427
|
+
async delete(all = false) {
|
|
428
|
+
const doc = this._raw;
|
|
315
429
|
let ok = false;
|
|
316
|
-
|
|
430
|
+
const socket = internals(this._wa).socket;
|
|
431
|
+
if (socket) {
|
|
317
432
|
if (all) {
|
|
318
|
-
await
|
|
319
|
-
delete: { remoteJid: doc.cid, id: doc.id, fromMe: doc.me },
|
|
320
|
-
});
|
|
433
|
+
await socket.sendMessage(doc.cid, { delete: { remoteJid: doc.cid, id: doc.id, fromMe: doc.me } });
|
|
321
434
|
}
|
|
322
435
|
else {
|
|
323
|
-
await
|
|
436
|
+
await socket.chatModify({
|
|
324
437
|
deleteForMe: {
|
|
325
438
|
deleteMedia: false,
|
|
326
439
|
key: { remoteJid: doc.cid, id: doc.id, fromMe: doc.me },
|
|
@@ -328,161 +441,361 @@ export class Message {
|
|
|
328
441
|
},
|
|
329
442
|
}, doc.cid);
|
|
330
443
|
}
|
|
331
|
-
await
|
|
444
|
+
await this._wa.engine.unset(`/chat/${doc.cid}/message/${doc.id}`);
|
|
332
445
|
ok = true;
|
|
333
446
|
}
|
|
334
447
|
return ok;
|
|
335
448
|
}
|
|
336
|
-
/**
|
|
337
|
-
async
|
|
338
|
-
|
|
339
|
-
let ok = false;
|
|
340
|
-
if (wa._socket && doc.me) {
|
|
341
|
-
try {
|
|
342
|
-
await wa._socket.sendMessage(doc.cid, {
|
|
343
|
-
text,
|
|
344
|
-
edit: { remoteJid: doc.cid, id: doc.id, fromMe: true },
|
|
345
|
-
});
|
|
346
|
-
const content_type = getContentType(doc.raw.message ?? {});
|
|
347
|
-
if (content_type === 'conversation') {
|
|
348
|
-
doc.raw.message = { conversation: text };
|
|
349
|
-
}
|
|
350
|
-
else if (content_type === 'extendedTextMessage') {
|
|
351
|
-
doc.raw.message = { extendedTextMessage: { text } };
|
|
352
|
-
}
|
|
353
|
-
doc.caption = text;
|
|
354
|
-
doc.edited = true;
|
|
355
|
-
await wa.engine.set(`/chat/${doc.cid}/message/${doc.id}`, serialize(doc));
|
|
356
|
-
ok = true;
|
|
357
|
-
}
|
|
358
|
-
catch {
|
|
359
|
-
ok = false;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return ok;
|
|
449
|
+
/** Responde con texto. / Replies with text. */
|
|
450
|
+
async text(caption, extra = {}) {
|
|
451
|
+
return Message.text(this._wa, this._raw.cid, caption, { ...extra, mid: this._raw.id });
|
|
363
452
|
}
|
|
364
|
-
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const id = this.id;
|
|
368
|
-
return this._wa.on('message:updated', (updated) => {
|
|
369
|
-
if (updated.cid === cid && updated.id === id) {
|
|
370
|
-
handler(updated);
|
|
371
|
-
}
|
|
372
|
-
});
|
|
453
|
+
/** Responde con imagen. / Replies with an image. */
|
|
454
|
+
async image(buf, extra = {}) {
|
|
455
|
+
return Message.image(this._wa, this._raw.cid, buf, { ...extra, mid: this._raw.id });
|
|
373
456
|
}
|
|
374
|
-
/** Responde con
|
|
375
|
-
async
|
|
376
|
-
return this._wa.
|
|
457
|
+
/** Responde con video. / Replies with a video. */
|
|
458
|
+
async video(buf, extra = {}) {
|
|
459
|
+
return Message.video(this._wa, this._raw.cid, buf, { ...extra, mid: this._raw.id });
|
|
377
460
|
}
|
|
378
|
-
/** Responde con
|
|
379
|
-
async
|
|
380
|
-
return this._wa.
|
|
461
|
+
/** Responde con audio. / Replies with audio. */
|
|
462
|
+
async audio(buf, extra = {}) {
|
|
463
|
+
return Message.audio(this._wa, this._raw.cid, buf, { ...extra, mid: this._raw.id });
|
|
381
464
|
}
|
|
382
|
-
/** Responde con
|
|
383
|
-
async
|
|
384
|
-
return this._wa.
|
|
465
|
+
/** Responde con ubicación. / Replies with a location. */
|
|
466
|
+
async location(loc, extra = {}) {
|
|
467
|
+
return Message.location(this._wa, this._raw.cid, loc, { ...extra, mid: this._raw.id });
|
|
385
468
|
}
|
|
386
|
-
/** Responde con
|
|
387
|
-
async
|
|
388
|
-
return this._wa.
|
|
469
|
+
/** Responde con encuesta. / Replies with a poll. */
|
|
470
|
+
async poll(input, extra = {}) {
|
|
471
|
+
return Message.poll(this._wa, this._raw.cid, input, { ...extra, mid: this._raw.id });
|
|
389
472
|
}
|
|
390
|
-
/** Responde con
|
|
391
|
-
async
|
|
392
|
-
return this._wa.
|
|
473
|
+
/** Responde con documento. / Replies with a document. */
|
|
474
|
+
async document(buf, extra) {
|
|
475
|
+
return Message.document(this._wa, this._raw.cid, buf, { ...extra, mid: this._raw.id });
|
|
393
476
|
}
|
|
394
|
-
/** Responde con
|
|
395
|
-
async
|
|
396
|
-
return this._wa.
|
|
477
|
+
/** Responde con tarjeta(s) de contacto. / Replies with contact card(s). */
|
|
478
|
+
async vcard(contacts, extra = {}) {
|
|
479
|
+
return Message.vcard(this._wa, this._raw.cid, contacts, { ...extra, mid: this._raw.id });
|
|
397
480
|
}
|
|
398
|
-
/** Responde con
|
|
399
|
-
async
|
|
400
|
-
return this._wa.
|
|
481
|
+
/** Responde con evento. / Replies with an event. */
|
|
482
|
+
async event(data, extra = {}) {
|
|
483
|
+
return Message.event(this._wa, this._raw.cid, data, { ...extra, mid: this._raw.id });
|
|
401
484
|
}
|
|
402
|
-
/**
|
|
403
|
-
|
|
404
|
-
|
|
485
|
+
/**
|
|
486
|
+
* Obtiene un mensaje por chat y id.
|
|
487
|
+
* Retrieves a message by chat and id.
|
|
488
|
+
*
|
|
489
|
+
* @param wa - Cliente dueño / Owner client
|
|
490
|
+
* @param cid - Identificador del chat / Chat identifier
|
|
491
|
+
* @param mid - Identificador del mensaje / Message identifier
|
|
492
|
+
* @returns Mensaje o null / Message or null
|
|
493
|
+
*/
|
|
494
|
+
static async get(wa, cid, mid) {
|
|
495
|
+
const jid = await internals(wa).resolve_jid(cid);
|
|
496
|
+
if (jid) {
|
|
497
|
+
const doc = deserialize(await wa.engine.get(`/chat/${jid}/message/${mid}`));
|
|
498
|
+
if (doc)
|
|
499
|
+
return message(wa, doc);
|
|
500
|
+
}
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Pagina los mensajes de un chat desde el más reciente.
|
|
505
|
+
* Paginates chat messages from the most recent one.
|
|
506
|
+
*
|
|
507
|
+
* @param wa - Cliente dueño / Owner client
|
|
508
|
+
* @param cid - Identificador del chat / Chat identifier
|
|
509
|
+
* @param offset - Desplazamiento / Offset
|
|
510
|
+
* @param limit - Tamaño de página / Page size
|
|
511
|
+
* @returns Página de mensajes / Message page
|
|
512
|
+
*/
|
|
513
|
+
static async list(wa, cid, offset = 0, limit = 50) {
|
|
514
|
+
const jid = await internals(wa).resolve_jid(cid);
|
|
515
|
+
if (jid) {
|
|
516
|
+
return (await wa.engine.list(`/chat/${jid}/message`, offset, limit))
|
|
517
|
+
.map((raw) => deserialize(raw))
|
|
518
|
+
.filter((doc) => doc !== null)
|
|
519
|
+
.map((doc) => message(wa, doc));
|
|
520
|
+
}
|
|
521
|
+
return [];
|
|
522
|
+
}
|
|
523
|
+
/** Envía texto. / Sends text. */
|
|
524
|
+
static async text(wa, cid, caption, extra = {}) {
|
|
525
|
+
return send(wa, cid, { text: caption }, undefined, extra);
|
|
526
|
+
}
|
|
527
|
+
/** Envía imagen. / Sends an image. */
|
|
528
|
+
static async image(wa, cid, buf, extra = {}) {
|
|
529
|
+
return send(wa, cid, { image: buf, caption: extra.caption }, buf, extra);
|
|
530
|
+
}
|
|
531
|
+
/** Envía video. / Sends a video. */
|
|
532
|
+
static async video(wa, cid, buf, extra = {}) {
|
|
533
|
+
return send(wa, cid, { video: buf, caption: extra.caption }, buf, extra);
|
|
534
|
+
}
|
|
535
|
+
/** Envía audio. / Sends audio. */
|
|
536
|
+
static async audio(wa, cid, buf, extra = {}) {
|
|
537
|
+
return send(wa, cid, { audio: buf, ptt: extra.ptt ?? true }, buf, extra);
|
|
538
|
+
}
|
|
539
|
+
/** Envía ubicación. / Sends a location. */
|
|
540
|
+
static async location(wa, cid, loc, extra = {}) {
|
|
541
|
+
return send(wa, cid, { location: { degreesLatitude: loc.lat, degreesLongitude: loc.lng } }, undefined, extra);
|
|
542
|
+
}
|
|
543
|
+
/** Envía encuesta. / Sends a poll. */
|
|
544
|
+
static async poll(wa, cid, input, extra = {}) {
|
|
545
|
+
const multiple = extra.multiple ?? false;
|
|
546
|
+
return send(wa, cid, {
|
|
547
|
+
poll: {
|
|
548
|
+
name: input.content,
|
|
549
|
+
values: input.options.map((option) => option.content),
|
|
550
|
+
selectableCount: multiple ? 0 : 1,
|
|
551
|
+
},
|
|
552
|
+
}, undefined, extra, { multiple });
|
|
553
|
+
}
|
|
554
|
+
/** Envía documento. / Sends a document. */
|
|
555
|
+
static async document(wa, cid, buf, extra) {
|
|
556
|
+
return send(wa, cid, { document: buf, fileName: extra.file_name, mimetype: extra.mimetype ?? 'application/octet-stream', caption: extra.caption }, buf, extra);
|
|
557
|
+
}
|
|
558
|
+
/** Envía tarjeta(s) de contacto. / Sends contact card(s). */
|
|
559
|
+
static async vcard(wa, cid, contacts, extra = {}) {
|
|
560
|
+
const built = contacts.map((entry) => ({
|
|
561
|
+
displayName: entry.name,
|
|
562
|
+
vcard: [
|
|
563
|
+
'BEGIN:VCARD',
|
|
564
|
+
'VERSION:3.0',
|
|
565
|
+
`FN:${entry.name}`,
|
|
566
|
+
`TEL;type=CELL;waid=${entry.phone.replace(/\D+/g, '')}:${entry.phone}`,
|
|
567
|
+
'END:VCARD',
|
|
568
|
+
].join('\n'),
|
|
569
|
+
}));
|
|
570
|
+
return send(wa, cid, { contacts: { contacts: built } }, Buffer.from(built.map((entry) => entry.vcard).join('\n'), 'utf-8'), extra);
|
|
405
571
|
}
|
|
406
|
-
/**
|
|
407
|
-
async event(data,
|
|
408
|
-
|
|
572
|
+
/** Envía evento. / Sends an event. */
|
|
573
|
+
static async event(wa, cid, data, extra = {}) {
|
|
574
|
+
const binary = Buffer.from(JSON.stringify({ name: data.name, caption: data.caption, start: data.start.getTime(), end: data.end?.getTime() ?? null }), 'utf-8');
|
|
575
|
+
return send(wa, cid, {
|
|
576
|
+
event: {
|
|
577
|
+
name: data.name,
|
|
578
|
+
description: data.caption,
|
|
579
|
+
startDate: data.start,
|
|
580
|
+
endDate: data.end,
|
|
581
|
+
location: data.place ? { degreesLatitude: data.place.lat, degreesLongitude: data.place.lng } : undefined,
|
|
582
|
+
},
|
|
583
|
+
}, binary, extra);
|
|
584
|
+
}
|
|
585
|
+
/** Reacciona a un mensaje por id. / Reacts to a message by id. */
|
|
586
|
+
static async react(wa, cid, mid, emoji) {
|
|
587
|
+
const msg = await Message.get(wa, cid, mid);
|
|
588
|
+
return msg ? msg.react(emoji) : false;
|
|
589
|
+
}
|
|
590
|
+
/** Destaca un mensaje por id. / Stars a message by id. */
|
|
591
|
+
static async star(wa, cid, mid, value) {
|
|
592
|
+
const msg = await Message.get(wa, cid, mid);
|
|
593
|
+
return msg ? msg.star(value) : false;
|
|
594
|
+
}
|
|
595
|
+
/** Marca un mensaje como leído por id. / Marks a message as read by id. */
|
|
596
|
+
static async seen(wa, cid, mid) {
|
|
597
|
+
const msg = await Message.get(wa, cid, mid);
|
|
598
|
+
return msg ? msg.seen() : false;
|
|
599
|
+
}
|
|
600
|
+
/** Edita un mensaje por id. / Edits a message by id. */
|
|
601
|
+
static async edit(wa, cid, mid, caption) {
|
|
602
|
+
const msg = await Message.get(wa, cid, mid);
|
|
603
|
+
return msg ? msg.edit(caption) : false;
|
|
604
|
+
}
|
|
605
|
+
/** Reenvía un mensaje por id. / Forwards a message by id. */
|
|
606
|
+
static async forward(wa, cid, mid, target) {
|
|
607
|
+
const msg = await Message.get(wa, cid, mid);
|
|
608
|
+
return msg ? msg.forward(target) : false;
|
|
609
|
+
}
|
|
610
|
+
/** Elimina un mensaje por id. / Deletes a message by id. */
|
|
611
|
+
static async delete(wa, cid, mid, all = false) {
|
|
612
|
+
const msg = await Message.get(wa, cid, mid);
|
|
613
|
+
return msg ? msg.delete(all) : false;
|
|
614
|
+
}
|
|
615
|
+
/** Reacciones de un mensaje por id. / Reactions of a message by id. */
|
|
616
|
+
static async reactions(wa, cid, mid) {
|
|
617
|
+
const msg = await Message.get(wa, cid, mid);
|
|
618
|
+
return msg ? msg.reactions() : [];
|
|
409
619
|
}
|
|
410
620
|
}
|
|
411
621
|
/**
|
|
412
|
-
* Mensaje de texto
|
|
413
|
-
* Text message
|
|
622
|
+
* Mensaje de texto; `preview()` expone la tarjeta del enlace embebido.
|
|
623
|
+
* Text message; `preview()` exposes the embedded link card.
|
|
414
624
|
*/
|
|
415
625
|
export class Text extends Message {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
catch {
|
|
433
|
-
/* fallback empty */
|
|
626
|
+
/**
|
|
627
|
+
* Preview del enlace del texto, o null cuando no trae metadata.
|
|
628
|
+
* Text link preview, or null when it carries no metadata.
|
|
629
|
+
*
|
|
630
|
+
* @returns { link, name, content, thumb } o null / { link, name, content, thumb } or null
|
|
631
|
+
*/
|
|
632
|
+
async preview() {
|
|
633
|
+
const ext = this._raw.raw.message?.extendedTextMessage;
|
|
634
|
+
if (ext?.matchedText && (ext.title || ext.description)) {
|
|
635
|
+
return {
|
|
636
|
+
link: ext.matchedText,
|
|
637
|
+
name: ext.title ?? null,
|
|
638
|
+
content: ext.description ?? null,
|
|
639
|
+
thumb: to_buffer(ext.jpegThumbnail),
|
|
640
|
+
};
|
|
434
641
|
}
|
|
642
|
+
return null;
|
|
435
643
|
}
|
|
436
|
-
return Readable.from(Buffer.alloc(0));
|
|
437
|
-
}
|
|
438
|
-
/** @internal Acumula un Readable en Buffer. */
|
|
439
|
-
async function _drain(readable) {
|
|
440
|
-
const chunks = [];
|
|
441
|
-
for await (const chunk of readable) {
|
|
442
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
443
|
-
}
|
|
444
|
-
return Buffer.concat(chunks);
|
|
445
644
|
}
|
|
446
645
|
/**
|
|
447
|
-
* Mensaje de imagen
|
|
448
|
-
* Image message
|
|
646
|
+
* Mensaje de imagen: dimensiones, peso y miniatura.
|
|
647
|
+
* Image message: dimensions, size and thumbnail.
|
|
449
648
|
*/
|
|
450
649
|
export class Image extends Message {
|
|
650
|
+
/** @internal */
|
|
651
|
+
get _media() {
|
|
652
|
+
return unwrap(this._raw.raw.message ?? {}).imageMessage;
|
|
653
|
+
}
|
|
654
|
+
/** Ancho en píxeles. / Width in pixels. */
|
|
655
|
+
get width() {
|
|
656
|
+
return this._media?.width ?? 0;
|
|
657
|
+
}
|
|
658
|
+
/** Alto en píxeles. / Height in pixels. */
|
|
659
|
+
get height() {
|
|
660
|
+
return this._media?.height ?? 0;
|
|
661
|
+
}
|
|
662
|
+
/** Peso en bytes. / Size in bytes. */
|
|
663
|
+
get size() {
|
|
664
|
+
return to_number(this._media?.fileLength);
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Miniatura JPEG embebida, o null.
|
|
668
|
+
* Embedded JPEG thumbnail, or null.
|
|
669
|
+
*
|
|
670
|
+
* @returns Buffer de la miniatura o null / Thumbnail buffer or null
|
|
671
|
+
*/
|
|
672
|
+
async thumb() {
|
|
673
|
+
return to_buffer(this._media?.jpegThumbnail);
|
|
674
|
+
}
|
|
451
675
|
async content() {
|
|
452
|
-
return
|
|
676
|
+
return drain(await this.stream());
|
|
453
677
|
}
|
|
454
678
|
}
|
|
455
679
|
/**
|
|
456
|
-
* Mensaje de video
|
|
457
|
-
* Video message
|
|
680
|
+
* Mensaje de video: dimensiones, duración, peso y miniatura.
|
|
681
|
+
* Video message: dimensions, duration, size and thumbnail.
|
|
458
682
|
*/
|
|
459
683
|
export class Video extends Message {
|
|
684
|
+
/** @internal */
|
|
685
|
+
get _media() {
|
|
686
|
+
return unwrap(this._raw.raw.message ?? {}).videoMessage;
|
|
687
|
+
}
|
|
688
|
+
/** Ancho en píxeles. / Width in pixels. */
|
|
689
|
+
get width() {
|
|
690
|
+
return this._media?.width ?? 0;
|
|
691
|
+
}
|
|
692
|
+
/** Alto en píxeles. / Height in pixels. */
|
|
693
|
+
get height() {
|
|
694
|
+
return this._media?.height ?? 0;
|
|
695
|
+
}
|
|
696
|
+
/** Duración en segundos. / Duration in seconds. */
|
|
697
|
+
get duration() {
|
|
698
|
+
return this._media?.seconds ?? 0;
|
|
699
|
+
}
|
|
700
|
+
/** Peso en bytes. / Size in bytes. */
|
|
701
|
+
get size() {
|
|
702
|
+
return to_number(this._media?.fileLength);
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Miniatura JPEG embebida, o null.
|
|
706
|
+
* Embedded JPEG thumbnail, or null.
|
|
707
|
+
*
|
|
708
|
+
* @returns Buffer de la miniatura o null / Thumbnail buffer or null
|
|
709
|
+
*/
|
|
710
|
+
async thumb() {
|
|
711
|
+
return to_buffer(this._media?.jpegThumbnail);
|
|
712
|
+
}
|
|
460
713
|
async content() {
|
|
461
|
-
return
|
|
714
|
+
return drain(await this.stream());
|
|
462
715
|
}
|
|
463
716
|
}
|
|
464
717
|
/**
|
|
465
|
-
* Mensaje de audio
|
|
466
|
-
*
|
|
467
|
-
* Audio message. Inherits `stream()` from the base class; `content()` drains the stream.
|
|
468
|
-
* `ptt` flags voice notes.
|
|
718
|
+
* Mensaje de audio: nota de voz o archivo, con forma de onda del protocolo.
|
|
719
|
+
* Audio message: voice note or file, with the protocol waveform.
|
|
469
720
|
*/
|
|
470
721
|
export class Audio extends Message {
|
|
471
|
-
/**
|
|
722
|
+
/** @internal */
|
|
723
|
+
get _media() {
|
|
724
|
+
return unwrap(this._raw.raw.message ?? {}).audioMessage;
|
|
725
|
+
}
|
|
726
|
+
/** true si es nota de voz. / true when push-to-talk. */
|
|
472
727
|
get ptt() {
|
|
473
|
-
return this.
|
|
728
|
+
return this._media?.ptt === true;
|
|
729
|
+
}
|
|
730
|
+
/** Duración en segundos. / Duration in seconds. */
|
|
731
|
+
get duration() {
|
|
732
|
+
return this._media?.seconds ?? 0;
|
|
733
|
+
}
|
|
734
|
+
/** Peso en bytes. / Size in bytes. */
|
|
735
|
+
get size() {
|
|
736
|
+
return to_number(this._media?.fileLength);
|
|
737
|
+
}
|
|
738
|
+
/** Forma de onda 0-100 lista para pintar. / Paint-ready 0-100 waveform. */
|
|
739
|
+
get waveform() {
|
|
740
|
+
const wave = this._media?.waveform;
|
|
741
|
+
const bytes = wave instanceof Uint8Array ? wave : typeof wave === 'string' ? Buffer.from(wave, 'base64') : Buffer.alloc(0);
|
|
742
|
+
return Array.from(bytes);
|
|
474
743
|
}
|
|
475
744
|
async content() {
|
|
476
|
-
return
|
|
745
|
+
return drain(await this.stream());
|
|
477
746
|
}
|
|
478
747
|
}
|
|
479
748
|
/**
|
|
480
|
-
* Mensaje de
|
|
481
|
-
*
|
|
749
|
+
* Mensaje de sticker: dimensiones, peso y animación.
|
|
750
|
+
* Sticker message: dimensions, size and animation.
|
|
482
751
|
*/
|
|
483
|
-
export class
|
|
752
|
+
export class Sticker extends Message {
|
|
753
|
+
/** @internal */
|
|
754
|
+
get _media() {
|
|
755
|
+
return unwrap(this._raw.raw.message ?? {}).stickerMessage;
|
|
756
|
+
}
|
|
757
|
+
/** Ancho en píxeles. / Width in pixels. */
|
|
758
|
+
get width() {
|
|
759
|
+
return this._media?.width ?? 0;
|
|
760
|
+
}
|
|
761
|
+
/** Alto en píxeles. / Height in pixels. */
|
|
762
|
+
get height() {
|
|
763
|
+
return this._media?.height ?? 0;
|
|
764
|
+
}
|
|
765
|
+
/** true si el sticker es animado. / true when animated. */
|
|
766
|
+
get animated() {
|
|
767
|
+
return this._media?.isAnimated === true;
|
|
768
|
+
}
|
|
769
|
+
/** Peso en bytes. / Size in bytes. */
|
|
770
|
+
get size() {
|
|
771
|
+
return to_number(this._media?.fileLength);
|
|
772
|
+
}
|
|
773
|
+
async content() {
|
|
774
|
+
return drain(await this.stream());
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Mensaje de documento; el MIME real vive en `mime` de la base.
|
|
779
|
+
* Document message; the actual MIME lives in the base `mime`.
|
|
780
|
+
*/
|
|
781
|
+
export class Document extends Message {
|
|
782
|
+
/** Peso en bytes. / Size in bytes. */
|
|
783
|
+
get size() {
|
|
784
|
+
const media = unwrap(this._raw.raw.message ?? {}).documentMessage;
|
|
785
|
+
return to_number(media?.fileLength);
|
|
786
|
+
}
|
|
787
|
+
async content() {
|
|
788
|
+
return drain(await this.stream());
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Mensaje de ubicación, fija o en vivo.
|
|
793
|
+
* Location message, static or live.
|
|
794
|
+
*/
|
|
795
|
+
export class Location extends Message {
|
|
796
|
+
/** @internal */
|
|
484
797
|
get _loc() {
|
|
485
|
-
return this.
|
|
798
|
+
return this._raw.raw.message?.locationMessage ?? this._raw.raw.message?.liveLocationMessage;
|
|
486
799
|
}
|
|
487
800
|
/** Latitud en grados. / Latitude in degrees. */
|
|
488
801
|
get lat() {
|
|
@@ -492,247 +805,184 @@ export class Gps extends Message {
|
|
|
492
805
|
get lng() {
|
|
493
806
|
return this._loc?.degreesLongitude ?? 0;
|
|
494
807
|
}
|
|
495
|
-
/** URL de Google Maps apuntando a la coordenada. / Google Maps URL for the coordinate. */
|
|
496
|
-
get link() {
|
|
497
|
-
return `https://www.google.com/maps/@${this.lat},${this.lng},15z`;
|
|
498
|
-
}
|
|
499
808
|
/** true si es ubicación en tiempo real. / true when live location. */
|
|
500
809
|
get live() {
|
|
501
|
-
return Boolean(this.
|
|
810
|
+
return Boolean(this._raw.raw.message?.liveLocationMessage);
|
|
811
|
+
}
|
|
812
|
+
/** URL de Google Maps de la coordenada. / Google Maps URL for the coordinate. */
|
|
813
|
+
get link() {
|
|
814
|
+
return `https://www.google.com/maps/@${this.lat},${this.lng},15z`;
|
|
502
815
|
}
|
|
503
816
|
}
|
|
504
817
|
/**
|
|
505
|
-
* Mensaje de encuesta
|
|
506
|
-
* Poll message
|
|
818
|
+
* Mensaje de encuesta: opciones con conteo, votos por contacto y voto propio.
|
|
819
|
+
* Poll message: options with counts, per-contact votes and self-voting.
|
|
507
820
|
*/
|
|
508
821
|
export class Poll extends Message {
|
|
822
|
+
/** @internal */
|
|
509
823
|
get _poll() {
|
|
510
|
-
const
|
|
511
|
-
return
|
|
824
|
+
const msg = this._raw.raw.message;
|
|
825
|
+
return msg?.pollCreationMessage ?? msg?.pollCreationMessageV2 ?? msg?.pollCreationMessageV3;
|
|
826
|
+
}
|
|
827
|
+
/** @internal Updates de voto con los bytes normalizados post-engine. / Vote updates with post-engine normalized bytes. */
|
|
828
|
+
get _updates() {
|
|
829
|
+
return (this._raw.raw.pollUpdates ?? []).map((update) => ({
|
|
830
|
+
...update,
|
|
831
|
+
vote: update.vote
|
|
832
|
+
? {
|
|
833
|
+
...update.vote,
|
|
834
|
+
selectedOptions: (update.vote.selectedOptions ?? []).map((option) => typeof option === 'string' ? Buffer.from(option, 'base64') : option),
|
|
835
|
+
}
|
|
836
|
+
: update.vote,
|
|
837
|
+
}));
|
|
512
838
|
}
|
|
513
|
-
/**
|
|
514
|
-
* true si admite múltiples respuestas. Lee primero el flag explícito persistido
|
|
515
|
-
* al enviar (caso propio, donde WhatsApp pierde el discriminador en el echo);
|
|
516
|
-
* fallback al `selectableOptionsCount` del proto (polls foráneos o de UI móvil).
|
|
517
|
-
* true if the poll accepts multiple answers. Prefers the persisted send-time
|
|
518
|
-
* flag (own polls, since WhatsApp drops the discriminator on echo); falls back
|
|
519
|
-
* to the proto `selectableOptionsCount` (foreign or mobile-UI polls).
|
|
520
|
-
*/
|
|
839
|
+
/** true si admite varias respuestas. / true when multi-select. */
|
|
521
840
|
get multiple() {
|
|
522
|
-
if (typeof this.
|
|
523
|
-
return this.
|
|
841
|
+
if (typeof this._raw.multiple === 'boolean') {
|
|
842
|
+
return this._raw.multiple;
|
|
524
843
|
}
|
|
525
844
|
return (this._poll?.selectableOptionsCount ?? 1) !== 1;
|
|
526
845
|
}
|
|
527
|
-
/** Opciones con conteo de votos
|
|
846
|
+
/** Opciones con su conteo de votos. / Options with their vote counts. */
|
|
528
847
|
get options() {
|
|
529
|
-
const
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
vote: u.vote
|
|
535
|
-
? {
|
|
536
|
-
...u.vote,
|
|
537
|
-
selectedOptions: (u.vote.selectedOptions ?? []).map((s) => typeof s === 'string' ? Buffer.from(s, 'base64') : s),
|
|
538
|
-
}
|
|
539
|
-
: u.vote,
|
|
540
|
-
}));
|
|
541
|
-
const aggregated = getAggregateVotesInPollMessage({ message: this._doc.raw.message ?? undefined, pollUpdates: updates }, this._wa._socket?.user?.id);
|
|
542
|
-
const counts = new Map(aggregated.map((a) => [a.name, a.voters.length]));
|
|
543
|
-
return opts.map((o) => ({
|
|
544
|
-
content: o.optionName ?? '',
|
|
545
|
-
count: counts.get(o.optionName ?? '') ?? 0,
|
|
848
|
+
const aggregated = getAggregateVotesInPollMessage({ message: this._raw.raw.message ?? undefined, pollUpdates: this._updates }, internals(this._wa).socket?.user?.id);
|
|
849
|
+
const counts = new Map(aggregated.map((entry) => [entry.name, entry.voters.length]));
|
|
850
|
+
return (this._poll?.options ?? []).map((option) => ({
|
|
851
|
+
name: option.optionName ?? '',
|
|
852
|
+
count: counts.get(option.optionName ?? '') ?? 0,
|
|
546
853
|
}));
|
|
547
854
|
}
|
|
548
855
|
/**
|
|
549
|
-
*
|
|
550
|
-
*
|
|
856
|
+
* Votos individuales: opción elegida y teléfono del votante.
|
|
857
|
+
* Individual votes: chosen option and voter phone.
|
|
858
|
+
*
|
|
859
|
+
* @returns Lista de votos / Vote list
|
|
860
|
+
*/
|
|
861
|
+
async votes() {
|
|
862
|
+
const aggregated = getAggregateVotesInPollMessage({ message: this._raw.raw.message ?? undefined, pollUpdates: this._updates }, internals(this._wa).socket?.user?.id);
|
|
863
|
+
const result = [];
|
|
864
|
+
for (const entry of aggregated) {
|
|
865
|
+
for (const voter of entry.voters) {
|
|
866
|
+
const jid = await internals(this._wa).resolve_jid(voter);
|
|
867
|
+
result.push({ name: entry.name, contact: (jid ?? voter).split('@')[0].split(':')[0] });
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
return result;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Vota en la encuesta con uno o varios índices. Cifra el voto (HMAC+AES-GCM) y lo
|
|
874
|
+
* enruta al chat @lid con la identidad LID propia. Best-effort: el voto entrante
|
|
875
|
+
* descifra correcto, pero WhatsApp no propaga el voto emitido desde un dispositivo
|
|
876
|
+
* vinculado (companion).
|
|
877
|
+
* Votes in the poll with one or more indexes. Encrypts the vote (HMAC+AES-GCM) and
|
|
878
|
+
* routes it to the @lid chat with the own LID identity. Best-effort: incoming votes
|
|
879
|
+
* decrypt fine, but WhatsApp does not propagate votes emitted from a linked
|
|
880
|
+
* (companion) device.
|
|
881
|
+
*
|
|
882
|
+
* @param index - Índice o índices de la opción / Option index or indexes
|
|
883
|
+
* @returns true si el voto se emitió / true when the vote was relayed
|
|
551
884
|
*/
|
|
552
885
|
async select(index) {
|
|
553
|
-
const
|
|
554
|
-
const indices = Array.isArray(index) ? index : [index];
|
|
886
|
+
const doc = this._raw;
|
|
555
887
|
const opts = this._poll?.options ?? [];
|
|
556
|
-
const selected_options =
|
|
888
|
+
const selected_options = (Array.isArray(index) ? index : [index])
|
|
557
889
|
.filter((i) => i >= 0 && i < opts.length)
|
|
558
890
|
.map((i) => sha256(Buffer.from(opts[i].optionName ?? '')));
|
|
559
|
-
|
|
560
|
-
// del engine). Normaliza a Buffer antes de derivar el HMAC.
|
|
561
|
-
// messageSecret may arrive as Buffer (runtime raw) or base64 string (post engine
|
|
562
|
-
// deserialize). Normalize to Buffer before deriving the HMAC.
|
|
563
|
-
const secret_raw = _doc.raw.message?.messageContextInfo?.messageSecret;
|
|
891
|
+
const secret_raw = doc.raw.message?.messageContextInfo?.messageSecret;
|
|
564
892
|
const poll_enc_key = typeof secret_raw === 'string' ? Buffer.from(secret_raw, 'base64') : secret_raw;
|
|
565
|
-
|
|
893
|
+
const socket = internals(this._wa).socket;
|
|
894
|
+
if (!poll_enc_key || !socket || selected_options.length === 0) {
|
|
566
895
|
return false;
|
|
567
896
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
// Always forcing LID (3.1.1 fix) made votes undecryptable on PN chats: the
|
|
575
|
-
// receiver derives the key from the stanza's sender JID.
|
|
576
|
-
const poll_key = _doc.raw.key ?? {};
|
|
577
|
-
const self_id = _wa._socket.user?.id ?? '';
|
|
578
|
-
const self_lid = _wa._socket.user?.lid ?? '';
|
|
579
|
-
const self_for_chat = _doc.cid.endsWith('@lid') && self_lid ? self_lid : self_id;
|
|
580
|
-
const voter_jid = jidNormalizedUser(self_for_chat);
|
|
581
|
-
let poll_creator_raw;
|
|
582
|
-
if (poll_key.fromMe) {
|
|
583
|
-
poll_creator_raw = self_for_chat;
|
|
897
|
+
const poll_key = doc.raw.key ?? {};
|
|
898
|
+
const self_id = socket.user?.id ?? '';
|
|
899
|
+
const self_lid = socket.user?.lid ?? '';
|
|
900
|
+
let dest = doc.cid;
|
|
901
|
+
if (poll_key.remoteJid?.endsWith('@lid')) {
|
|
902
|
+
dest = poll_key.remoteJid;
|
|
584
903
|
}
|
|
585
|
-
else if (
|
|
586
|
-
|
|
904
|
+
else if (!doc.cid.endsWith('@lid')) {
|
|
905
|
+
const contact_raw = deserialize(await this._wa.engine.get(`/contact/${doc.cid}`));
|
|
906
|
+
const mapped = await socket.signalRepository?.lidMapping?.getLIDForPN(doc.cid).catch(() => null);
|
|
907
|
+
dest = contact_raw?.lid ?? mapped ?? doc.cid;
|
|
587
908
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
909
|
+
const self_for_send = dest.endsWith('@lid') && self_lid ? self_lid : self_id;
|
|
910
|
+
const voter_jid = jidNormalizedUser(self_for_send);
|
|
911
|
+
const poll_creator_jid = jidNormalizedUser(poll_key.fromMe
|
|
912
|
+
? self_for_send
|
|
913
|
+
: poll_key.remoteJid?.endsWith('@lid')
|
|
914
|
+
? poll_key.remoteJid
|
|
915
|
+
: getKeyAuthor(poll_key, self_id));
|
|
594
916
|
const sign = Buffer.concat([
|
|
595
|
-
Buffer.from(
|
|
917
|
+
Buffer.from(doc.id),
|
|
596
918
|
Buffer.from(poll_creator_jid),
|
|
597
919
|
Buffer.from(voter_jid),
|
|
598
920
|
Buffer.from('Poll Vote'),
|
|
599
921
|
new Uint8Array([1]),
|
|
600
922
|
]);
|
|
601
|
-
const
|
|
602
|
-
const enc_key = hmacSign(sign, key0, 'sha256');
|
|
603
|
-
const payload = proto.Message.PollVoteMessage.encode({
|
|
604
|
-
selectedOptions: selected_options,
|
|
605
|
-
}).finish();
|
|
606
|
-
const aad = Buffer.from(`${poll_msg_id}\x00${voter_jid}`);
|
|
923
|
+
const enc_key = hmacSign(sign, hmacSign(poll_enc_key, new Uint8Array(32), 'sha256'), 'sha256');
|
|
607
924
|
const enc_iv = randomBytes(12);
|
|
608
|
-
const enc_payload = aesEncryptGCM(
|
|
925
|
+
const enc_payload = aesEncryptGCM(proto.Message.PollVoteMessage.encode({ selectedOptions: selected_options }).finish(), enc_key, enc_iv, Buffer.from(`${doc.id}\x00${voter_jid}`));
|
|
609
926
|
const msg_id = generateMessageID();
|
|
610
|
-
await
|
|
927
|
+
await socket.relayMessage(dest, {
|
|
611
928
|
pollUpdateMessage: {
|
|
612
|
-
pollCreationMessageKey:
|
|
929
|
+
pollCreationMessageKey: dest === doc.cid ? doc.raw.key : { ...doc.raw.key, remoteJid: dest },
|
|
613
930
|
vote: { encPayload: enc_payload, encIv: enc_iv },
|
|
614
931
|
senderTimestampMs: Date.now(),
|
|
615
932
|
},
|
|
616
933
|
}, { messageId: msg_id });
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
// `message:updated` reflejen el cambio sin esperar (nunca) un echo del servidor.
|
|
620
|
-
// baileys.relayMessage doesn't emit a local upsert on the originating companion.
|
|
621
|
-
// We merge the own vote into the doc so `options[].count` and the `message:updated`
|
|
622
|
-
// event reflect the change without waiting for a server echo that never comes.
|
|
623
|
-
const own_update_key = {
|
|
624
|
-
remoteJid: _doc.raw.key?.remoteJid ?? _doc.cid,
|
|
625
|
-
fromMe: true,
|
|
626
|
-
id: msg_id,
|
|
627
|
-
};
|
|
628
|
-
updateMessageWithPollUpdate(_doc.raw, {
|
|
629
|
-
pollUpdateMessageKey: own_update_key,
|
|
934
|
+
updateMessageWithPollUpdate(doc.raw, {
|
|
935
|
+
pollUpdateMessageKey: { remoteJid: doc.raw.key?.remoteJid ?? doc.cid, fromMe: true, id: msg_id },
|
|
630
936
|
vote: { selectedOptions: selected_options },
|
|
631
937
|
senderTimestampMs: Date.now(),
|
|
632
938
|
});
|
|
633
|
-
await _wa.engine.set(`/chat/${
|
|
634
|
-
_wa.
|
|
939
|
+
await this._wa.engine.set(`/chat/${doc.cid}/message/${doc.id}`, serialize(doc), doc.created_at);
|
|
940
|
+
this._wa.emit('message:updated', this, await this.chat(), this._wa);
|
|
635
941
|
return true;
|
|
636
942
|
}
|
|
637
943
|
}
|
|
638
944
|
/**
|
|
639
|
-
* Mensaje de
|
|
640
|
-
*
|
|
641
|
-
* el tipo de mensaje (`documentMessage`), no el mimetype. Hereda `stream()` de la
|
|
642
|
-
* clase base; `content()` drena el stream (cache → download).
|
|
643
|
-
* Document message. WhatsApp lets you send any file (PDF, image, audio, video…)
|
|
644
|
-
* as a document; what sets it apart from image/video/audio is the message type
|
|
645
|
-
* (`documentMessage`), not the mimetype. Inherits `stream()` from the base class;
|
|
646
|
-
* `content()` drains the stream (cache → download).
|
|
647
|
-
*/
|
|
648
|
-
export class Document extends Message {
|
|
649
|
-
get _doc_msg() {
|
|
650
|
-
const m = this._doc.raw.message;
|
|
651
|
-
return m?.documentMessage ?? m?.documentWithCaptionMessage?.message?.documentMessage;
|
|
652
|
-
}
|
|
653
|
-
/** Nombre del archivo. / File name. */
|
|
654
|
-
get file_name() {
|
|
655
|
-
return this._doc_msg?.fileName ?? '';
|
|
656
|
-
}
|
|
657
|
-
/** Tamaño en bytes (0 si se desconoce). / Size in bytes (0 if unknown). */
|
|
658
|
-
get size() {
|
|
659
|
-
return Number(this._doc_msg?.fileLength?.toString() ?? '0');
|
|
660
|
-
}
|
|
661
|
-
/** Número de páginas (PDF); 0 si no aplica. / Page count (PDF); 0 when not applicable. */
|
|
662
|
-
get pages() {
|
|
663
|
-
return this._doc_msg?.pageCount ?? 0;
|
|
664
|
-
}
|
|
665
|
-
/** Título del documento. / Document title. */
|
|
666
|
-
get title() {
|
|
667
|
-
return this._doc_msg?.title ?? '';
|
|
668
|
-
}
|
|
669
|
-
async content() {
|
|
670
|
-
return _drain(await this.stream());
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Construye un vCard 3.0 mínimo con el teléfono enlazado como contacto de WhatsApp.
|
|
675
|
-
* Builds a minimal vCard 3.0 with the phone linked as a WhatsApp contact.
|
|
676
|
-
*
|
|
677
|
-
* @param name - Nombre mostrado / Display name
|
|
678
|
-
* @param phone - Teléfono en formato internacional / Phone in international format
|
|
679
|
-
* @returns String vCard (VCF) / vCard (VCF) string
|
|
680
|
-
*/
|
|
681
|
-
function build_vcard(name, phone) {
|
|
682
|
-
const waid = phone.replace(/\D+/g, '');
|
|
683
|
-
return [
|
|
684
|
-
'BEGIN:VCARD',
|
|
685
|
-
'VERSION:3.0',
|
|
686
|
-
`FN:${name}`,
|
|
687
|
-
`TEL;type=CELL;waid=${waid}:${phone}`,
|
|
688
|
-
'END:VCARD',
|
|
689
|
-
].join('\n');
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Mensaje de tarjeta(s) de contacto (vCard). Unifica `contactMessage` (uno) y
|
|
693
|
-
* `contactsArrayMessage` (varios) bajo una sola lista `contacts`.
|
|
694
|
-
* Contact card message (vCard). Unifies `contactMessage` (single) and
|
|
695
|
-
* `contactsArrayMessage` (multiple) under a single `contacts` list.
|
|
945
|
+
* Mensaje de tarjeta(s) de contacto.
|
|
946
|
+
* Contact card(s) message.
|
|
696
947
|
*/
|
|
697
948
|
export class VCard extends Message {
|
|
698
|
-
/** Contactos de la tarjeta
|
|
949
|
+
/** Contactos de la tarjeta. / Card contacts. */
|
|
699
950
|
get contacts() {
|
|
700
|
-
const
|
|
701
|
-
const raw =
|
|
702
|
-
return raw.map((
|
|
703
|
-
const tel = (
|
|
704
|
-
return { name:
|
|
951
|
+
const msg = this._raw.raw.message;
|
|
952
|
+
const raw = msg?.contactsArrayMessage?.contacts ?? (msg?.contactMessage ? [msg.contactMessage] : []);
|
|
953
|
+
return raw.map((card) => {
|
|
954
|
+
const tel = (card.vcard ?? '').match(/TEL[^:]*:(.+)/);
|
|
955
|
+
return { name: card.displayName ?? '', phone: tel ? tel[1].trim() : '' };
|
|
705
956
|
});
|
|
706
957
|
}
|
|
707
958
|
}
|
|
708
959
|
/**
|
|
709
|
-
* Mensaje de evento de calendario
|
|
710
|
-
*
|
|
711
|
-
* Calendar event message (`eventMessage`): name, description, date range,
|
|
712
|
-
* cancellation state, join link and location.
|
|
960
|
+
* Mensaje de evento de calendario.
|
|
961
|
+
* Calendar event message.
|
|
713
962
|
*/
|
|
714
963
|
export class Event extends Message {
|
|
964
|
+
/** @internal */
|
|
715
965
|
get _event() {
|
|
716
|
-
return this.
|
|
966
|
+
return this._raw.raw.message?.eventMessage;
|
|
717
967
|
}
|
|
718
968
|
/** Nombre del evento. / Event name. */
|
|
719
969
|
get name() {
|
|
720
970
|
return this._event?.name ?? '';
|
|
721
971
|
}
|
|
722
|
-
/**
|
|
972
|
+
/** Inicio en ISO UTC. / Start as ISO UTC. */
|
|
723
973
|
get start() {
|
|
724
|
-
return
|
|
974
|
+
return new Date(to_number(this._event?.startTime) * 1000).toISOString();
|
|
725
975
|
}
|
|
726
|
-
/**
|
|
976
|
+
/** Fin en ISO UTC, o null. / End as ISO UTC, or null. */
|
|
727
977
|
get end() {
|
|
728
978
|
const end = this._event?.endTime;
|
|
729
|
-
return end == null ? null :
|
|
979
|
+
return end == null ? null : new Date(to_number(end) * 1000).toISOString();
|
|
730
980
|
}
|
|
731
|
-
/** true si
|
|
981
|
+
/** true si fue cancelado. / true when canceled. */
|
|
732
982
|
get canceled() {
|
|
733
983
|
return this._event?.isCanceled ?? false;
|
|
734
984
|
}
|
|
735
|
-
/** Link de unión
|
|
985
|
+
/** Link de unión, si aplica. / Join link, if any. */
|
|
736
986
|
get link() {
|
|
737
987
|
return this._event?.joinLink ?? '';
|
|
738
988
|
}
|
|
@@ -743,205 +993,75 @@ export class Event extends Message {
|
|
|
743
993
|
}
|
|
744
994
|
}
|
|
745
995
|
/**
|
|
746
|
-
* Factoría
|
|
747
|
-
*
|
|
996
|
+
* Factoría de Message: evalúa el tipo y retorna la instancia de la subclase correcta.
|
|
997
|
+
* Acepta el documento persistido o el mensaje crudo de baileys — en ese caso el
|
|
998
|
+
* documento se deriva aquí mismo (id, tipo, autor, caption, mime, fechas).
|
|
999
|
+
* Message factory: evaluates the type and returns the right subclass instance. Accepts
|
|
1000
|
+
* the persisted document or the raw baileys message — in that case the document is
|
|
1001
|
+
* derived right here (id, type, author, caption, mime, dates).
|
|
1002
|
+
*
|
|
1003
|
+
* @param wa - Instancia principal / Main WhatsApp instance
|
|
1004
|
+
* @param raw - Documento persistido o WAMessage crudo / Persisted document or raw WAMessage
|
|
1005
|
+
* @returns Instancia del tipo correcto / Right-type instance
|
|
748
1006
|
*/
|
|
749
|
-
export function message(wa) {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
}
|
|
792
|
-
const raw = await wa._socket.sendMessage(jid, {
|
|
793
|
-
...content,
|
|
794
|
-
...(quoted ? { quoted } : {}),
|
|
795
|
-
});
|
|
796
|
-
const sent_id = raw?.key?.id;
|
|
797
|
-
if (raw && sent_id) {
|
|
798
|
-
const doc = build_message_doc(raw, wa._socket?.user?.id);
|
|
799
|
-
if (doc_overrides) {
|
|
800
|
-
Object.assign(doc, doc_overrides);
|
|
801
|
-
}
|
|
802
|
-
await wa.engine.set(`/chat/${jid}/message/${sent_id}`, serialize(doc));
|
|
803
|
-
if (binary) {
|
|
804
|
-
await wa.engine.set(`/chat/${jid}/message/${sent_id}/content`, serialize({ data: binary.toString('base64') }));
|
|
805
|
-
}
|
|
806
|
-
result = await build_instance(doc);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
return result;
|
|
1007
|
+
export function message(wa, raw) {
|
|
1008
|
+
let doc;
|
|
1009
|
+
if ('key' in raw) {
|
|
1010
|
+
const key = raw.key ?? {};
|
|
1011
|
+
const unwrapped = unwrap(raw.message ?? {});
|
|
1012
|
+
const content_type = getContentType(unwrapped);
|
|
1013
|
+
const msg_type = MESSAGE_TYPE_MAP[content_type] ?? 'text';
|
|
1014
|
+
const msg_content = unwrapped[content_type];
|
|
1015
|
+
const context_info = msg_content?.contextInfo;
|
|
1016
|
+
const ephemeral_duration = raw.ephemeralDuration ?? context_info?.expiration;
|
|
1017
|
+
const self_id = internals(wa).socket?.user?.id;
|
|
1018
|
+
doc = {
|
|
1019
|
+
id: key.id ?? '',
|
|
1020
|
+
cid: key.remoteJidAlt ?? key.remoteJid ?? '',
|
|
1021
|
+
mid: context_info?.stanzaId ?? null,
|
|
1022
|
+
me: key.fromMe ?? false,
|
|
1023
|
+
type: msg_type,
|
|
1024
|
+
author: key.fromMe && self_id
|
|
1025
|
+
? jidNormalizedUser(self_id)
|
|
1026
|
+
: key.participant || key.remoteJidAlt || key.remoteJid || '',
|
|
1027
|
+
status: raw.status ?? 1,
|
|
1028
|
+
starred: raw.starred ?? false,
|
|
1029
|
+
forwarded: context_info?.isForwarded ?? false,
|
|
1030
|
+
created_at: (Number(raw.messageTimestamp) || Math.floor(Date.now() / 1000)) * 1000,
|
|
1031
|
+
deleted_at: raw.ephemeralStartTimestamp != null && ephemeral_duration != null
|
|
1032
|
+
? (Number(raw.ephemeralStartTimestamp) + ephemeral_duration) * 1000
|
|
1033
|
+
: null,
|
|
1034
|
+
mime: typeof msg_content === 'object' && msg_type !== 'text'
|
|
1035
|
+
? (msg_content?.mimetype ?? 'application/octet-stream')
|
|
1036
|
+
: 'text/plain',
|
|
1037
|
+
caption: typeof msg_content === 'string'
|
|
1038
|
+
? msg_content
|
|
1039
|
+
: msg_type === 'event'
|
|
1040
|
+
? (msg_content?.description ?? '')
|
|
1041
|
+
: (msg_content?.caption ??
|
|
1042
|
+
msg_content?.text ??
|
|
1043
|
+
msg_content?.name ??
|
|
1044
|
+
msg_content?.displayName ??
|
|
1045
|
+
''),
|
|
1046
|
+
edited: false,
|
|
1047
|
+
raw,
|
|
1048
|
+
};
|
|
810
1049
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
/** Obtiene un mensaje por CID/MID. */
|
|
826
|
-
async get(cid, mid) {
|
|
827
|
-
const jid = await wa._resolve_jid(cid);
|
|
828
|
-
if (!jid) {
|
|
829
|
-
return null;
|
|
830
|
-
}
|
|
831
|
-
const doc = deserialize(await wa.engine.get(`/chat/${jid}/message/${mid}`));
|
|
832
|
-
return doc ? build_instance(doc) : null;
|
|
833
|
-
},
|
|
834
|
-
/** Pagina mensajes de un chat. */
|
|
835
|
-
async list(cid, offset = 0, limit = 50) {
|
|
836
|
-
const jid = await wa._resolve_jid(cid);
|
|
837
|
-
const result = [];
|
|
838
|
-
if (jid) {
|
|
839
|
-
for (const raw of await wa.engine.list(`/chat/${jid}/message`, offset, limit)) {
|
|
840
|
-
const doc = deserialize(raw);
|
|
841
|
-
if (doc) {
|
|
842
|
-
result.push(await build_instance(doc));
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
return result;
|
|
847
|
-
},
|
|
848
|
-
/** Cuenta mensajes de un chat. */
|
|
849
|
-
async count(cid) {
|
|
850
|
-
const jid = await wa._resolve_jid(cid);
|
|
851
|
-
return jid ? wa.engine.count(`/chat/${jid}/message`) : 0;
|
|
852
|
-
},
|
|
853
|
-
async text(cid, caption, opts = {}) {
|
|
854
|
-
return send(cid, { text: caption }, undefined, opts.mid);
|
|
855
|
-
},
|
|
856
|
-
async image(cid, buf, opts = {}) {
|
|
857
|
-
return send(cid, { image: buf, caption: opts.caption }, buf, opts.mid);
|
|
858
|
-
},
|
|
859
|
-
async video(cid, buf, opts = {}) {
|
|
860
|
-
return send(cid, { video: buf, caption: opts.caption }, buf, opts.mid);
|
|
861
|
-
},
|
|
862
|
-
async audio(cid, buf, opts = {}) {
|
|
863
|
-
return send(cid, { audio: buf, ptt: opts.ptt ?? true }, buf, opts.mid);
|
|
864
|
-
},
|
|
865
|
-
async location(cid, loc, opts = {}) {
|
|
866
|
-
return send(cid, { location: { degreesLatitude: loc.lat, degreesLongitude: loc.lng } }, undefined, opts.mid);
|
|
867
|
-
},
|
|
868
|
-
async poll(cid, p, opts = {}) {
|
|
869
|
-
const multiple = opts.multiple ?? false;
|
|
870
|
-
return send(cid, {
|
|
871
|
-
poll: {
|
|
872
|
-
name: p.content,
|
|
873
|
-
values: p.options.map((o) => o.content),
|
|
874
|
-
selectableCount: multiple ? 0 : 1,
|
|
875
|
-
},
|
|
876
|
-
}, undefined, opts.mid, { multiple });
|
|
877
|
-
},
|
|
878
|
-
async document(cid, buf, opts) {
|
|
879
|
-
return send(cid, {
|
|
880
|
-
document: buf,
|
|
881
|
-
fileName: opts.file_name,
|
|
882
|
-
mimetype: opts.mimetype ?? 'application/octet-stream',
|
|
883
|
-
caption: opts.caption,
|
|
884
|
-
}, buf, opts.mid);
|
|
885
|
-
},
|
|
886
|
-
async vcard(cid, contacts, opts = {}) {
|
|
887
|
-
const built = contacts.map((c) => ({
|
|
888
|
-
displayName: c.name,
|
|
889
|
-
vcard: build_vcard(c.name, c.phone),
|
|
890
|
-
}));
|
|
891
|
-
const binary = Buffer.from(built.map((c) => c.vcard).join('\n'), 'utf-8');
|
|
892
|
-
return send(cid, { contacts: { contacts: built } }, binary, opts.mid);
|
|
893
|
-
},
|
|
894
|
-
async event(cid, data, opts = {}) {
|
|
895
|
-
const binary = Buffer.from(JSON.stringify({
|
|
896
|
-
name: data.name,
|
|
897
|
-
caption: data.caption,
|
|
898
|
-
start: data.start.getTime(),
|
|
899
|
-
end: data.end?.getTime() ?? null,
|
|
900
|
-
}), 'utf-8');
|
|
901
|
-
return send(cid, {
|
|
902
|
-
event: {
|
|
903
|
-
name: data.name,
|
|
904
|
-
description: data.caption,
|
|
905
|
-
startDate: data.start,
|
|
906
|
-
endDate: data.end,
|
|
907
|
-
location: data.place
|
|
908
|
-
? { degreesLatitude: data.place.lat, degreesLongitude: data.place.lng }
|
|
909
|
-
: undefined,
|
|
910
|
-
},
|
|
911
|
-
}, binary, opts.mid);
|
|
912
|
-
},
|
|
913
|
-
async edit(cid, mid, text) {
|
|
914
|
-
const m = await api.get(cid, mid);
|
|
915
|
-
return m ? m.edit(text) : false;
|
|
916
|
-
},
|
|
917
|
-
async delete(cid, mid, all = true) {
|
|
918
|
-
const m = await api.get(cid, mid);
|
|
919
|
-
return m ? m.delete(all) : false;
|
|
920
|
-
},
|
|
921
|
-
async react(cid, mid, emoji) {
|
|
922
|
-
const m = await api.get(cid, mid);
|
|
923
|
-
return m ? m.react(emoji) : false;
|
|
924
|
-
},
|
|
925
|
-
async forward(cid, mid, target) {
|
|
926
|
-
const m = await api.get(cid, mid);
|
|
927
|
-
return m ? m.forward(target) : false;
|
|
928
|
-
},
|
|
929
|
-
async seen(cid, mid) {
|
|
930
|
-
const m = await api.get(cid, mid);
|
|
931
|
-
return m ? m.seen() : false;
|
|
932
|
-
},
|
|
933
|
-
async star(cid, mid, value) {
|
|
934
|
-
const m = await api.get(cid, mid);
|
|
935
|
-
return m ? m.star(value) : false;
|
|
936
|
-
},
|
|
937
|
-
watch(cid, mid, handler) {
|
|
938
|
-
return wa.on('message:updated', (updated) => {
|
|
939
|
-
if (updated.cid === cid && updated.id === mid) {
|
|
940
|
-
handler(updated);
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
},
|
|
1050
|
+
else {
|
|
1051
|
+
doc = raw;
|
|
1052
|
+
}
|
|
1053
|
+
const types = {
|
|
1054
|
+
text: Text,
|
|
1055
|
+
image: Image,
|
|
1056
|
+
video: Video,
|
|
1057
|
+
audio: Audio,
|
|
1058
|
+
sticker: Sticker,
|
|
1059
|
+
document: Document,
|
|
1060
|
+
location: Location,
|
|
1061
|
+
poll: Poll,
|
|
1062
|
+
vcard: VCard,
|
|
1063
|
+
event: Event,
|
|
944
1064
|
};
|
|
945
|
-
return
|
|
1065
|
+
return new (types[doc.type] ?? Message)(wa, doc);
|
|
946
1066
|
}
|
|
947
1067
|
//# sourceMappingURL=index.js.map
|