@gqb333/based 2.7.78 → 2.7.79
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/Utils/buttons.js +284 -0
- package/lib/index.js +7 -14
- package/package.json +1 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.sendButton = sendButton;
|
|
5
|
+
exports.sendButtonMessages = sendButtonMessages;
|
|
6
|
+
exports.sendQuickReply = sendQuickReply;
|
|
7
|
+
exports.sendList = sendList;
|
|
8
|
+
exports.sendUrl = sendUrl;
|
|
9
|
+
exports.sendCopy = sendCopy;
|
|
10
|
+
exports.createButtons = createButtons;
|
|
11
|
+
exports.createSection = createSection;
|
|
12
|
+
|
|
13
|
+
const { generateWAMessageFromContent, prepareWAMessageMedia } = require("./generics");
|
|
14
|
+
const { proto } = require("../../WAProto");
|
|
15
|
+
const fetch = (...args) => import('node-fetch').then(({ default: f }) => f(...args));
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Invia un messaggio con pulsanti quick_reply moderni
|
|
19
|
+
*/
|
|
20
|
+
async function sendButton(conn, jid, text = '', footer = '', buffer, buttons, quoted, options = {}) {
|
|
21
|
+
try {
|
|
22
|
+
let img, video;
|
|
23
|
+
|
|
24
|
+
if (buffer && /^https?:\/\//i.test(buffer)) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(buffer);
|
|
27
|
+
const contentType = response.headers.get('content-type');
|
|
28
|
+
if (/^image\//i.test(contentType)) {
|
|
29
|
+
img = await prepareWAMessageMedia({ image: { url: buffer } }, { upload: conn.waUploadToServer });
|
|
30
|
+
} else if (/^video\//i.test(contentType)) {
|
|
31
|
+
video = await prepareWAMessageMedia({ video: { url: buffer } }, { upload: conn.waUploadToServer });
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error('Errore caricamento media da URL:', e);
|
|
35
|
+
}
|
|
36
|
+
} else if (buffer) {
|
|
37
|
+
try {
|
|
38
|
+
const type = await conn.getFile(buffer);
|
|
39
|
+
if (/^image\//i.test(type.mime)) {
|
|
40
|
+
img = await prepareWAMessageMedia({ image: type.data }, { upload: conn.waUploadToServer });
|
|
41
|
+
} else if (/^video\//i.test(type.mime)) {
|
|
42
|
+
video = await prepareWAMessageMedia({ video: type.data }, { upload: conn.waUploadToServer });
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.error('Errore caricamento media da buffer:', e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const prep = generateWAMessageFromContent(jid, {
|
|
50
|
+
viewOnceMessage: {
|
|
51
|
+
message: {
|
|
52
|
+
interactiveMessage: {
|
|
53
|
+
body: { text },
|
|
54
|
+
footer: { text: footer },
|
|
55
|
+
header: {
|
|
56
|
+
hasMediaAttachment: !!(img || video),
|
|
57
|
+
...(img ? { imageMessage: img.imageMessage } : {}),
|
|
58
|
+
...(video ? { videoMessage: video.videoMessage } : {})
|
|
59
|
+
},
|
|
60
|
+
nativeFlowMessage: {
|
|
61
|
+
buttons: buttons.map(([title, id]) => ({
|
|
62
|
+
name: 'quick_reply',
|
|
63
|
+
buttonParamsJson: JSON.stringify({ display_text: title, id })
|
|
64
|
+
})),
|
|
65
|
+
messageParamsJson: ''
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, { quoted });
|
|
71
|
+
|
|
72
|
+
return await conn.relayMessage(jid, prep.message, { messageId: prep.key.id });
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('❌ Errore sendButton:', error);
|
|
75
|
+
return await conn.sendMessage(jid, { text }, quoted ? { quoted } : {});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Invia pulsanti template (metodo legacy)
|
|
81
|
+
*/
|
|
82
|
+
async function sendButtonMessages(conn, jid, text = '', footer = '', buffer, buttons, quoted, options) {
|
|
83
|
+
try {
|
|
84
|
+
if (buffer) {
|
|
85
|
+
try {
|
|
86
|
+
const type = await conn.getFile(buffer);
|
|
87
|
+
buffer = type.data;
|
|
88
|
+
} catch {}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const templateButtons = buttons.map(([btnText, id], index) => ({
|
|
92
|
+
index: index + 1,
|
|
93
|
+
quickReplyButton: { displayText: btnText, id }
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
return await conn.sendMessage(jid, {
|
|
97
|
+
text, footer, templateButtons,
|
|
98
|
+
...(buffer ? { image: buffer } : {})
|
|
99
|
+
}, options);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('❌ Errore sendButtonMessages:', error);
|
|
102
|
+
return await conn.sendMessage(jid, { text }, quoted ? { quoted } : {});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Invia quick_reply semplificato
|
|
108
|
+
*/
|
|
109
|
+
async function sendQuickReply(conn, jid, text, buttons, options = {}) {
|
|
110
|
+
try {
|
|
111
|
+
const { footer = '', quoted = null, title = '', image = null, video = null } = options;
|
|
112
|
+
|
|
113
|
+
if (!Array.isArray(buttons) || buttons.length === 0) throw new Error('Buttons deve essere un array non vuoto');
|
|
114
|
+
|
|
115
|
+
const buttonArray = buttons.map(btn => ({
|
|
116
|
+
name: 'quick_reply',
|
|
117
|
+
buttonParamsJson: JSON.stringify({
|
|
118
|
+
display_text: btn.text || btn.display_text || 'Button',
|
|
119
|
+
id: btn.id || btn.command || Math.random().toString(36)
|
|
120
|
+
})
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
let mediaHeader = {};
|
|
124
|
+
|
|
125
|
+
if (image) {
|
|
126
|
+
const prepared = typeof image === 'string' && /^https?:\/\//i.test(image)
|
|
127
|
+
? await prepareWAMessageMedia({ image: { url: image } }, { upload: conn.waUploadToServer })
|
|
128
|
+
: null;
|
|
129
|
+
mediaHeader.imageMessage = prepared ? prepared.imageMessage : image;
|
|
130
|
+
mediaHeader.hasMediaAttachment = true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (video) {
|
|
134
|
+
const prepared = typeof video === 'string' && /^https?:\/\//i.test(video)
|
|
135
|
+
? await prepareWAMessageMedia({ video: { url: video } }, { upload: conn.waUploadToServer })
|
|
136
|
+
: null;
|
|
137
|
+
mediaHeader.videoMessage = prepared ? prepared.videoMessage : video;
|
|
138
|
+
mediaHeader.hasMediaAttachment = true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const header = {
|
|
142
|
+
hasMediaAttachment: mediaHeader.hasMediaAttachment || false,
|
|
143
|
+
...(title ? { title } : {}),
|
|
144
|
+
...(mediaHeader.imageMessage ? { imageMessage: mediaHeader.imageMessage } : {}),
|
|
145
|
+
...(mediaHeader.videoMessage ? { videoMessage: mediaHeader.videoMessage } : {})
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const msg = generateWAMessageFromContent(jid, {
|
|
149
|
+
viewOnceMessage: {
|
|
150
|
+
message: {
|
|
151
|
+
messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 },
|
|
152
|
+
interactiveMessage: proto.Message.InteractiveMessage.create({
|
|
153
|
+
body: proto.Message.InteractiveMessage.Body.create({ text }),
|
|
154
|
+
footer: proto.Message.InteractiveMessage.Footer.create({ text: footer }),
|
|
155
|
+
header: proto.Message.InteractiveMessage.Header.create(header),
|
|
156
|
+
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
|
|
157
|
+
buttons: buttonArray,
|
|
158
|
+
messageParamsJson: ''
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}, quoted ? { quoted } : {});
|
|
164
|
+
|
|
165
|
+
return await conn.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error('❌ Errore sendQuickReply:', error);
|
|
168
|
+
return await conn.sendMessage(jid, { text }, quoted ? { quoted } : {});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Invia messaggio lista
|
|
174
|
+
*/
|
|
175
|
+
async function sendList(conn, jid, text, buttonText, sections, options = {}) {
|
|
176
|
+
try {
|
|
177
|
+
const { footer = '', quoted = null, title = '' } = options;
|
|
178
|
+
if (!Array.isArray(sections) || sections.length === 0) throw new Error('Sections deve essere un array non vuoto');
|
|
179
|
+
return await conn.sendMessage(jid, { text, footer, title, buttonText, sections }, quoted ? { quoted } : {});
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error('❌ Errore sendList:', error);
|
|
182
|
+
return await conn.sendMessage(jid, { text }, quoted ? { quoted } : {});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Invia pulsanti URL / Call
|
|
188
|
+
*/
|
|
189
|
+
async function sendUrl(conn, jid, text, buttons, options = {}) {
|
|
190
|
+
try {
|
|
191
|
+
const { footer = '', quoted = null, title = '' } = options;
|
|
192
|
+
if (!Array.isArray(buttons) || buttons.length === 0) throw new Error('Buttons deve essere un array non vuoto');
|
|
193
|
+
|
|
194
|
+
const buttonArray = buttons.map(btn => {
|
|
195
|
+
if (btn.url) return {
|
|
196
|
+
name: 'cta_url',
|
|
197
|
+
buttonParamsJson: JSON.stringify({ display_text: btn.text || 'Link', url: btn.url, merchant_url: btn.url })
|
|
198
|
+
};
|
|
199
|
+
if (btn.phoneNumber) return {
|
|
200
|
+
name: 'cta_call',
|
|
201
|
+
buttonParamsJson: JSON.stringify({ display_text: btn.text || 'Chiama', phone_number: btn.phoneNumber })
|
|
202
|
+
};
|
|
203
|
+
return null;
|
|
204
|
+
}).filter(Boolean);
|
|
205
|
+
|
|
206
|
+
if (buttonArray.length === 0) throw new Error('Nessun pulsante valido trovato');
|
|
207
|
+
|
|
208
|
+
const msg = generateWAMessageFromContent(jid, {
|
|
209
|
+
viewOnceMessage: {
|
|
210
|
+
message: {
|
|
211
|
+
messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 },
|
|
212
|
+
interactiveMessage: proto.Message.InteractiveMessage.create({
|
|
213
|
+
body: proto.Message.InteractiveMessage.Body.create({ text }),
|
|
214
|
+
footer: proto.Message.InteractiveMessage.Footer.create({ text: footer }),
|
|
215
|
+
header: proto.Message.InteractiveMessage.Header.create({ hasMediaAttachment: false, ...(title ? { title } : {}) }),
|
|
216
|
+
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
|
|
217
|
+
buttons: buttonArray,
|
|
218
|
+
messageParamsJson: ''
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}, quoted ? { quoted } : {});
|
|
224
|
+
|
|
225
|
+
return await conn.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error('❌ Errore sendUrl:', error);
|
|
228
|
+
return await conn.sendMessage(jid, { text }, quoted ? { quoted } : {});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Invia pulsante copia codice
|
|
234
|
+
*/
|
|
235
|
+
async function sendCopy(conn, jid, text, copyText, options = {}) {
|
|
236
|
+
try {
|
|
237
|
+
const { footer = '', quoted = null, buttonText = 'Copia Codice' } = options;
|
|
238
|
+
|
|
239
|
+
const msg = generateWAMessageFromContent(jid, {
|
|
240
|
+
viewOnceMessage: {
|
|
241
|
+
message: {
|
|
242
|
+
messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 },
|
|
243
|
+
interactiveMessage: proto.Message.InteractiveMessage.create({
|
|
244
|
+
body: proto.Message.InteractiveMessage.Body.create({ text }),
|
|
245
|
+
footer: proto.Message.InteractiveMessage.Footer.create({ text: footer }),
|
|
246
|
+
header: proto.Message.InteractiveMessage.Header.create({ hasMediaAttachment: false }),
|
|
247
|
+
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
|
|
248
|
+
buttons: [{ name: 'cta_copy', buttonParamsJson: JSON.stringify({ display_text: buttonText, copy_code: copyText }) }],
|
|
249
|
+
messageParamsJson: ''
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}, quoted ? { quoted } : {});
|
|
255
|
+
|
|
256
|
+
return await conn.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error('❌ Errore sendCopy:', error);
|
|
259
|
+
return await conn.sendMessage(jid, { text }, quoted ? { quoted } : {});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Helper: crea array pulsanti
|
|
265
|
+
*/
|
|
266
|
+
function createButtons(buttons) {
|
|
267
|
+
return buttons.map(btn =>
|
|
268
|
+
Array.isArray(btn) ? { id: btn[0], text: btn[1] } : { id: btn.id, text: btn.text }
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Helper: crea sezione per sendList
|
|
274
|
+
*/
|
|
275
|
+
function createSection(title, rows) {
|
|
276
|
+
return {
|
|
277
|
+
title,
|
|
278
|
+
rows: rows.map(row => ({
|
|
279
|
+
title: row.title,
|
|
280
|
+
description: row.description || '',
|
|
281
|
+
rowId: row.id || row.rowId
|
|
282
|
+
}))
|
|
283
|
+
};
|
|
284
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -3,22 +3,14 @@
|
|
|
3
3
|
const chalk = require("chalk");
|
|
4
4
|
|
|
5
5
|
if (process.env.NODE_ENV !== 'test' && process.env.SUPPRESS_BANNER !== 'true') {
|
|
6
|
-
const empty = chalk.hex('#00bfff')('┃') + ' '.repeat(48) + chalk.hex('#00bfff')('┃');
|
|
7
|
-
|
|
8
6
|
const banner = `
|
|
9
|
-
${chalk.hex('#00bfff')('
|
|
10
|
-
${chalk.hex('#00bfff')('
|
|
11
|
-
${chalk.hex('#00bfff')('
|
|
12
|
-
${chalk.hex('#00bfff')('
|
|
13
|
-
${chalk.hex('#00bfff')('
|
|
14
|
-
${chalk.hex('#00bfff')('
|
|
15
|
-
${empty}
|
|
16
|
-
${chalk.hex('#00bfff')('┃')}${chalk.white().bold(' baileys by Gab @trucidarle ')}${chalk.hex('#00bfff')('┃')}
|
|
17
|
-
${chalk.hex('#00bfff')('┃')}${chalk.hex('#888888')(' powered by 333 staff ')}${chalk.hex('#00bfff')('┃')}
|
|
18
|
-
${empty}
|
|
19
|
-
${chalk.hex('#00bfff')('┗' + '━'.repeat(48) + '┛')}
|
|
7
|
+
${chalk.hex('#00bfff')('╔' + '═'.repeat(44) + '╗')}
|
|
8
|
+
${chalk.hex('#00bfff')('║')}${' '.repeat(44)}${chalk.hex('#00bfff')('║')}
|
|
9
|
+
${chalk.hex('#00bfff')('║')}${chalk.hex('#00bfff').bold(' Baileys by Gab333WT ')} ${chalk.hex('#00bfff')('║')}
|
|
10
|
+
${chalk.hex('#00bfff')('║')}${chalk.hex('#888888')(' Telegram: @trucidarle ')} ${chalk.hex('#00bfff')('║')}
|
|
11
|
+
${chalk.hex('#00bfff')('║')}${' '.repeat(44)}${chalk.hex('#00bfff')('║')}
|
|
12
|
+
${chalk.hex('#00bfff')('╚' + '═'.repeat(44) + '╝')}
|
|
20
13
|
`;
|
|
21
|
-
|
|
22
14
|
console.log(banner);
|
|
23
15
|
}
|
|
24
16
|
|
|
@@ -64,5 +56,6 @@ __exportStar(require("./Defaults"), exports);
|
|
|
64
56
|
__exportStar(require("./WABinary"), exports);
|
|
65
57
|
__exportStar(require("./WAM"), exports);
|
|
66
58
|
__exportStar(require("./WAUSync"), exports);
|
|
59
|
+
__exportStar(require("./Utils/buttons"), exports);
|
|
67
60
|
|
|
68
61
|
exports.default = Socket_1.default;
|