alipclutch-baileys 8.4.1 → 8.5.2
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/lib/Socket/messages-send.js +26 -67
- package/lib/Socket/setup.js +380 -332
- package/lib/Socket/setup.ts +595 -191
- package/lib/Socket/socket.d.ts +270 -43
- package/package.json +4 -4
- package/LICENSE +0 -23
package/lib/Socket/setup.ts
CHANGED
|
@@ -1,219 +1,623 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface MediaUploadOptions {
|
|
6
|
-
fileEncSha256?: Buffer;
|
|
7
|
-
mediaType?: string;
|
|
8
|
-
newsletter?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type WAMediaUploadFunction = (
|
|
12
|
-
stream: Buffer | NodeJS.ReadableStream,
|
|
13
|
-
options?: MediaUploadOptions
|
|
14
|
-
) => Promise<{ url: string; directPath: string }>;
|
|
1
|
+
/* modified by alip */
|
|
2
|
+
const WAProto = require('../../WAProto').proto;
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const Utils_1 = require("../Utils");
|
|
15
5
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
class yaoii {
|
|
7
|
+
constructor(utils, waUploadToServer, relayMessageFn) {
|
|
8
|
+
this.utils = utils;
|
|
9
|
+
this.relayMessage = relayMessageFn
|
|
10
|
+
this.waUploadToServer = waUploadToServer;
|
|
11
|
+
this.bail = {
|
|
12
|
+
generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
|
|
13
|
+
generateMessageID: Utils_1.generateMessageID,
|
|
14
|
+
getContentType: (msg) => Object.keys(msg.message || {})[0]
|
|
15
|
+
};
|
|
21
16
|
}
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
isAvatar?: boolean;
|
|
35
|
-
isAiSticker?: boolean;
|
|
36
|
-
isLottie?: boolean;
|
|
18
|
+
detectType(content) {
|
|
19
|
+
if (content.requestPaymentMessage) return 'PAYMENT';
|
|
20
|
+
if (content.productMessage) return 'PRODUCT';
|
|
21
|
+
if (content.interactiveMessage) return 'INTERACTIVE';
|
|
22
|
+
if (content.albumMessage) return 'ALBUM';
|
|
23
|
+
if (content.eventMessage) return 'EVENT';
|
|
24
|
+
if (content.pollResultMessage) return 'POLL_RESULT';
|
|
25
|
+
if (content.listMessage) return 'LIST';
|
|
26
|
+
if (content.groupStatusMessage) return 'GROUP_STORY';
|
|
27
|
+
if (content.groupStoryMessage) return 'GROUP_STORY';
|
|
28
|
+
return null;
|
|
37
29
|
}
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
31
|
+
async handlePayment(content, quoted) {
|
|
32
|
+
const data = content.requestPaymentMessage;
|
|
33
|
+
let notes = {};
|
|
34
|
+
|
|
35
|
+
if (data.sticker?.stickerMessage) {
|
|
36
|
+
notes = {
|
|
37
|
+
stickerMessage: {
|
|
38
|
+
...data.sticker.stickerMessage,
|
|
39
|
+
contextInfo: {
|
|
40
|
+
stanzaId: quoted?.key?.id,
|
|
41
|
+
participant: quoted?.key?.participant || content.sender,
|
|
42
|
+
quotedMessage: quoted?.message
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
} else if (data.note) {
|
|
47
|
+
notes = {
|
|
48
|
+
extendedTextMessage: {
|
|
49
|
+
text: data.note,
|
|
50
|
+
contextInfo: {
|
|
51
|
+
stanzaId: quoted?.key?.id,
|
|
52
|
+
participant: quoted?.key?.participant || content.sender,
|
|
53
|
+
quotedMessage: quoted?.message
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
|
|
61
|
+
expiryTimestamp: data.expiry || 0,
|
|
62
|
+
amount1000: data.amount || 0,
|
|
63
|
+
currencyCodeIso4217: data.currency || "IDR",
|
|
64
|
+
requestFrom: data.from || "0@s.whatsapp.net",
|
|
65
|
+
noteMessage: notes,
|
|
66
|
+
background: data.background ?? {
|
|
67
|
+
id: "DEFAULT",
|
|
68
|
+
placeholderArgb: 0xFFF0F0F0
|
|
69
|
+
}
|
|
70
|
+
})
|
|
55
71
|
};
|
|
56
72
|
}
|
|
73
|
+
|
|
74
|
+
async handleProduct(content, jid, quoted) {
|
|
75
|
+
const {
|
|
76
|
+
title,
|
|
77
|
+
description,
|
|
78
|
+
thumbnail,
|
|
79
|
+
productId,
|
|
80
|
+
retailerId,
|
|
81
|
+
url,
|
|
82
|
+
body = "",
|
|
83
|
+
footer = "",
|
|
84
|
+
buttons = [],
|
|
85
|
+
priceAmount1000 = null,
|
|
86
|
+
currencyCode = "IDR"
|
|
87
|
+
} = content.productMessage;
|
|
57
88
|
|
|
58
|
-
|
|
59
|
-
title: string;
|
|
60
|
-
description: string;
|
|
61
|
-
thumbnail: Buffer | { url: string };
|
|
62
|
-
productId: string;
|
|
63
|
-
retailerId: string;
|
|
64
|
-
url: string;
|
|
65
|
-
body?: string;
|
|
66
|
-
footer?: string;
|
|
67
|
-
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
68
|
-
priceAmount1000?: number | null;
|
|
69
|
-
currencyCode?: string;
|
|
70
|
-
}
|
|
89
|
+
let productImage;
|
|
71
90
|
|
|
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
|
-
|
|
91
|
+
if (Buffer.isBuffer(thumbnail)) {
|
|
92
|
+
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
93
|
+
{ image: thumbnail },
|
|
94
|
+
{ upload: this.waUploadToServer }
|
|
95
|
+
);
|
|
96
|
+
productImage = imageMessage;
|
|
97
|
+
} else if (typeof thumbnail === 'object' && thumbnail.url) {
|
|
98
|
+
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
99
|
+
{ image: { url: thumbnail.url }},
|
|
100
|
+
{ upload: this.waUploadToServer }
|
|
101
|
+
);
|
|
102
|
+
productImage = imageMessage;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
viewOnceMessage: {
|
|
107
|
+
message: {
|
|
108
|
+
interactiveMessage: {
|
|
109
|
+
body: { text: body },
|
|
110
|
+
footer: { text: footer },
|
|
111
|
+
header: {
|
|
112
|
+
title,
|
|
113
|
+
hasMediaAttachment: true,
|
|
114
|
+
productMessage: {
|
|
115
|
+
product: {
|
|
116
|
+
productImage,
|
|
117
|
+
productId,
|
|
118
|
+
title,
|
|
119
|
+
description,
|
|
120
|
+
currencyCode,
|
|
121
|
+
priceAmount1000,
|
|
122
|
+
retailerId,
|
|
123
|
+
url,
|
|
124
|
+
productImageCount: 1
|
|
125
|
+
},
|
|
126
|
+
businessOwnerJid: "0@s.whatsapp.net"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
nativeFlowMessage: { buttons }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
98
133
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async handleInteractive(content, jid, quoted) {
|
|
137
|
+
const {
|
|
138
|
+
title,
|
|
139
|
+
footer,
|
|
140
|
+
thumbnail,
|
|
141
|
+
image,
|
|
142
|
+
video,
|
|
143
|
+
document,
|
|
144
|
+
mimetype,
|
|
145
|
+
fileName,
|
|
146
|
+
jpegThumbnail,
|
|
147
|
+
contextInfo,
|
|
148
|
+
externalAdReply,
|
|
149
|
+
buttons = [],
|
|
150
|
+
nativeFlowMessage,
|
|
151
|
+
header
|
|
152
|
+
} = content.interactiveMessage;
|
|
153
|
+
|
|
154
|
+
let media = null;
|
|
155
|
+
let mediaType = null;
|
|
156
|
+
|
|
157
|
+
const getMediaPayload = (mediaData, type) => {
|
|
158
|
+
if (typeof mediaData === 'object' && mediaData.url) {
|
|
159
|
+
return { [type]: { url: mediaData.url } };
|
|
160
|
+
}
|
|
161
|
+
return { [type]: mediaData };
|
|
109
162
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
163
|
+
|
|
164
|
+
if (thumbnail) {
|
|
165
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
166
|
+
getMediaPayload(thumbnail, 'image'),
|
|
167
|
+
{ upload: this.waUploadToServer }
|
|
168
|
+
);
|
|
169
|
+
mediaType = 'image';
|
|
170
|
+
} else if (image) {
|
|
171
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
172
|
+
getMediaPayload(image, 'image'),
|
|
173
|
+
{ upload: this.waUploadToServer }
|
|
174
|
+
);
|
|
175
|
+
mediaType = 'image';
|
|
176
|
+
} else if (video) {
|
|
177
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
178
|
+
getMediaPayload(video, 'video'),
|
|
179
|
+
{ upload: this.waUploadToServer }
|
|
180
|
+
);
|
|
181
|
+
mediaType = 'video';
|
|
182
|
+
} else if (document) {
|
|
183
|
+
let documentPayload = getMediaPayload(document, 'document');
|
|
184
|
+
|
|
185
|
+
if (jpegThumbnail) {
|
|
186
|
+
documentPayload.jpegThumbnail = jpegThumbnail;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
190
|
+
documentPayload,
|
|
191
|
+
{ upload: this.waUploadToServer }
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (fileName) {
|
|
195
|
+
media.documentMessage.fileName = fileName;
|
|
196
|
+
}
|
|
197
|
+
if (mimetype) {
|
|
198
|
+
media.documentMessage.mimetype = mimetype;
|
|
199
|
+
}
|
|
200
|
+
mediaType = 'document';
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let interactiveMessage = {
|
|
204
|
+
body: { text: title || "" },
|
|
205
|
+
footer: { text: footer || "" }
|
|
115
206
|
};
|
|
116
|
-
|
|
207
|
+
|
|
208
|
+
if (buttons && buttons.length > 0) {
|
|
209
|
+
interactiveMessage.nativeFlowMessage = {
|
|
210
|
+
buttons: buttons
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
if (nativeFlowMessage) {
|
|
214
|
+
interactiveMessage.nativeFlowMessage = {
|
|
215
|
+
...interactiveMessage.nativeFlowMessage,
|
|
216
|
+
...nativeFlowMessage
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
} else if (nativeFlowMessage) {
|
|
220
|
+
interactiveMessage.nativeFlowMessage = nativeFlowMessage;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (media) {
|
|
224
|
+
interactiveMessage.header = {
|
|
225
|
+
title: header || "",
|
|
226
|
+
hasMediaAttachment: true,
|
|
227
|
+
...media
|
|
228
|
+
};
|
|
229
|
+
} else {
|
|
230
|
+
interactiveMessage.header = {
|
|
231
|
+
title: header || "",
|
|
232
|
+
hasMediaAttachment: false
|
|
233
|
+
};
|
|
234
|
+
}
|
|
117
235
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
236
|
+
let finalContextInfo = {};
|
|
237
|
+
|
|
238
|
+
const inputContextInfo = contextInfo || {};
|
|
239
|
+
if (quoted) {
|
|
240
|
+
inputContextInfo.stanzaId = quoted.key.id;
|
|
241
|
+
inputContextInfo.participant = quoted.key.participant || quoted.key.remoteJid;
|
|
242
|
+
inputContextInfo.quotedMessage = quoted.message;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (Object.keys(inputContextInfo).length > 0) {
|
|
246
|
+
finalContextInfo = {
|
|
247
|
+
mentionedJid: inputContextInfo.mentionedJid || [],
|
|
248
|
+
forwardingScore: inputContextInfo.forwardingScore || 0,
|
|
249
|
+
isForwarded: inputContextInfo.isForwarded || false,
|
|
250
|
+
...inputContextInfo
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (externalAdReply) {
|
|
255
|
+
finalContextInfo.externalAdReply = {
|
|
256
|
+
title: externalAdReply.title || "",
|
|
257
|
+
body: externalAdReply.body || "",
|
|
258
|
+
mediaType: externalAdReply.mediaType || 1,
|
|
259
|
+
thumbnailUrl: externalAdReply.thumbnailUrl || "",
|
|
260
|
+
mediaUrl: externalAdReply.mediaUrl || "",
|
|
261
|
+
sourceUrl: externalAdReply.sourceUrl || "",
|
|
262
|
+
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
263
|
+
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
264
|
+
...externalAdReply
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (Object.keys(finalContextInfo).length > 0) {
|
|
269
|
+
interactiveMessage.contextInfo = finalContextInfo;
|
|
270
|
+
}
|
|
122
271
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
name: string;
|
|
272
|
+
return {
|
|
273
|
+
interactiveMessage: interactiveMessage
|
|
274
|
+
};
|
|
127
275
|
}
|
|
276
|
+
|
|
277
|
+
async handleAlbum(content, jid, quoted) {
|
|
278
|
+
const array = content.albumMessage;
|
|
279
|
+
const album = await this.utils.generateWAMessageFromContent(jid, {
|
|
280
|
+
messageContextInfo: {
|
|
281
|
+
messageSecret: crypto.randomBytes(32),
|
|
282
|
+
},
|
|
283
|
+
albumMessage: {
|
|
284
|
+
expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
|
|
285
|
+
expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
|
|
286
|
+
},
|
|
287
|
+
}, {
|
|
288
|
+
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
289
|
+
quoted,
|
|
290
|
+
upload: this.waUploadToServer
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
await this.relayMessage(jid, album.message, {
|
|
294
|
+
messageId: album.key.id,
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
for (let content of array) {
|
|
298
|
+
const img = await this.utils.generateWAMessage(jid, content, {
|
|
299
|
+
upload: this.waUploadToServer,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
img.message.messageContextInfo = {
|
|
303
|
+
messageSecret: crypto.randomBytes(32),
|
|
304
|
+
messageAssociation: {
|
|
305
|
+
associationType: 1,
|
|
306
|
+
parentMessageKey: album.key,
|
|
307
|
+
},
|
|
308
|
+
participant: "0@s.whatsapp.net",
|
|
309
|
+
remoteJid: "status@broadcast",
|
|
310
|
+
forwardingScore: 99999,
|
|
311
|
+
isForwarded: true,
|
|
312
|
+
mentionedJid: [jid],
|
|
313
|
+
starred: true,
|
|
314
|
+
labels: ["Y", "Important"],
|
|
315
|
+
isHighlighted: true,
|
|
316
|
+
businessMessageForwardInfo: {
|
|
317
|
+
businessOwnerJid: jid,
|
|
318
|
+
},
|
|
319
|
+
dataSharingContext: {
|
|
320
|
+
showMmDisclosure: true,
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
img.message.forwardedNewsletterMessageInfo = {
|
|
325
|
+
newsletterJid: "0@newsletter",
|
|
326
|
+
serverMessageId: 1,
|
|
327
|
+
newsletterName: `WhatsApp`,
|
|
328
|
+
contentType: 1,
|
|
329
|
+
timestamp: new Date().toISOString(),
|
|
330
|
+
senderName: "Alip Clutch",
|
|
331
|
+
content: "Text Message",
|
|
332
|
+
priority: "high",
|
|
333
|
+
status: "sent",
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
img.message.disappearingMode = {
|
|
337
|
+
initiator: 3,
|
|
338
|
+
trigger: 4,
|
|
339
|
+
initiatorDeviceJid: jid,
|
|
340
|
+
initiatedByExternalService: true,
|
|
341
|
+
initiatedByUserDevice: true,
|
|
342
|
+
initiatedBySystem: true,
|
|
343
|
+
initiatedByServer: true,
|
|
344
|
+
initiatedByAdmin: true,
|
|
345
|
+
initiatedByUser: true,
|
|
346
|
+
initiatedByApp: true,
|
|
347
|
+
initiatedByBot: true,
|
|
348
|
+
initiatedByMe: true,
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
await this.relayMessage(jid, img.message, {
|
|
352
|
+
messageId: img.key.id,
|
|
353
|
+
quoted: {
|
|
354
|
+
key: {
|
|
355
|
+
remoteJid: album.key.remoteJid,
|
|
356
|
+
id: album.key.id,
|
|
357
|
+
fromMe: true,
|
|
358
|
+
participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
359
|
+
},
|
|
360
|
+
message: album.message,
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
return album;
|
|
365
|
+
}
|
|
128
366
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
367
|
+
async handleEvent(content, jid, quoted) {
|
|
368
|
+
const eventData = content.eventMessage;
|
|
369
|
+
|
|
370
|
+
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
371
|
+
viewOnceMessage: {
|
|
372
|
+
message: {
|
|
373
|
+
messageContextInfo: {
|
|
374
|
+
deviceListMetadata: {},
|
|
375
|
+
deviceListMetadataVersion: 2,
|
|
376
|
+
messageSecret: crypto.randomBytes(32),
|
|
377
|
+
supportPayload: JSON.stringify({
|
|
378
|
+
version: 2,
|
|
379
|
+
is_ai_message: true,
|
|
380
|
+
should_show_system_message: true,
|
|
381
|
+
ticket_id: crypto.randomBytes(16).toString('hex')
|
|
382
|
+
})
|
|
383
|
+
},
|
|
384
|
+
eventMessage: {
|
|
385
|
+
contextInfo: {
|
|
386
|
+
mentionedJid: [jid],
|
|
387
|
+
participant: jid,
|
|
388
|
+
remoteJid: "status@broadcast",
|
|
389
|
+
forwardedNewsletterMessageInfo: {
|
|
390
|
+
newsletterName: "alip clutch.",
|
|
391
|
+
newsletterJid: "120363401467939056@newsletter",
|
|
392
|
+
serverMessageId: 1
|
|
393
|
+
},
|
|
394
|
+
...(quoted ? {
|
|
395
|
+
stanzaId: quoted.key.id,
|
|
396
|
+
participant: quoted.key.participant || quoted.key.remoteJid,
|
|
397
|
+
quotedMessage: quoted.message
|
|
398
|
+
} : {})
|
|
399
|
+
},
|
|
400
|
+
isCanceled: eventData.isCanceled || false,
|
|
401
|
+
name: eventData.name,
|
|
402
|
+
description: eventData.description,
|
|
403
|
+
location: eventData.location || {
|
|
404
|
+
degreesLatitude: 0,
|
|
405
|
+
degreesLongitude: 0,
|
|
406
|
+
name: "Location"
|
|
407
|
+
},
|
|
408
|
+
joinLink: eventData.joinLink || '',
|
|
409
|
+
startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
|
|
410
|
+
endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
|
|
411
|
+
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}, { quoted });
|
|
416
|
+
|
|
417
|
+
await this.relayMessage(jid, msg.message, {
|
|
418
|
+
messageId: msg.key.id
|
|
419
|
+
});
|
|
420
|
+
return msg;
|
|
138
421
|
}
|
|
422
|
+
|
|
423
|
+
async handlePollResult(content, jid, quoted) {
|
|
424
|
+
const pollData = content.pollResultMessage;
|
|
139
425
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
426
|
+
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
427
|
+
pollResultSnapshotMessage: {
|
|
428
|
+
name: pollData.name,
|
|
429
|
+
pollVotes: pollData.pollVotes.map(vote => ({
|
|
430
|
+
optionName: vote.optionName,
|
|
431
|
+
optionVoteCount: typeof vote.optionVoteCount === 'number'
|
|
432
|
+
? vote.optionVoteCount.toString()
|
|
433
|
+
: vote.optionVoteCount
|
|
434
|
+
}))
|
|
435
|
+
}
|
|
436
|
+
}, {
|
|
437
|
+
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
438
|
+
quoted
|
|
439
|
+
});
|
|
144
440
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
interface MessageContent {
|
|
151
|
-
requestPaymentMessage?: PaymentMessage;
|
|
152
|
-
productMessage?: ProductMessage;
|
|
153
|
-
interactiveMessage?: InteractiveMessage;
|
|
154
|
-
albumMessage?: AlbumItem[];
|
|
155
|
-
eventMessage?: EventMessage;
|
|
156
|
-
pollResultMessage?: PollResultMessage;
|
|
157
|
-
sender?: string;
|
|
441
|
+
await this.relayMessage(jid, msg.message, {
|
|
442
|
+
messageId: msg.key.id
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
return msg;
|
|
158
446
|
}
|
|
159
447
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
448
|
+
async handleList(content, jid, quoted) {
|
|
449
|
+
const data = content.listMessage;
|
|
450
|
+
|
|
451
|
+
const listMessagePayload = WAProto.Message.ListMessage.fromObject({
|
|
452
|
+
title: data.title || '',
|
|
453
|
+
description: data.description || '',
|
|
454
|
+
buttonText: data.buttonText || 'Pilih',
|
|
455
|
+
sections: data.sections.map(section => ({
|
|
456
|
+
title: section.title,
|
|
457
|
+
rows: section.rows.map(row => ({
|
|
458
|
+
rowId: row.rowId || this.utils.generateMessageID(),
|
|
459
|
+
title: row.title,
|
|
460
|
+
description: row.description || ''
|
|
461
|
+
}))
|
|
462
|
+
})),
|
|
463
|
+
listType: data.listType || 1,
|
|
464
|
+
footerText: data.footer || ''
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
const listContent = {
|
|
468
|
+
listMessage: listMessagePayload
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
const contextInfo = data.contextInfo || {};
|
|
164
472
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
473
|
+
if (quoted) {
|
|
474
|
+
contextInfo.stanzaId = quoted.key.id;
|
|
475
|
+
contextInfo.participant = quoted.key.participant || quoted.key.remoteJid;
|
|
476
|
+
contextInfo.quotedMessage = quoted.message;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (Object.keys(contextInfo).length > 0) {
|
|
480
|
+
listContent.listMessage.contextInfo = contextInfo;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const msg = await this.utils.generateWAMessageFromContent(
|
|
484
|
+
jid,
|
|
485
|
+
listContent,
|
|
486
|
+
{ quoted }
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
490
|
+
|
|
491
|
+
return msg;
|
|
171
492
|
}
|
|
172
|
-
}
|
|
173
493
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
494
|
+
async handleGroupStory(content, jid, quoted) {
|
|
495
|
+
if (content.groupStatusMessage) {
|
|
496
|
+
const storyData = content.groupStatusMessage;
|
|
497
|
+
let waMsgContent;
|
|
498
|
+
|
|
499
|
+
if (storyData.message) {
|
|
500
|
+
waMsgContent = storyData;
|
|
501
|
+
} else {
|
|
502
|
+
if (typeof this.bail?.generateWAMessageContent === "function") {
|
|
503
|
+
waMsgContent = await this.bail.generateWAMessageContent(storyData, {
|
|
504
|
+
upload: this.waUploadToServer
|
|
505
|
+
});
|
|
506
|
+
} else if (typeof this.utils?.generateWAMessageContent === "function") {
|
|
507
|
+
waMsgContent = await this.utils.generateWAMessageContent(storyData, {
|
|
508
|
+
upload: this.waUploadToServer
|
|
509
|
+
});
|
|
510
|
+
} else if (typeof this.utils?.prepareMessageContent === "function") {
|
|
511
|
+
waMsgContent = await this.utils.prepareMessageContent(storyData, {
|
|
512
|
+
upload: this.waUploadToServer
|
|
513
|
+
});
|
|
514
|
+
} else {
|
|
515
|
+
waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
|
|
516
|
+
upload: this.waUploadToServer
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let msg = {
|
|
522
|
+
message: {
|
|
523
|
+
groupStatusMessageV2: {
|
|
524
|
+
message: waMsgContent.message || waMsgContent
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
return await this.relayMessage(jid, msg.message, {
|
|
530
|
+
messageId: this.bail.generateMessageID()
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
} else if (content.groupStoryMessage) {
|
|
534
|
+
const { groupStoryMessage } = content;
|
|
535
|
+
|
|
536
|
+
if (!this.utils.isJidGroup(jid)) {
|
|
537
|
+
throw new Error("Group Story messages must be sent to a group JID.");
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
let mediaContent = {};
|
|
541
|
+
|
|
542
|
+
if (groupStoryMessage.image || groupStoryMessage.video) {
|
|
543
|
+
const mediaData = groupStoryMessage.image || groupStoryMessage.video;
|
|
544
|
+
const mediaType = groupStoryMessage.image ? 'image' : 'video';
|
|
545
|
+
|
|
546
|
+
let stream;
|
|
547
|
+
if (Buffer.isBuffer(mediaData)) {
|
|
548
|
+
stream = mediaData;
|
|
549
|
+
} else if (typeof mediaData === 'object' && mediaData.url) {
|
|
550
|
+
throw new Error("Group Story media from URL is not supported in this simplified handler. Use Buffer or fetch it first.");
|
|
551
|
+
} else {
|
|
552
|
+
stream = Buffer.from(mediaData, 'base64');
|
|
553
|
+
}
|
|
180
554
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
555
|
+
const upload = await this.waUploadToServer(stream, {
|
|
556
|
+
mediaType: mediaType,
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
mediaContent = {
|
|
560
|
+
[mediaType + 'Message']: {
|
|
561
|
+
url: upload.url,
|
|
562
|
+
mimetype: mediaType === 'image' ? 'image/jpeg' : 'video/mp4',
|
|
563
|
+
caption: groupStoryMessage.caption,
|
|
564
|
+
fileSha256: upload.fileSha256,
|
|
565
|
+
fileEncSha256: upload.fileEncSha256,
|
|
566
|
+
mediaKey: upload.mediaKey,
|
|
567
|
+
fileLength: upload.fileLength,
|
|
568
|
+
directPath: upload.directPath,
|
|
569
|
+
mediaKeyTimestamp: this.utils.unixTimestampSeconds(),
|
|
570
|
+
jpegThumbnail: groupStoryMessage.jpegThumbnail,
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
} else if (groupStoryMessage.caption) {
|
|
574
|
+
mediaContent = {
|
|
575
|
+
extendedTextMessage: {
|
|
576
|
+
text: groupStoryMessage.caption
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
} else {
|
|
580
|
+
throw new Error("Group Story content must contain image, video, or caption.");
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const groupStatusMessageContent = {
|
|
584
|
+
groupStatusMessage: {
|
|
585
|
+
key: {
|
|
586
|
+
remoteJid: jid,
|
|
587
|
+
fromMe: true,
|
|
588
|
+
id: this.utils.generateMessageID(),
|
|
589
|
+
participant: this.utils.jidNormalizedUser(this.utils.auth.creds.me.id)
|
|
590
|
+
},
|
|
591
|
+
message: {
|
|
592
|
+
...mediaContent,
|
|
593
|
+
contextInfo: {
|
|
594
|
+
mentionedJid: groupStoryMessage.mentions || [],
|
|
595
|
+
...(quoted ? {
|
|
596
|
+
stanzaId: quoted.key.id,
|
|
597
|
+
participant: quoted.key.participant || quoted.key.remoteJid,
|
|
598
|
+
quotedMessage: quoted.message
|
|
599
|
+
} : {})
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
const fullMsg = await this.utils.generateWAMessageFromContent(
|
|
606
|
+
jid,
|
|
607
|
+
groupStatusMessageContent,
|
|
608
|
+
{ quoted, logger: this.utils.logger }
|
|
609
|
+
);
|
|
610
|
+
|
|
611
|
+
await this.relayMessage(jid, fullMsg.message, {
|
|
612
|
+
messageId: fullMsg.key.id,
|
|
613
|
+
type: 'group_status',
|
|
614
|
+
});
|
|
211
615
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
616
|
+
return fullMsg;
|
|
617
|
+
} else {
|
|
618
|
+
throw new Error("Invalid content for handleGroupStory. Neither groupStatusMessage nor groupStoryMessage found.");
|
|
619
|
+
}
|
|
620
|
+
}
|
|
217
621
|
}
|
|
218
622
|
|
|
219
|
-
|
|
623
|
+
module.exports = yaoii;
|