@ryuu-reinzz/haruka-lib 4.0.0-beta.1 → 4.0.0-beta.3
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/main/socket.js +1274 -1272
- package/package.json +1 -1
package/main/socket.js
CHANGED
|
@@ -51,1493 +51,1497 @@ import Sticker from './sticker-engine/index.js';
|
|
|
51
51
|
const __filename = fileURLToPath(import.meta.url);
|
|
52
52
|
const __dirname = dirname(__filename);
|
|
53
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
54
|
+
/**
|
|
55
|
+
* @param {import('baileys').WASocket} socket
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
function addProperty(socket, baileys) {
|
|
59
|
+
const {
|
|
60
|
+
proto,
|
|
61
|
+
generateWAMessageFromContent,
|
|
62
|
+
jidDecode,
|
|
63
|
+
downloadContentFromMessage,
|
|
64
|
+
prepareWAMessageMedia,
|
|
65
|
+
generateMessageID,
|
|
66
|
+
generateWAMessage
|
|
67
|
+
} = baileys;
|
|
68
|
+
let sendMessage = socket.sendMessage;
|
|
69
|
+
|
|
70
|
+
function extractIE(text, {
|
|
71
|
+
extract = true,
|
|
72
|
+
hyperlink = true,
|
|
73
|
+
citation = true,
|
|
74
|
+
latex = true
|
|
75
|
+
} = {}) {
|
|
76
|
+
if (!extract) {
|
|
77
|
+
return {
|
|
78
|
+
text,
|
|
79
|
+
ie: [],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
let ie = [],
|
|
83
|
+
result = '',
|
|
84
|
+
last = 0,
|
|
85
|
+
citation_index = 1,
|
|
86
|
+
hyperlink_index = 0,
|
|
87
|
+
latex_index = 0,
|
|
88
|
+
stack = [];
|
|
89
|
+
for (let i = 0; i < text.length; i++) {
|
|
90
|
+
if (text[i] == '[' && text[i - 1] != '\\') {
|
|
91
|
+
stack.push(i);
|
|
92
|
+
} else if (text[i] == ']' && (text[i + 1] == '(' || text[i + 1] == '<')) {
|
|
93
|
+
let start = stack.pop();
|
|
94
|
+
if (start == null) continue;
|
|
95
|
+
let open = text[i + 1],
|
|
96
|
+
close = open == '(' ? ')' : '>',
|
|
97
|
+
type = open == '(' ? 'link' : 'latex',
|
|
98
|
+
end = i + 2,
|
|
99
|
+
depth = 1;
|
|
100
|
+
while (end < text.length && depth) {
|
|
101
|
+
if (text[end] == open && text[end - 1] != '\\') depth++;
|
|
102
|
+
else if (text[end] == close && text[end - 1] != '\\') depth--;
|
|
103
|
+
end++;
|
|
104
|
+
}
|
|
105
|
+
if (depth) continue;
|
|
106
|
+
let raw = text.slice(start + 1, i).trim(),
|
|
107
|
+
url = text.slice(i + 2, end - 1).trim(),
|
|
108
|
+
key,
|
|
109
|
+
tag,
|
|
110
|
+
data;
|
|
111
|
+
if (type == 'latex') {
|
|
112
|
+
if (!latex) continue;
|
|
113
|
+
let [txt = '', width = null, height = null, font_height = null, padding = null] = raw.split('|');
|
|
114
|
+
key = `\u004E\u0049\u0058\u0045\u004C_LATEX_${latex_index++}`;
|
|
115
|
+
tag = `{{${key}}}${txt || 'image'}{{/${key}}}`;
|
|
116
|
+
data = {
|
|
117
|
+
type: 'latex',
|
|
118
|
+
ie: {
|
|
119
|
+
key,
|
|
120
|
+
text: txt,
|
|
121
|
+
url,
|
|
122
|
+
width,
|
|
123
|
+
height,
|
|
124
|
+
font_height,
|
|
125
|
+
padding,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
} else if (raw) {
|
|
129
|
+
if (!hyperlink) continue;
|
|
130
|
+
key = `\u004E\u0049\u0058\u0045\u004C_HYPERLINK_${hyperlink_index++}`;
|
|
131
|
+
tag = `{{${key}}}${url}{{/${key}}}`;
|
|
132
|
+
data = {
|
|
133
|
+
type: 'hyperlink',
|
|
134
|
+
ie: {
|
|
135
|
+
key,
|
|
136
|
+
text: raw,
|
|
137
|
+
url,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
if (!citation) continue;
|
|
142
|
+
key = `\u004E\u0049\u0058\u0045\u004C_CITATION_${citation_index - 1}`;
|
|
143
|
+
tag = `{{${key}}}${url}{{/${key}}}`;
|
|
144
|
+
data = {
|
|
145
|
+
type: 'citation',
|
|
146
|
+
ie: {
|
|
147
|
+
reference_id: citation_index++,
|
|
148
|
+
key,
|
|
149
|
+
text: '',
|
|
150
|
+
url,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
result += text.slice(last, start) + tag;
|
|
155
|
+
last = end;
|
|
156
|
+
ie.push(data);
|
|
157
|
+
i = end - 1;
|
|
137
158
|
}
|
|
138
|
-
result += text.slice(last, start) + tag;
|
|
139
|
-
last = end;
|
|
140
|
-
ie.push(data);
|
|
141
|
-
i = end - 1;
|
|
142
159
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
class BaseBuilder {
|
|
152
|
-
constructor() {
|
|
153
|
-
this._title = '';
|
|
154
|
-
this._subtitle = '';
|
|
155
|
-
this._body = '';
|
|
156
|
-
this._footer = '';
|
|
157
|
-
this._contextInfo = {};
|
|
158
|
-
this._extraPayload = {};
|
|
160
|
+
result += text.slice(last);
|
|
161
|
+
return {
|
|
162
|
+
text: result,
|
|
163
|
+
ie,
|
|
164
|
+
};
|
|
159
165
|
}
|
|
160
166
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
class BaseBuilder {
|
|
168
|
+
constructor() {
|
|
169
|
+
this._title = '';
|
|
170
|
+
this._subtitle = '';
|
|
171
|
+
this._body = '';
|
|
172
|
+
this._footer = '';
|
|
173
|
+
this._contextInfo = {};
|
|
174
|
+
this._extraPayload = {};
|
|
164
175
|
}
|
|
165
|
-
this._title = title;
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
176
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
177
|
+
setTitle(title) {
|
|
178
|
+
if (typeof title !== 'string') {
|
|
179
|
+
throw new TypeError('Title must be a string');
|
|
180
|
+
}
|
|
181
|
+
this._title = title;
|
|
182
|
+
return this;
|
|
172
183
|
}
|
|
173
|
-
this._subtitle = subtitle;
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
184
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
185
|
+
setSubtitle(subtitle) {
|
|
186
|
+
if (typeof subtitle !== 'string') {
|
|
187
|
+
throw new TypeError('Subtitle must be a string');
|
|
188
|
+
}
|
|
189
|
+
this._subtitle = subtitle;
|
|
190
|
+
return this;
|
|
180
191
|
}
|
|
181
|
-
this._body = body;
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
192
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
setBody(body) {
|
|
194
|
+
if (typeof body !== 'string') {
|
|
195
|
+
throw new TypeError('Body must be a string');
|
|
196
|
+
}
|
|
197
|
+
this._body = body;
|
|
198
|
+
return this;
|
|
188
199
|
}
|
|
189
|
-
this._footer = footer;
|
|
190
|
-
return this;
|
|
191
|
-
}
|
|
192
200
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
setFooter(footer) {
|
|
202
|
+
if (typeof footer !== 'string') {
|
|
203
|
+
throw new TypeError('Footer must be a string');
|
|
204
|
+
}
|
|
205
|
+
this._footer = footer;
|
|
206
|
+
return this;
|
|
196
207
|
}
|
|
197
208
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
209
|
+
setContextInfo(obj) {
|
|
210
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
211
|
+
throw new TypeError('ContextInfo must be a plain object');
|
|
212
|
+
}
|
|
201
213
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
throw new TypeError('Payload must be a plain object');
|
|
214
|
+
this._contextInfo = obj;
|
|
215
|
+
return this;
|
|
205
216
|
}
|
|
206
217
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
218
|
+
addPayload(obj) {
|
|
219
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
220
|
+
throw new TypeError('Payload must be a plain object');
|
|
221
|
+
}
|
|
211
222
|
|
|
212
|
-
|
|
213
|
-
return await sharp(buffer)
|
|
214
|
-
.resize(x, y, {
|
|
215
|
-
fit,
|
|
216
|
-
position: 'center',
|
|
217
|
-
background: {
|
|
218
|
-
r: 0,
|
|
219
|
-
g: 0,
|
|
220
|
-
b: 0,
|
|
221
|
-
alpha: 0
|
|
222
|
-
},
|
|
223
|
-
})
|
|
224
|
-
.png()
|
|
225
|
-
.toBuffer();
|
|
226
|
-
}
|
|
223
|
+
Object.assign(this._extraPayload, obj);
|
|
227
224
|
|
|
228
|
-
|
|
229
|
-
try {
|
|
230
|
-
let response = await fetch(url, options);
|
|
231
|
-
if (!response.ok) throw Error(`HTTP ${response.status}`);
|
|
232
|
-
return Buffer.from(await response.arrayBuffer());
|
|
233
|
-
} catch (error) {
|
|
234
|
-
if (config.silent) return Buffer.alloc(0);
|
|
235
|
-
throw error;
|
|
225
|
+
return this;
|
|
236
226
|
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
class Button extends BaseBuilder {
|
|
241
|
-
#client;
|
|
242
227
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
228
|
+
static async resize(buffer, x, y, fit = 'cover') {
|
|
229
|
+
return await sharp(buffer)
|
|
230
|
+
.resize(x, y, {
|
|
231
|
+
fit,
|
|
232
|
+
position: 'center',
|
|
233
|
+
background: {
|
|
234
|
+
r: 0,
|
|
235
|
+
g: 0,
|
|
236
|
+
b: 0,
|
|
237
|
+
alpha: 0
|
|
238
|
+
},
|
|
239
|
+
})
|
|
240
|
+
.png()
|
|
241
|
+
.toBuffer();
|
|
247
242
|
}
|
|
248
|
-
this.#client = client;
|
|
249
243
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
244
|
+
static async fetchBuffer(url, options = {}, config = {}) {
|
|
245
|
+
try {
|
|
246
|
+
let response = await fetch(url, options);
|
|
247
|
+
if (!response.ok) throw Error(`HTTP ${response.status}`);
|
|
248
|
+
return Buffer.from(await response.arrayBuffer());
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (config.silent) return Buffer.alloc(0);
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
Buffer.isBuffer(path) ? (this._data = {
|
|
260
|
-
video: path,
|
|
261
|
-
...options
|
|
262
|
-
}) : (this._data = {
|
|
263
|
-
video: {
|
|
264
|
-
url: path
|
|
265
|
-
},
|
|
266
|
-
...options
|
|
267
|
-
});
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
256
|
+
class Button extends BaseBuilder {
|
|
257
|
+
#client;
|
|
270
258
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
image: {
|
|
278
|
-
url: path
|
|
279
|
-
},
|
|
280
|
-
...options
|
|
281
|
-
});
|
|
282
|
-
return this;
|
|
283
|
-
}
|
|
259
|
+
constructor(client) {
|
|
260
|
+
super();
|
|
261
|
+
if (!client) {
|
|
262
|
+
throw new Error('Socket is required');
|
|
263
|
+
}
|
|
264
|
+
this.#client = client;
|
|
284
265
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
document: {
|
|
292
|
-
url: path
|
|
293
|
-
},
|
|
294
|
-
...options
|
|
295
|
-
});
|
|
296
|
-
return this;
|
|
297
|
-
}
|
|
266
|
+
this._buttons = [];
|
|
267
|
+
this._data;
|
|
268
|
+
this._currentSelectionIndex = -1;
|
|
269
|
+
this._currentSectionIndex = -1;
|
|
270
|
+
this._params = {};
|
|
271
|
+
}
|
|
298
272
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
273
|
+
setVideo(path, options = {}) {
|
|
274
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
275
|
+
Buffer.isBuffer(path) ? (this._data = {
|
|
276
|
+
video: path,
|
|
277
|
+
...options
|
|
278
|
+
}) : (this._data = {
|
|
279
|
+
video: {
|
|
280
|
+
url: path
|
|
281
|
+
},
|
|
282
|
+
...options
|
|
283
|
+
});
|
|
284
|
+
return this;
|
|
302
285
|
}
|
|
303
286
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
287
|
+
setImage(path, options = {}) {
|
|
288
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
289
|
+
Buffer.isBuffer(path) ? (this._data = {
|
|
290
|
+
image: path,
|
|
291
|
+
...options
|
|
292
|
+
}) : (this._data = {
|
|
293
|
+
image: {
|
|
294
|
+
url: path
|
|
295
|
+
},
|
|
296
|
+
...options
|
|
297
|
+
});
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
307
300
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
301
|
+
setDocument(path, options = {}) {
|
|
302
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
303
|
+
Buffer.isBuffer(path) ? (this._data = {
|
|
304
|
+
document: path,
|
|
305
|
+
...options
|
|
306
|
+
}) : (this._data = {
|
|
307
|
+
document: {
|
|
308
|
+
url: path
|
|
309
|
+
},
|
|
310
|
+
...options
|
|
311
|
+
});
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
312
314
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
setMedia(obj) {
|
|
316
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
317
|
+
throw new TypeError('Media must be a plain object');
|
|
318
|
+
}
|
|
317
319
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
buttonParamsJson: typeof params === 'string' ? params : JSON.stringify(params),
|
|
322
|
-
});
|
|
320
|
+
this._data = obj;
|
|
321
|
+
return this;
|
|
322
|
+
}
|
|
323
323
|
|
|
324
|
-
|
|
325
|
-
|
|
324
|
+
clearButtons() {
|
|
325
|
+
this._buttons = [];
|
|
326
|
+
return this;
|
|
327
|
+
}
|
|
326
328
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
329
|
+
setParams(obj) {
|
|
330
|
+
this._params = obj;
|
|
331
|
+
return this;
|
|
330
332
|
}
|
|
331
|
-
const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
|
|
332
|
-
buttonParams.sections[this._currentSectionIndex].rows.push({
|
|
333
|
-
header,
|
|
334
|
-
title,
|
|
335
|
-
description,
|
|
336
|
-
id
|
|
337
|
-
});
|
|
338
|
-
this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
|
|
339
|
-
return this;
|
|
340
|
-
}
|
|
341
333
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
334
|
+
addButton(name, params) {
|
|
335
|
+
this._buttons.push({
|
|
336
|
+
name,
|
|
337
|
+
buttonParamsJson: typeof params === 'string' ? params : JSON.stringify(params),
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
return this;
|
|
345
341
|
}
|
|
346
|
-
const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
|
|
347
|
-
buttonParams.sections.push({
|
|
348
|
-
title,
|
|
349
|
-
highlight_label,
|
|
350
|
-
rows: []
|
|
351
|
-
});
|
|
352
|
-
this._currentSectionIndex = buttonParams.sections.length - 1;
|
|
353
|
-
this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
|
|
354
|
-
return this;
|
|
355
|
-
}
|
|
356
342
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
343
|
+
makeRow(header = '', title = '', description = '', id = '') {
|
|
344
|
+
if (this._currentSelectionIndex === -1 || this._currentSectionIndex === -1) {
|
|
345
|
+
throw new Error('You need to create a selection and a section first');
|
|
346
|
+
}
|
|
347
|
+
const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
|
|
348
|
+
buttonParams.sections[this._currentSectionIndex].rows.push({
|
|
349
|
+
header,
|
|
362
350
|
title,
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
351
|
+
description,
|
|
352
|
+
id
|
|
353
|
+
});
|
|
354
|
+
this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
370
357
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
358
|
+
makeSection(title = '', highlight_label = '') {
|
|
359
|
+
if (this._currentSelectionIndex === -1) {
|
|
360
|
+
throw new Error('You need to create a selection first');
|
|
361
|
+
}
|
|
362
|
+
const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
|
|
363
|
+
buttonParams.sections.push({
|
|
364
|
+
title,
|
|
365
|
+
highlight_label,
|
|
366
|
+
rows: []
|
|
367
|
+
});
|
|
368
|
+
this._currentSectionIndex = buttonParams.sections.length - 1;
|
|
369
|
+
this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
|
|
370
|
+
return this;
|
|
371
|
+
}
|
|
382
372
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
name: 'cta_call',
|
|
386
|
-
buttonParamsJson: JSON.stringify({
|
|
387
|
-
display_text,
|
|
388
|
-
id,
|
|
373
|
+
addSelection(title, options = {}) {
|
|
374
|
+
this._buttons.push({
|
|
389
375
|
...options,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
376
|
+
name: 'single_select',
|
|
377
|
+
buttonParamsJson: JSON.stringify({
|
|
378
|
+
title,
|
|
379
|
+
sections: []
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
this._currentSelectionIndex = this._buttons.length - 1;
|
|
383
|
+
this._currentSectionIndex = -1;
|
|
384
|
+
return this;
|
|
385
|
+
}
|
|
394
386
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
387
|
+
addReply(display_text = '', id = '', options = {}) {
|
|
388
|
+
this._buttons.push({
|
|
389
|
+
name: 'quick_reply',
|
|
390
|
+
buttonParamsJson: JSON.stringify({
|
|
391
|
+
display_text,
|
|
392
|
+
id,
|
|
393
|
+
...options,
|
|
394
|
+
}),
|
|
395
|
+
});
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
406
398
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
399
|
+
addCall(display_text = '', id = '', options = {}) {
|
|
400
|
+
this._buttons.push({
|
|
401
|
+
name: 'cta_call',
|
|
402
|
+
buttonParamsJson: JSON.stringify({
|
|
403
|
+
display_text,
|
|
404
|
+
id,
|
|
405
|
+
...options,
|
|
406
|
+
}),
|
|
407
|
+
});
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
418
410
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
411
|
+
addReminder(display_text = '', id = '', options = {}) {
|
|
412
|
+
this._buttons.push({
|
|
413
|
+
name: 'cta_reminder',
|
|
414
|
+
buttonParamsJson: JSON.stringify({
|
|
415
|
+
display_text,
|
|
416
|
+
id,
|
|
417
|
+
...options,
|
|
418
|
+
}),
|
|
419
|
+
});
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
430
422
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
423
|
+
addCancelReminder(display_text = '', id = '', options = {}) {
|
|
424
|
+
this._buttons.push({
|
|
425
|
+
name: 'cta_cancel_reminder',
|
|
426
|
+
buttonParamsJson: JSON.stringify({
|
|
427
|
+
display_text,
|
|
428
|
+
id,
|
|
429
|
+
...options,
|
|
430
|
+
}),
|
|
431
|
+
});
|
|
432
|
+
return this;
|
|
433
|
+
}
|
|
438
434
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
435
|
+
addAddress(display_text = '', id = '', options = {}) {
|
|
436
|
+
this._buttons.push({
|
|
437
|
+
name: 'address_message',
|
|
438
|
+
buttonParamsJson: JSON.stringify({
|
|
439
|
+
display_text,
|
|
440
|
+
id,
|
|
441
|
+
...options,
|
|
442
|
+
}),
|
|
443
|
+
});
|
|
444
|
+
return this;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
addLocation(options = {}) {
|
|
448
|
+
this._buttons.push({
|
|
449
|
+
name: 'send_location',
|
|
450
|
+
buttonParamsJson: JSON.stringify(options),
|
|
451
|
+
});
|
|
452
|
+
return this;
|
|
453
|
+
}
|
|
452
454
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
name: 'cta_copy',
|
|
456
|
-
buttonParamsJson: JSON.stringify({
|
|
457
|
-
display_text,
|
|
458
|
-
copy_code,
|
|
455
|
+
addUrl(display_text = '', url = '', webview_interaction = false, options = {}) {
|
|
456
|
+
this._buttons.push({
|
|
459
457
|
...options,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
458
|
+
name: 'cta_url',
|
|
459
|
+
buttonParamsJson: JSON.stringify({
|
|
460
|
+
display_text,
|
|
461
|
+
url,
|
|
462
|
+
webview_interaction,
|
|
463
|
+
...options,
|
|
464
|
+
}),
|
|
465
|
+
});
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
464
468
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
button_title: 'string',
|
|
477
|
-
},
|
|
478
|
-
tap_target_configuration: {
|
|
479
|
-
title: 'string',
|
|
480
|
-
description: 'string',
|
|
481
|
-
canonical_url: 'string',
|
|
482
|
-
domain: 'string',
|
|
483
|
-
buttonIndex: 'number',
|
|
484
|
-
},
|
|
485
|
-
};
|
|
469
|
+
addCopy(display_text = '', copy_code = '', options = {}) {
|
|
470
|
+
this._buttons.push({
|
|
471
|
+
name: 'cta_copy',
|
|
472
|
+
buttonParamsJson: JSON.stringify({
|
|
473
|
+
display_text,
|
|
474
|
+
copy_code,
|
|
475
|
+
...options,
|
|
476
|
+
}),
|
|
477
|
+
});
|
|
478
|
+
return this;
|
|
479
|
+
}
|
|
486
480
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
text: this._footer,
|
|
481
|
+
static paramsList = {
|
|
482
|
+
limited_time_offer: {
|
|
483
|
+
text: 'string',
|
|
484
|
+
url: 'string',
|
|
485
|
+
copy_code: 'string',
|
|
486
|
+
expiration_time: 'number',
|
|
494
487
|
},
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
await prepareWAMessageMedia(this._data, {
|
|
501
|
-
upload: this.#client.waUploadToServer
|
|
502
|
-
}).catch((e) => {
|
|
503
|
-
if (String(e).includes('Invalid media type')) return this._data;
|
|
504
|
-
throw e;
|
|
505
|
-
}) : {}),
|
|
488
|
+
bottom_sheet: {
|
|
489
|
+
in_thread_buttons_limit: 'number',
|
|
490
|
+
divider_indices: ['number'],
|
|
491
|
+
list_title: 'string',
|
|
492
|
+
button_title: 'string',
|
|
506
493
|
},
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
494
|
+
tap_target_configuration: {
|
|
495
|
+
title: 'string',
|
|
496
|
+
description: 'string',
|
|
497
|
+
canonical_url: 'string',
|
|
498
|
+
domain: 'string',
|
|
499
|
+
buttonIndex: 'number',
|
|
510
500
|
},
|
|
511
501
|
};
|
|
512
|
-
}
|
|
513
502
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return generateWAMessageFromContent(
|
|
520
|
-
jid, {
|
|
521
|
-
...this._extraPayload,
|
|
522
|
-
interactiveMessage: {
|
|
523
|
-
...message,
|
|
524
|
-
contextInfo: this._contextInfo,
|
|
503
|
+
async toCard() {
|
|
504
|
+
return {
|
|
505
|
+
body: {
|
|
506
|
+
text: this._body,
|
|
525
507
|
},
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
508
|
+
footer: {
|
|
509
|
+
text: this._footer,
|
|
510
|
+
},
|
|
511
|
+
header: {
|
|
512
|
+
title: this._title,
|
|
513
|
+
subtitle: this._subtitle,
|
|
514
|
+
hasMediaAttachment: !!this._data,
|
|
515
|
+
...(this._data ?
|
|
516
|
+
await prepareWAMessageMedia(this._data, {
|
|
517
|
+
upload: this.#client.waUploadToServer
|
|
518
|
+
}).catch((e) => {
|
|
519
|
+
if (String(e).includes('Invalid media type')) return this._data;
|
|
520
|
+
throw e;
|
|
521
|
+
}) : {}),
|
|
522
|
+
},
|
|
523
|
+
nativeFlowMessage: {
|
|
524
|
+
messageParamsJson: JSON.stringify(this._params),
|
|
525
|
+
buttons: this._buttons,
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
}
|
|
531
529
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
530
|
+
async build(jid, {
|
|
531
|
+
...options
|
|
532
|
+
} = {}) {
|
|
533
|
+
const message = await this.toCard();
|
|
536
534
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
tag: 'interactive',
|
|
544
|
-
attrs: {
|
|
545
|
-
type: 'native_flow',
|
|
546
|
-
v: '1'
|
|
535
|
+
return generateWAMessageFromContent(
|
|
536
|
+
jid, {
|
|
537
|
+
...this._extraPayload,
|
|
538
|
+
interactiveMessage: {
|
|
539
|
+
...message,
|
|
540
|
+
contextInfo: this._contextInfo,
|
|
547
541
|
},
|
|
542
|
+
}, {
|
|
543
|
+
...options
|
|
544
|
+
}
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
async send(jid, {
|
|
549
|
+
...options
|
|
550
|
+
} = {}) {
|
|
551
|
+
const msg = await this.build(jid, options);
|
|
552
|
+
|
|
553
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
554
|
+
messageId: msg.key.id,
|
|
555
|
+
additionalNodes: [{
|
|
556
|
+
tag: 'biz',
|
|
557
|
+
attrs: {},
|
|
548
558
|
content: [{
|
|
549
|
-
tag: '
|
|
559
|
+
tag: 'interactive',
|
|
550
560
|
attrs: {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
|
|
561
|
+
type: 'native_flow',
|
|
562
|
+
v: '1'
|
|
563
|
+
},
|
|
564
|
+
content: [{
|
|
565
|
+
tag: 'native_flow',
|
|
566
|
+
attrs: {
|
|
567
|
+
v: '9',
|
|
568
|
+
name: 'mixed'
|
|
569
|
+
}
|
|
570
|
+
}],
|
|
571
|
+
}, ],
|
|
555
572
|
}, ],
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
return msg;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
class ButtonV2 extends BaseBuilder {
|
|
564
|
-
#client;
|
|
565
|
-
|
|
566
|
-
constructor(client) {
|
|
567
|
-
super();
|
|
568
|
-
if (!client) {
|
|
569
|
-
throw new Error('Socket is required');
|
|
573
|
+
...options,
|
|
574
|
+
});
|
|
575
|
+
return msg;
|
|
570
576
|
}
|
|
571
|
-
|
|
572
|
-
this.#client = client;
|
|
573
|
-
this._image;
|
|
574
|
-
this._data;
|
|
575
|
-
this._buttons = [];
|
|
576
577
|
}
|
|
577
578
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
return this;
|
|
587
|
-
}
|
|
579
|
+
class ButtonV2 extends BaseBuilder {
|
|
580
|
+
#client;
|
|
581
|
+
|
|
582
|
+
constructor(client) {
|
|
583
|
+
super();
|
|
584
|
+
if (!client) {
|
|
585
|
+
throw new Error('Socket is required');
|
|
586
|
+
}
|
|
588
587
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
588
|
+
this.#client = client;
|
|
589
|
+
this._image;
|
|
590
|
+
this._data;
|
|
591
|
+
this._buttons = [];
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
594
|
+
addButton(displayText = '', buttonId = crypto.randomUUID()) {
|
|
595
|
+
this._buttons.push({
|
|
596
|
+
buttonId,
|
|
597
|
+
buttonText: {
|
|
598
|
+
displayText
|
|
599
|
+
},
|
|
600
|
+
type: 1,
|
|
601
|
+
});
|
|
602
|
+
return this;
|
|
603
|
+
}
|
|
597
604
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
605
|
+
addRawButton(obj) {
|
|
606
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
607
|
+
throw new TypeError('Buttons must be a plain object');
|
|
608
|
+
}
|
|
603
609
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
throw new TypeError('Media must be a plain object');
|
|
610
|
+
this._buttons.push(obj);
|
|
611
|
+
return this;
|
|
607
612
|
}
|
|
608
613
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
614
|
+
setThumbnail(path) {
|
|
615
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
616
|
+
this._image = path;
|
|
617
|
+
return this;
|
|
618
|
+
}
|
|
612
619
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
let _thumbnail = this._image ? await BaseBuilder.resize(Buffer.isBuffer(this._image) ? this._image : await BaseBuilder.fetchBuffer(this._image, {}, {
|
|
617
|
-
silent: true
|
|
618
|
-
}), 300, 300) : null;
|
|
619
|
-
const msg = generateWAMessageFromContent(
|
|
620
|
-
jid, {
|
|
621
|
-
...this._extraPayload,
|
|
622
|
-
buttonsMessage: {
|
|
623
|
-
contentText: this._body,
|
|
624
|
-
footerText: this._footer,
|
|
625
|
-
...(this._data ?
|
|
626
|
-
this._data : {
|
|
627
|
-
headerType: 6,
|
|
628
|
-
locationMessage: {
|
|
629
|
-
degreesLatitude: 0,
|
|
630
|
-
degreesLongitude: 0,
|
|
631
|
-
name: this._title,
|
|
632
|
-
address: this._subtitle,
|
|
633
|
-
jpegThumbnail: _thumbnail,
|
|
634
|
-
},
|
|
635
|
-
}),
|
|
636
|
-
viewOnce: true,
|
|
637
|
-
contextInfo: this._contextInfo,
|
|
638
|
-
buttons: [...this._buttons],
|
|
639
|
-
},
|
|
640
|
-
}, {
|
|
641
|
-
...options
|
|
620
|
+
setMedia(obj) {
|
|
621
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
622
|
+
throw new TypeError('Media must be a plain object');
|
|
642
623
|
}
|
|
643
|
-
);
|
|
644
|
-
return msg;
|
|
645
|
-
}
|
|
646
624
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
if (this._buttons.length < 1) throw new Error('ButtonV2 requires at least one button');
|
|
651
|
-
const msg = await this.build(jid, options);
|
|
625
|
+
this._data = obj;
|
|
626
|
+
return this;
|
|
627
|
+
}
|
|
652
628
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
629
|
+
async build(jid, {
|
|
630
|
+
...options
|
|
631
|
+
} = {}) {
|
|
632
|
+
let _thumbnail = this._image ? await BaseBuilder.resize(Buffer.isBuffer(this._image) ? this._image : await BaseBuilder.fetchBuffer(this._image, {}, {
|
|
633
|
+
silent: true
|
|
634
|
+
}), 300, 300) : null;
|
|
635
|
+
const msg = generateWAMessageFromContent(
|
|
636
|
+
jid, {
|
|
637
|
+
...this._extraPayload,
|
|
638
|
+
buttonsMessage: {
|
|
639
|
+
contentText: this._body,
|
|
640
|
+
footerText: this._footer,
|
|
641
|
+
...(this._data ?
|
|
642
|
+
this._data : {
|
|
643
|
+
headerType: 6,
|
|
644
|
+
locationMessage: {
|
|
645
|
+
degreesLatitude: 0,
|
|
646
|
+
degreesLongitude: 0,
|
|
647
|
+
name: this._title,
|
|
648
|
+
address: this._subtitle,
|
|
649
|
+
jpegThumbnail: _thumbnail,
|
|
650
|
+
},
|
|
651
|
+
}),
|
|
652
|
+
viewOnce: true,
|
|
653
|
+
contextInfo: this._contextInfo,
|
|
654
|
+
buttons: [...this._buttons],
|
|
663
655
|
},
|
|
656
|
+
}, {
|
|
657
|
+
...options
|
|
658
|
+
}
|
|
659
|
+
);
|
|
660
|
+
return msg;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
async send(jid, {
|
|
664
|
+
...options
|
|
665
|
+
} = {}) {
|
|
666
|
+
if (this._buttons.length < 1) throw new Error('ButtonV2 requires at least one button');
|
|
667
|
+
const msg = await this.build(jid, options);
|
|
668
|
+
|
|
669
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
670
|
+
messageId: msg.key.id,
|
|
671
|
+
additionalNodes: [{
|
|
672
|
+
tag: 'biz',
|
|
673
|
+
attrs: {},
|
|
664
674
|
content: [{
|
|
665
|
-
tag: '
|
|
675
|
+
tag: 'interactive',
|
|
666
676
|
attrs: {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
}
|
|
670
|
-
|
|
677
|
+
type: 'native_flow',
|
|
678
|
+
v: '1'
|
|
679
|
+
},
|
|
680
|
+
content: [{
|
|
681
|
+
tag: 'native_flow',
|
|
682
|
+
attrs: {
|
|
683
|
+
v: '9',
|
|
684
|
+
name: 'mixed'
|
|
685
|
+
}
|
|
686
|
+
}],
|
|
687
|
+
}, ],
|
|
671
688
|
}, ],
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
return msg;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
class Carousel extends BaseBuilder {
|
|
680
|
-
#client;
|
|
681
|
-
|
|
682
|
-
constructor(client) {
|
|
683
|
-
super();
|
|
684
|
-
if (!client) {
|
|
685
|
-
throw new Error('Socket is required');
|
|
689
|
+
...options,
|
|
690
|
+
});
|
|
691
|
+
return msg;
|
|
686
692
|
}
|
|
687
|
-
|
|
688
|
-
this.#client = client;
|
|
689
|
-
this._cards = [];
|
|
690
693
|
}
|
|
691
694
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
const baseIndex = this._cards.length;
|
|
695
|
+
class Carousel extends BaseBuilder {
|
|
696
|
+
#client;
|
|
695
697
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
698
|
+
constructor(client) {
|
|
699
|
+
super();
|
|
700
|
+
if (!client) {
|
|
701
|
+
throw new Error('Socket is required');
|
|
699
702
|
}
|
|
703
|
+
|
|
704
|
+
this.#client = client;
|
|
705
|
+
this._cards = [];
|
|
700
706
|
}
|
|
701
707
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
708
|
+
addCard(card) {
|
|
709
|
+
const cards = Array.isArray(card) ? card : [card];
|
|
710
|
+
const baseIndex = this._cards.length;
|
|
705
711
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
jid, {
|
|
711
|
-
...this._extraPayload,
|
|
712
|
-
interactiveMessage: {
|
|
713
|
-
header: {
|
|
714
|
-
hasMediaAttachment: false,
|
|
715
|
-
},
|
|
716
|
-
body: {
|
|
717
|
-
text: this._body
|
|
718
|
-
},
|
|
719
|
-
footer: {
|
|
720
|
-
text: this._footer
|
|
721
|
-
},
|
|
722
|
-
contextInfo: this._contextInfo,
|
|
723
|
-
carouselMessage: {
|
|
724
|
-
cards: this._cards,
|
|
725
|
-
},
|
|
726
|
-
},
|
|
727
|
-
}, {
|
|
728
|
-
...options
|
|
712
|
+
for (const [index, c] of cards.entries()) {
|
|
713
|
+
if (!c?.header?.hasMediaAttachment) {
|
|
714
|
+
throw new Error(`Card [${baseIndex + index}] must include an image or video in header`);
|
|
715
|
+
}
|
|
729
716
|
}
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
717
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const msg = this.build(jid, options);
|
|
718
|
+
this._cards.push(...cards);
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
737
721
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
722
|
+
build(jid, {
|
|
723
|
+
...options
|
|
724
|
+
} = {}) {
|
|
725
|
+
return generateWAMessageFromContent(
|
|
726
|
+
jid, {
|
|
727
|
+
...this._extraPayload,
|
|
728
|
+
interactiveMessage: {
|
|
729
|
+
header: {
|
|
730
|
+
hasMediaAttachment: false,
|
|
731
|
+
},
|
|
732
|
+
body: {
|
|
733
|
+
text: this._body
|
|
734
|
+
},
|
|
735
|
+
footer: {
|
|
736
|
+
text: this._footer
|
|
737
|
+
},
|
|
738
|
+
contextInfo: this._contextInfo,
|
|
739
|
+
carouselMessage: {
|
|
740
|
+
cards: this._cards,
|
|
741
|
+
},
|
|
748
742
|
},
|
|
743
|
+
}, {
|
|
744
|
+
...options
|
|
745
|
+
}
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
async send(jid, {
|
|
750
|
+
...options
|
|
751
|
+
} = {}) {
|
|
752
|
+
const msg = this.build(jid, options);
|
|
753
|
+
|
|
754
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
755
|
+
messageId: msg.key.id,
|
|
756
|
+
additionalNodes: [{
|
|
757
|
+
tag: 'biz',
|
|
758
|
+
attrs: {},
|
|
749
759
|
content: [{
|
|
750
|
-
tag: '
|
|
760
|
+
tag: 'interactive',
|
|
751
761
|
attrs: {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
}
|
|
755
|
-
|
|
762
|
+
type: 'native_flow',
|
|
763
|
+
v: '1'
|
|
764
|
+
},
|
|
765
|
+
content: [{
|
|
766
|
+
tag: 'native_flow',
|
|
767
|
+
attrs: {
|
|
768
|
+
v: '9',
|
|
769
|
+
name: 'mixed'
|
|
770
|
+
}
|
|
771
|
+
}],
|
|
772
|
+
}, ],
|
|
756
773
|
}, ],
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
774
|
+
...options,
|
|
775
|
+
});
|
|
776
|
+
return msg;
|
|
777
|
+
}
|
|
761
778
|
}
|
|
762
|
-
}
|
|
763
779
|
|
|
764
|
-
class AIRich extends BaseBuilder {
|
|
765
|
-
|
|
780
|
+
class AIRich extends BaseBuilder {
|
|
781
|
+
#client;
|
|
766
782
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
783
|
+
constructor(client) {
|
|
784
|
+
if (!client) {
|
|
785
|
+
throw new Error('Socket is required');
|
|
786
|
+
}
|
|
771
787
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
788
|
+
super();
|
|
789
|
+
this.#client = client;
|
|
790
|
+
this._contextInfo = {};
|
|
791
|
+
this._submessages = [];
|
|
792
|
+
this._sections = [];
|
|
793
|
+
this._richResponseSources = [];
|
|
794
|
+
}
|
|
779
795
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
796
|
+
static newLayout(name, data) {
|
|
797
|
+
return {
|
|
798
|
+
view_model: {
|
|
799
|
+
[Array.isArray(data) ? 'primitives' : 'primitive']: data,
|
|
800
|
+
__typename: `GenAI${name}LayoutViewModel`,
|
|
801
|
+
},
|
|
802
|
+
};
|
|
803
|
+
}
|
|
788
804
|
|
|
789
|
-
|
|
790
|
-
|
|
805
|
+
addSubmessage(submessage) {
|
|
806
|
+
const items = Array.isArray(submessage) ? submessage : [submessage];
|
|
807
|
+
|
|
808
|
+
for (const item of items) {
|
|
809
|
+
if (typeof item !== 'object' || item === null || Array.isArray(item)) {
|
|
810
|
+
throw new TypeError('Submessage must be a plain object or array of plain objects');
|
|
811
|
+
}
|
|
791
812
|
|
|
792
|
-
|
|
793
|
-
if (typeof item !== 'object' || item === null || Array.isArray(item)) {
|
|
794
|
-
throw new TypeError('Submessage must be a plain object or array of plain objects');
|
|
813
|
+
this._submessages.push(item);
|
|
795
814
|
}
|
|
796
815
|
|
|
797
|
-
this
|
|
816
|
+
return this;
|
|
798
817
|
}
|
|
799
818
|
|
|
800
|
-
|
|
801
|
-
|
|
819
|
+
addSection(section) {
|
|
820
|
+
const items = Array.isArray(section) ? section : [section];
|
|
802
821
|
|
|
803
|
-
|
|
804
|
-
|
|
822
|
+
for (const item of items) {
|
|
823
|
+
if (typeof item !== 'object' || item === null || Array.isArray(item)) {
|
|
824
|
+
throw new TypeError('Section must be a plain object or array of plain objects');
|
|
825
|
+
}
|
|
805
826
|
|
|
806
|
-
|
|
807
|
-
if (typeof item !== 'object' || item === null || Array.isArray(item)) {
|
|
808
|
-
throw new TypeError('Section must be a plain object or array of plain objects');
|
|
827
|
+
this._sections.push(item);
|
|
809
828
|
}
|
|
810
829
|
|
|
811
|
-
this
|
|
830
|
+
return this;
|
|
812
831
|
}
|
|
813
832
|
|
|
814
|
-
|
|
815
|
-
|
|
833
|
+
addText(text, {
|
|
834
|
+
hyperlink = true,
|
|
835
|
+
citation = true,
|
|
836
|
+
latex = true
|
|
837
|
+
} = {}) {
|
|
838
|
+
if (typeof text != 'string') {
|
|
839
|
+
throw new TypeError('Text must be a string');
|
|
840
|
+
}
|
|
816
841
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
842
|
+
const extractedIE = extractIE(text, {
|
|
843
|
+
hyperlink,
|
|
844
|
+
citation,
|
|
845
|
+
latex,
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
const inline_entities = extractedIE.ie.map(({
|
|
849
|
+
type,
|
|
850
|
+
ie
|
|
851
|
+
}) => {
|
|
852
|
+
if (type == 'hyperlink') {
|
|
853
|
+
return {
|
|
854
|
+
key: ie.key,
|
|
855
|
+
metadata: {
|
|
856
|
+
display_name: ie.text,
|
|
857
|
+
is_trusted: true,
|
|
858
|
+
url: ie.url,
|
|
859
|
+
__typename: 'GenAIInlineLinkItem',
|
|
860
|
+
},
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
if (type == 'citation') {
|
|
864
|
+
return {
|
|
865
|
+
key: ie.key,
|
|
866
|
+
metadata: {
|
|
867
|
+
reference_id: ie.reference_id,
|
|
868
|
+
reference_url: ie.url,
|
|
869
|
+
reference_title: ie.url,
|
|
870
|
+
reference_display_name: ie.url,
|
|
871
|
+
sources: [],
|
|
872
|
+
__typename: 'GenAISearchCitationItem',
|
|
873
|
+
},
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
if (type == 'latex') {
|
|
877
|
+
return {
|
|
878
|
+
key: ie.key,
|
|
879
|
+
metadata: {
|
|
880
|
+
latex_expression: ie.text,
|
|
881
|
+
latex_image: {
|
|
882
|
+
url: ie.url,
|
|
883
|
+
width: Number(ie.width) || 100,
|
|
884
|
+
height: Number(ie.height) || 100,
|
|
885
|
+
},
|
|
886
|
+
font_height: Number(ie.font_height) || 83.333333333333,
|
|
887
|
+
padding: Number(ie.padding) || 15,
|
|
888
|
+
__typename: 'GenAILatexItem',
|
|
889
|
+
},
|
|
890
|
+
};
|
|
891
|
+
}
|
|
825
892
|
|
|
826
|
-
const extractedIE = extractIE(text, {
|
|
827
|
-
hyperlink,
|
|
828
|
-
citation,
|
|
829
|
-
latex,
|
|
830
|
-
});
|
|
831
|
-
|
|
832
|
-
const inline_entities = extractedIE.ie.map(({
|
|
833
|
-
type,
|
|
834
|
-
ie
|
|
835
|
-
}) => {
|
|
836
|
-
if (type == 'hyperlink') {
|
|
837
|
-
return {
|
|
838
|
-
key: ie.key,
|
|
839
|
-
metadata: {
|
|
840
|
-
display_name: ie.text,
|
|
841
|
-
is_trusted: true,
|
|
842
|
-
url: ie.url,
|
|
843
|
-
__typename: 'GenAIInlineLinkItem',
|
|
844
|
-
},
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
if (type == 'citation') {
|
|
848
|
-
return {
|
|
849
|
-
key: ie.key,
|
|
850
|
-
metadata: {
|
|
851
|
-
reference_id: ie.reference_id,
|
|
852
|
-
reference_url: ie.url,
|
|
853
|
-
reference_title: ie.url,
|
|
854
|
-
reference_display_name: ie.url,
|
|
855
|
-
sources: [],
|
|
856
|
-
__typename: 'GenAISearchCitationItem',
|
|
857
|
-
},
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
if (type == 'latex') {
|
|
861
893
|
return {
|
|
862
894
|
key: ie.key,
|
|
863
895
|
metadata: {
|
|
864
896
|
latex_expression: ie.text,
|
|
865
897
|
latex_image: {
|
|
866
898
|
url: ie.url,
|
|
867
|
-
width
|
|
868
|
-
height
|
|
899
|
+
width,
|
|
900
|
+
height,
|
|
869
901
|
},
|
|
870
902
|
font_height: Number(ie.font_height) || 83.333333333333,
|
|
871
903
|
padding: Number(ie.padding) || 15,
|
|
872
904
|
__typename: 'GenAILatexItem',
|
|
873
905
|
},
|
|
874
906
|
};
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
this._submessages.push({
|
|
910
|
+
messageType: 2,
|
|
911
|
+
messageText: extractedIE.text,
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
this._sections.push(
|
|
915
|
+
AIRich.newLayout('Single', {
|
|
916
|
+
text: extractedIE.text,
|
|
917
|
+
...(inline_entities.length && {
|
|
918
|
+
inline_entities,
|
|
919
|
+
}),
|
|
920
|
+
__typename: 'GenAIMarkdownTextUXPrimitive',
|
|
921
|
+
})
|
|
922
|
+
);
|
|
923
|
+
|
|
924
|
+
return this;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
addCode(language, code) {
|
|
928
|
+
if (typeof language !== 'string' || typeof code !== 'string') {
|
|
929
|
+
throw new TypeError('Language and code must be a string');
|
|
875
930
|
}
|
|
876
931
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
height,
|
|
885
|
-
},
|
|
886
|
-
font_height: Number(ie.font_height) || 83.333333333333,
|
|
887
|
-
padding: Number(ie.padding) || 15,
|
|
888
|
-
__typename: 'GenAILatexItem',
|
|
932
|
+
const meta = AIRich.tokenizer(code, language);
|
|
933
|
+
|
|
934
|
+
this._submessages.push({
|
|
935
|
+
messageType: 5,
|
|
936
|
+
codeMetadata: {
|
|
937
|
+
codeLanguage: language,
|
|
938
|
+
codeBlocks: meta.codeBlock,
|
|
889
939
|
},
|
|
890
|
-
};
|
|
891
|
-
});
|
|
892
|
-
|
|
893
|
-
this._submessages.push({
|
|
894
|
-
messageType: 2,
|
|
895
|
-
messageText: extractedIE.text,
|
|
896
|
-
});
|
|
897
|
-
|
|
898
|
-
this._sections.push(
|
|
899
|
-
AIRich.newLayout('Single', {
|
|
900
|
-
text: extractedIE.text,
|
|
901
|
-
...(inline_entities.length && {
|
|
902
|
-
inline_entities,
|
|
903
|
-
}),
|
|
904
|
-
__typename: 'GenAIMarkdownTextUXPrimitive',
|
|
905
|
-
})
|
|
906
|
-
);
|
|
940
|
+
});
|
|
907
941
|
|
|
908
|
-
|
|
909
|
-
|
|
942
|
+
this._sections.push(
|
|
943
|
+
AIRich.newLayout('Single', {
|
|
944
|
+
language,
|
|
945
|
+
code_blocks: meta.unified_codeBlock,
|
|
946
|
+
__typename: 'GenAICodeUXPrimitive',
|
|
947
|
+
})
|
|
948
|
+
);
|
|
910
949
|
|
|
911
|
-
|
|
912
|
-
if (typeof language !== 'string' || typeof code !== 'string') {
|
|
913
|
-
throw new TypeError('Language and code must be a string');
|
|
950
|
+
return this;
|
|
914
951
|
}
|
|
915
952
|
|
|
916
|
-
|
|
953
|
+
addTable(table) {
|
|
954
|
+
if (!Array.isArray(table)) {
|
|
955
|
+
throw new TypeError('Table must be an array');
|
|
956
|
+
}
|
|
917
957
|
|
|
918
|
-
|
|
919
|
-
messageType: 5,
|
|
920
|
-
codeMetadata: {
|
|
921
|
-
codeLanguage: language,
|
|
922
|
-
codeBlocks: meta.codeBlock,
|
|
923
|
-
},
|
|
924
|
-
});
|
|
958
|
+
const meta = AIRich.toTableMetadata(table);
|
|
925
959
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
960
|
+
this._submessages.push({
|
|
961
|
+
messageType: 4,
|
|
962
|
+
tableMetadata: {
|
|
963
|
+
title: meta.title,
|
|
964
|
+
rows: meta.rows,
|
|
965
|
+
},
|
|
966
|
+
});
|
|
933
967
|
|
|
934
|
-
|
|
935
|
-
|
|
968
|
+
this._sections.push(
|
|
969
|
+
AIRich.newLayout('Single', {
|
|
970
|
+
rows: meta.unified_rows,
|
|
971
|
+
__typename: 'GenATableUXPrimitive',
|
|
972
|
+
})
|
|
973
|
+
);
|
|
936
974
|
|
|
937
|
-
|
|
938
|
-
if (!Array.isArray(table)) {
|
|
939
|
-
throw new TypeError('Table must be an array');
|
|
975
|
+
return this;
|
|
940
976
|
}
|
|
941
977
|
|
|
942
|
-
const meta = AIRich.toTableMetadata(table);
|
|
943
978
|
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
rows: meta.rows,
|
|
949
|
-
},
|
|
950
|
-
});
|
|
979
|
+
addSource(sources = []) {
|
|
980
|
+
if (!(Array.isArray(sources) && (sources.every((item) => typeof item === 'string') || sources.every((item) => Array.isArray(item) && item.every((v) => typeof v === 'string'))))) {
|
|
981
|
+
throw new TypeError('Sources must be a string array or an array of string arrays');
|
|
982
|
+
}
|
|
951
983
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
__typename: 'GenATableUXPrimitive',
|
|
956
|
-
})
|
|
957
|
-
);
|
|
984
|
+
if (sources.every((item) => typeof item === 'string')) {
|
|
985
|
+
sources = [sources];
|
|
986
|
+
}
|
|
958
987
|
|
|
959
|
-
|
|
960
|
-
|
|
988
|
+
const source = sources.map(([profile_url, url, text]) => ({
|
|
989
|
+
source_type: 'THIRD_PARTY',
|
|
990
|
+
source_display_name: text ?? '',
|
|
991
|
+
source_subtitle: 'AI',
|
|
992
|
+
source_url: url ?? '',
|
|
993
|
+
favicon: {
|
|
994
|
+
url: profile_url ?? '',
|
|
995
|
+
mime_type: 'image/jpeg',
|
|
996
|
+
width: 16,
|
|
997
|
+
height: 16,
|
|
998
|
+
},
|
|
999
|
+
}));
|
|
961
1000
|
|
|
1001
|
+
this._sections.push(
|
|
1002
|
+
AIRich.newLayout('Single', {
|
|
1003
|
+
sources: source,
|
|
1004
|
+
__typename: 'GenAISearchResultPrimitive',
|
|
1005
|
+
})
|
|
1006
|
+
);
|
|
962
1007
|
|
|
963
|
-
|
|
964
|
-
if (!(Array.isArray(sources) && (sources.every((item) => typeof item === 'string') || sources.every((item) => Array.isArray(item) && item.every((v) => typeof v === 'string'))))) {
|
|
965
|
-
throw new TypeError('Sources must be a string array or an array of string arrays');
|
|
1008
|
+
return this;
|
|
966
1009
|
}
|
|
967
1010
|
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1011
|
+
addReels(reelsItems = []) {
|
|
1012
|
+
if (
|
|
1013
|
+
!(
|
|
1014
|
+
(reelsItems && typeof reelsItems === 'object' && !Array.isArray(reelsItems)) ||
|
|
1015
|
+
(Array.isArray(reelsItems) && reelsItems.every((item) => item && typeof item === 'object' && !Array.isArray(item)))
|
|
1016
|
+
)
|
|
1017
|
+
) {
|
|
1018
|
+
throw new TypeError('Reels items must be an object or an array of objects');
|
|
1019
|
+
}
|
|
971
1020
|
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
source_subtitle: 'AI',
|
|
976
|
-
source_url: url ?? '',
|
|
977
|
-
favicon: {
|
|
978
|
-
url: profile_url ?? '',
|
|
979
|
-
mime_type: 'image/jpeg',
|
|
980
|
-
width: 16,
|
|
981
|
-
height: 16,
|
|
982
|
-
},
|
|
983
|
-
}));
|
|
1021
|
+
if (!Array.isArray(reelsItems)) {
|
|
1022
|
+
reelsItems = [reelsItems];
|
|
1023
|
+
}
|
|
984
1024
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1025
|
+
this._submessages.push({
|
|
1026
|
+
messageType: 9,
|
|
1027
|
+
contentItemsMetadata: {
|
|
1028
|
+
contentType: 1,
|
|
1029
|
+
itemsMetadata: reelsItems.map((item) => ({
|
|
1030
|
+
reelItem: {
|
|
1031
|
+
title: item.username ?? '',
|
|
1032
|
+
profileIconUrl: item.profileIconUrl ?? item.profile_url ?? '',
|
|
1033
|
+
thumbnailUrl: item.thumbnailUrl ?? item.thumbnail ?? '',
|
|
1034
|
+
videoUrl: item.videoUrl ?? item.url ?? '',
|
|
1035
|
+
},
|
|
1036
|
+
})),
|
|
1037
|
+
},
|
|
1038
|
+
});
|
|
991
1039
|
|
|
992
|
-
|
|
993
|
-
|
|
1040
|
+
reelsItems.forEach((item, idx) => {
|
|
1041
|
+
this._richResponseSources.push({
|
|
1042
|
+
provider: '\u004E\u0049\u0058\u0045\u004C',
|
|
1043
|
+
thumbnailCDNURL: item.thumbnailUrl ?? item.thumbnail ?? '',
|
|
1044
|
+
sourceProviderURL: item.videoUrl ?? item.url ?? '',
|
|
1045
|
+
sourceQuery: '',
|
|
1046
|
+
faviconCDNURL: item.profileIconUrl ?? item.profile_url ?? '',
|
|
1047
|
+
citationNumber: idx + 1,
|
|
1048
|
+
sourceTitle: item.username ?? '',
|
|
1049
|
+
});
|
|
1050
|
+
});
|
|
994
1051
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1052
|
+
this._sections.push(
|
|
1053
|
+
AIRich.newLayout(
|
|
1054
|
+
'HScroll',
|
|
1055
|
+
reelsItems.map((item) => ({
|
|
1056
|
+
reels_url: item.videoUrl ?? item.url ?? '',
|
|
1057
|
+
thumbnail_url: item.thumbnailUrl ?? item.thumbnail ?? '',
|
|
1058
|
+
creator: item.username ?? item.title ?? '',
|
|
1059
|
+
avatar_url: item.profileIconUrl ?? item.profile_url ?? '',
|
|
1060
|
+
reels_title: item.reels_title ?? item.title ?? '',
|
|
1061
|
+
likes_count: item.likes_count ?? item.like ?? 0,
|
|
1062
|
+
shares_count: item.shares_count ?? item.share ?? 0,
|
|
1063
|
+
view_count: item.view_count ?? item.view ?? 0,
|
|
1064
|
+
reel_source: item.reel_source ?? item.source ?? 'IG',
|
|
1065
|
+
is_verified: !!(item.is_verified || item.verified),
|
|
1066
|
+
__typename: 'GenAIReelPrimitive',
|
|
1067
|
+
}))
|
|
1068
|
+
)
|
|
1069
|
+
);
|
|
1004
1070
|
|
|
1005
|
-
|
|
1006
|
-
reelsItems = [reelsItems];
|
|
1071
|
+
return this;
|
|
1007
1072
|
}
|
|
1008
1073
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1074
|
+
addImage(imageUrl) {
|
|
1075
|
+
if (!(typeof imageUrl === 'string' || (Array.isArray(imageUrl) && imageUrl.every((v) => typeof v === 'string')))) {
|
|
1076
|
+
throw new TypeError('imageUrl must be a string or array of strings');
|
|
1077
|
+
}
|
|
1078
|
+
const imageUrls = Array.isArray(imageUrl) ?
|
|
1079
|
+
imageUrl.map((url) => ({
|
|
1080
|
+
imagePreviewUrl: url,
|
|
1081
|
+
imageHighResUrl: url,
|
|
1082
|
+
sourceUrl: String.fromCharCode(104, 116, 116, 112, 115, 58, 47, 47, 102, 105, 111, 114, 97, 46, 110, 105, 120, 101, 108, 46, 109, 121, 46, 105, 100, 47),
|
|
1083
|
+
})) : [{
|
|
1084
|
+
imagePreviewUrl: imageUrl,
|
|
1085
|
+
imageHighResUrl: imageUrl,
|
|
1086
|
+
sourceUrl: String.fromCharCode(104, 116, 116, 112, 115, 58, 47, 47, 102, 105, 111, 114, 97, 46, 110, 105, 120, 101, 108, 46, 109, 121, 46, 105, 100, 47),
|
|
1087
|
+
}, ];
|
|
1088
|
+
|
|
1089
|
+
this._submessages.push({
|
|
1090
|
+
messageType: 1,
|
|
1091
|
+
gridImageMetadata: {
|
|
1092
|
+
gridImageUrl: {
|
|
1093
|
+
imagePreviewUrl: Array.isArray(imageUrl) ? imageUrl[0] : imageUrl,
|
|
1019
1094
|
},
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
reelsItems.forEach((item, idx) => {
|
|
1025
|
-
this._richResponseSources.push({
|
|
1026
|
-
provider: '\u004E\u0049\u0058\u0045\u004C',
|
|
1027
|
-
thumbnailCDNURL: item.thumbnailUrl ?? item.thumbnail ?? '',
|
|
1028
|
-
sourceProviderURL: item.videoUrl ?? item.url ?? '',
|
|
1029
|
-
sourceQuery: '',
|
|
1030
|
-
faviconCDNURL: item.profileIconUrl ?? item.profile_url ?? '',
|
|
1031
|
-
citationNumber: idx + 1,
|
|
1032
|
-
sourceTitle: item.username ?? '',
|
|
1095
|
+
imageUrls,
|
|
1096
|
+
},
|
|
1033
1097
|
});
|
|
1034
|
-
});
|
|
1035
|
-
|
|
1036
|
-
this._sections.push(
|
|
1037
|
-
AIRich.newLayout(
|
|
1038
|
-
'HScroll',
|
|
1039
|
-
reelsItems.map((item) => ({
|
|
1040
|
-
reels_url: item.videoUrl ?? item.url ?? '',
|
|
1041
|
-
thumbnail_url: item.thumbnailUrl ?? item.thumbnail ?? '',
|
|
1042
|
-
creator: item.username ?? item.title ?? '',
|
|
1043
|
-
avatar_url: item.profileIconUrl ?? item.profile_url ?? '',
|
|
1044
|
-
reels_title: item.reels_title ?? item.title ?? '',
|
|
1045
|
-
likes_count: item.likes_count ?? item.like ?? 0,
|
|
1046
|
-
shares_count: item.shares_count ?? item.share ?? 0,
|
|
1047
|
-
view_count: item.view_count ?? item.view ?? 0,
|
|
1048
|
-
reel_source: item.reel_source ?? item.source ?? 'IG',
|
|
1049
|
-
is_verified: !!(item.is_verified || item.verified),
|
|
1050
|
-
__typename: 'GenAIReelPrimitive',
|
|
1051
|
-
}))
|
|
1052
|
-
)
|
|
1053
|
-
);
|
|
1054
1098
|
|
|
1055
|
-
|
|
1056
|
-
|
|
1099
|
+
imageUrls.forEach(({
|
|
1100
|
+
imagePreviewUrl
|
|
1101
|
+
}) => {
|
|
1102
|
+
this._sections.push(
|
|
1103
|
+
AIRich.newLayout('Single', {
|
|
1104
|
+
media: {
|
|
1105
|
+
url: imagePreviewUrl,
|
|
1106
|
+
mime_type: 'image/png',
|
|
1107
|
+
},
|
|
1108
|
+
imagine_type: 'IMAGE',
|
|
1109
|
+
status: {
|
|
1110
|
+
status: 'READY',
|
|
1111
|
+
},
|
|
1112
|
+
__typename: 'GenAIImaginePrimitive',
|
|
1113
|
+
})
|
|
1114
|
+
);
|
|
1115
|
+
});
|
|
1057
1116
|
|
|
1058
|
-
|
|
1059
|
-
if (!(typeof imageUrl === 'string' || (Array.isArray(imageUrl) && imageUrl.every((v) => typeof v === 'string')))) {
|
|
1060
|
-
throw new TypeError('imageUrl must be a string or array of strings');
|
|
1117
|
+
return this;
|
|
1061
1118
|
}
|
|
1062
|
-
const imageUrls = Array.isArray(imageUrl) ?
|
|
1063
|
-
imageUrl.map((url) => ({
|
|
1064
|
-
imagePreviewUrl: url,
|
|
1065
|
-
imageHighResUrl: url,
|
|
1066
|
-
sourceUrl: String.fromCharCode(104, 116, 116, 112, 115, 58, 47, 47, 102, 105, 111, 114, 97, 46, 110, 105, 120, 101, 108, 46, 109, 121, 46, 105, 100, 47),
|
|
1067
|
-
})) : [{
|
|
1068
|
-
imagePreviewUrl: imageUrl,
|
|
1069
|
-
imageHighResUrl: imageUrl,
|
|
1070
|
-
sourceUrl: String.fromCharCode(104, 116, 116, 112, 115, 58, 47, 47, 102, 105, 111, 114, 97, 46, 110, 105, 120, 101, 108, 46, 109, 121, 46, 105, 100, 47),
|
|
1071
|
-
}, ];
|
|
1072
1119
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
imagePreviewUrl: Array.isArray(imageUrl) ? imageUrl[0] : imageUrl,
|
|
1078
|
-
},
|
|
1079
|
-
imageUrls,
|
|
1080
|
-
},
|
|
1081
|
-
});
|
|
1120
|
+
addVideo(videoUrl) {
|
|
1121
|
+
if (!(typeof videoUrl === 'string' || (Array.isArray(videoUrl) && videoUrl.every((v) => typeof v === 'string')))) {
|
|
1122
|
+
throw new TypeError('videoUrl must be a string or array of strings');
|
|
1123
|
+
}
|
|
1082
1124
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
}) => {
|
|
1086
|
-
this._sections.push(
|
|
1087
|
-
AIRich.newLayout('Single', {
|
|
1088
|
-
media: {
|
|
1089
|
-
url: imagePreviewUrl,
|
|
1090
|
-
mime_type: 'image/png',
|
|
1091
|
-
},
|
|
1092
|
-
imagine_type: 'IMAGE',
|
|
1093
|
-
status: {
|
|
1094
|
-
status: 'READY',
|
|
1095
|
-
},
|
|
1096
|
-
__typename: 'GenAIImaginePrimitive',
|
|
1097
|
-
})
|
|
1098
|
-
);
|
|
1099
|
-
});
|
|
1125
|
+
const videoUrls = (Array.isArray(videoUrl) ? videoUrl : [videoUrl]).map((item) => {
|
|
1126
|
+
const [url, duration = 0] = item.split('|');
|
|
1100
1127
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1128
|
+
return {
|
|
1129
|
+
videoPreviewUrl: url,
|
|
1130
|
+
videoHighResUrl: url,
|
|
1131
|
+
duration: Number(duration) || 0,
|
|
1132
|
+
sourceUrl: String.fromCharCode(104, 116, 116, 112, 115, 58, 47, 47, 102, 105, 111, 114, 97, 46, 110, 105, 120, 101, 108, 46, 109, 121, 46, 105, 100, 47),
|
|
1133
|
+
};
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
this._submessages.push({
|
|
1137
|
+
messageType: 2,
|
|
1138
|
+
messageText: '[ CANNOT_LOAD_VIDEO - \u0052\u0059\u0055\u0055 ]',
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
videoUrls.forEach(({
|
|
1142
|
+
videoPreviewUrl,
|
|
1143
|
+
duration = 0
|
|
1144
|
+
}) => {
|
|
1145
|
+
this._sections.push(
|
|
1146
|
+
AIRich.newLayout('Single', {
|
|
1147
|
+
media: {
|
|
1148
|
+
url: videoPreviewUrl,
|
|
1149
|
+
mime_type: 'video/mp4',
|
|
1150
|
+
duration,
|
|
1151
|
+
},
|
|
1152
|
+
imagine_type: 'ANIMATE',
|
|
1153
|
+
status: {
|
|
1154
|
+
status: 'READY',
|
|
1155
|
+
},
|
|
1156
|
+
__typename: 'GenAIImaginePrimitive',
|
|
1157
|
+
})
|
|
1158
|
+
);
|
|
1159
|
+
});
|
|
1103
1160
|
|
|
1104
|
-
|
|
1105
|
-
if (!(typeof videoUrl === 'string' || (Array.isArray(videoUrl) && videoUrl.every((v) => typeof v === 'string')))) {
|
|
1106
|
-
throw new TypeError('videoUrl must be a string or array of strings');
|
|
1161
|
+
return this;
|
|
1107
1162
|
}
|
|
1108
1163
|
|
|
1109
|
-
|
|
1110
|
-
|
|
1164
|
+
addProduct(data = {}) {
|
|
1165
|
+
if (!((data && typeof data === 'object' && !Array.isArray(data)) || (Array.isArray(data) && data.every((item) => item && typeof item === 'object' && !Array.isArray(item))))) {
|
|
1166
|
+
throw new TypeError('Product items must be an object or an array of objects');
|
|
1167
|
+
}
|
|
1111
1168
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
sourceUrl: String.fromCharCode(104, 116, 116, 112, 115, 58, 47, 47, 102, 105, 111, 114, 97, 46, 110, 105, 120, 101, 108, 46, 109, 121, 46, 105, 100, 47),
|
|
1117
|
-
};
|
|
1118
|
-
});
|
|
1169
|
+
this._submessages.push({
|
|
1170
|
+
messageType: 2,
|
|
1171
|
+
messageText: '[ CANNOT_LOAD_PRODUCT - \u0052\u0059\u0055\u0055 ]',
|
|
1172
|
+
});
|
|
1119
1173
|
|
|
1120
|
-
|
|
1121
|
-
messageType: 2,
|
|
1122
|
-
messageText: '[ CANNOT_LOAD_VIDEO - \u0052\u0059\u0055\u0055 ]',
|
|
1123
|
-
});
|
|
1174
|
+
const items = Array.isArray(data) ? data : [data];
|
|
1124
1175
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
},
|
|
1140
|
-
__typename: 'GenAIImaginePrimitive',
|
|
1141
|
-
})
|
|
1142
|
-
);
|
|
1143
|
-
});
|
|
1176
|
+
const product = items.map((item) => ({
|
|
1177
|
+
title: item.title,
|
|
1178
|
+
brand: item.brand,
|
|
1179
|
+
price: item.price,
|
|
1180
|
+
sale_price: item.sale_price,
|
|
1181
|
+
product_url: item.product_url ?? item.url,
|
|
1182
|
+
image: {
|
|
1183
|
+
url: item.image_url ?? item.image,
|
|
1184
|
+
},
|
|
1185
|
+
additional_images: [{
|
|
1186
|
+
url: item.icon_url ?? item.icon,
|
|
1187
|
+
}, ],
|
|
1188
|
+
__typename: 'GenAIProductItemCardPrimitive',
|
|
1189
|
+
}));
|
|
1144
1190
|
|
|
1145
|
-
|
|
1146
|
-
}
|
|
1191
|
+
this._sections.push(AIRich.newLayout(Array.isArray(data) ? 'HScroll' : 'Single', Array.isArray(data) ? product : product[0]));
|
|
1147
1192
|
|
|
1148
|
-
|
|
1149
|
-
if (!((data && typeof data === 'object' && !Array.isArray(data)) || (Array.isArray(data) && data.every((item) => item && typeof item === 'object' && !Array.isArray(item))))) {
|
|
1150
|
-
throw new TypeError('Product items must be an object or an array of objects');
|
|
1193
|
+
return this;
|
|
1151
1194
|
}
|
|
1152
1195
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
const items = Array.isArray(data) ? data : [data];
|
|
1159
|
-
|
|
1160
|
-
const product = items.map((item) => ({
|
|
1161
|
-
title: item.title,
|
|
1162
|
-
brand: item.brand,
|
|
1163
|
-
price: item.price,
|
|
1164
|
-
sale_price: item.sale_price,
|
|
1165
|
-
product_url: item.product_url ?? item.url,
|
|
1166
|
-
image: {
|
|
1167
|
-
url: item.image_url ?? item.image,
|
|
1168
|
-
},
|
|
1169
|
-
additional_images: [{
|
|
1170
|
-
url: item.icon_url ?? item.icon,
|
|
1171
|
-
}, ],
|
|
1172
|
-
__typename: 'GenAIProductItemCardPrimitive',
|
|
1173
|
-
}));
|
|
1196
|
+
addPost(data = {}) {
|
|
1197
|
+
if (!((data && typeof data === 'object' && !Array.isArray(data)) || (Array.isArray(data) && data.every((item) => item && typeof item === 'object' && !Array.isArray(item))))) {
|
|
1198
|
+
throw new TypeError('Post items must be an object or an array of objects');
|
|
1199
|
+
}
|
|
1174
1200
|
|
|
1175
|
-
|
|
1201
|
+
const posts = Array.isArray(data) ? data : [data];
|
|
1176
1202
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1203
|
+
this._submessages.push({
|
|
1204
|
+
messageType: 2,
|
|
1205
|
+
messageText: '[ CANNOT_LOAD_POST - \u0052\u0059\u0055\u0055 ]',
|
|
1206
|
+
});
|
|
1179
1207
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1208
|
+
const primitives = posts.map((p) => ({
|
|
1209
|
+
title: p.title ?? '',
|
|
1210
|
+
subtitle: p.subtitle ?? '',
|
|
1211
|
+
username: p.username ?? '',
|
|
1212
|
+
profile_picture_url: p.profile_picture_url ?? p.profile_url ?? '',
|
|
1213
|
+
is_verified: !!(p.is_verified || p.verified),
|
|
1214
|
+
thumbnail_url: p.thumbnail_url ?? p.thumbnail ?? '',
|
|
1215
|
+
post_caption: p.post_caption ?? p.caption ?? '',
|
|
1216
|
+
likes_count: p.likes_count ?? p.like ?? 0,
|
|
1217
|
+
comments_count: p.comments_count ?? p.comment ?? 0,
|
|
1218
|
+
shares_count: p.shares_count ?? p.share ?? 0,
|
|
1219
|
+
post_url: p.post_url ?? p.url ?? '',
|
|
1220
|
+
post_deeplink: p.post_deeplink ?? p.deeplink ?? '',
|
|
1221
|
+
source_app: p.source_app || p.source || 'INSTAGRAM',
|
|
1222
|
+
footer_label: p.footer_label ?? p.footer ?? '',
|
|
1223
|
+
footer_icon: p.footer_icon ?? p.icon ?? '',
|
|
1224
|
+
is_carousel: posts.length > 1,
|
|
1225
|
+
orientation: p.orientation ?? 'LANDSCAPE',
|
|
1226
|
+
post_type: p.post_type ?? 'VIDEO',
|
|
1227
|
+
__typename: 'GenAIPostPrimitive',
|
|
1228
|
+
}));
|
|
1229
|
+
|
|
1230
|
+
this._sections.push(AIRich.newLayout('HScroll', primitives));
|
|
1231
|
+
|
|
1232
|
+
return this;
|
|
1183
1233
|
}
|
|
1184
1234
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
});
|
|
1191
|
-
|
|
1192
|
-
const primitives = posts.map((p) => ({
|
|
1193
|
-
title: p.title ?? '',
|
|
1194
|
-
subtitle: p.subtitle ?? '',
|
|
1195
|
-
username: p.username ?? '',
|
|
1196
|
-
profile_picture_url: p.profile_picture_url ?? p.profile_url ?? '',
|
|
1197
|
-
is_verified: !!(p.is_verified || p.verified),
|
|
1198
|
-
thumbnail_url: p.thumbnail_url ?? p.thumbnail ?? '',
|
|
1199
|
-
post_caption: p.post_caption ?? p.caption ?? '',
|
|
1200
|
-
likes_count: p.likes_count ?? p.like ?? 0,
|
|
1201
|
-
comments_count: p.comments_count ?? p.comment ?? 0,
|
|
1202
|
-
shares_count: p.shares_count ?? p.share ?? 0,
|
|
1203
|
-
post_url: p.post_url ?? p.url ?? '',
|
|
1204
|
-
post_deeplink: p.post_deeplink ?? p.deeplink ?? '',
|
|
1205
|
-
source_app: p.source_app || p.source || 'INSTAGRAM',
|
|
1206
|
-
footer_label: p.footer_label ?? p.footer ?? '',
|
|
1207
|
-
footer_icon: p.footer_icon ?? p.icon ?? '',
|
|
1208
|
-
is_carousel: posts.length > 1,
|
|
1209
|
-
orientation: p.orientation ?? 'LANDSCAPE',
|
|
1210
|
-
post_type: p.post_type ?? 'VIDEO',
|
|
1211
|
-
__typename: 'GenAIPostPrimitive',
|
|
1212
|
-
}));
|
|
1213
|
-
|
|
1214
|
-
this._sections.push(AIRich.newLayout('HScroll', primitives));
|
|
1215
|
-
|
|
1216
|
-
return this;
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
addTip(text) {
|
|
1220
|
-
this._submessages.push({
|
|
1221
|
-
messageType: 2,
|
|
1222
|
-
messageText: text,
|
|
1223
|
-
});
|
|
1224
|
-
|
|
1225
|
-
this._sections.push(
|
|
1226
|
-
AIRich.newLayout('Single', {
|
|
1227
|
-
text,
|
|
1228
|
-
__typename: 'GenAIMetadataTextPrimitive',
|
|
1229
|
-
})
|
|
1230
|
-
);
|
|
1235
|
+
addTip(text) {
|
|
1236
|
+
this._submessages.push({
|
|
1237
|
+
messageType: 2,
|
|
1238
|
+
messageText: text,
|
|
1239
|
+
});
|
|
1231
1240
|
|
|
1232
|
-
|
|
1233
|
-
|
|
1241
|
+
this._sections.push(
|
|
1242
|
+
AIRich.newLayout('Single', {
|
|
1243
|
+
text,
|
|
1244
|
+
__typename: 'GenAIMetadataTextPrimitive',
|
|
1245
|
+
})
|
|
1246
|
+
);
|
|
1234
1247
|
|
|
1235
|
-
|
|
1236
|
-
if (!(typeof suggestion === 'string' || (Array.isArray(suggestion) && suggestion.every((v) => typeof v === 'string')))) {
|
|
1237
|
-
throw new TypeError('Suggestion must be a string or array of strings');
|
|
1248
|
+
return this;
|
|
1238
1249
|
}
|
|
1239
1250
|
|
|
1240
|
-
|
|
1241
|
-
suggestion.
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
__typename: 'GenAIFollowUpSuggestionPillPrimitive',
|
|
1245
|
-
})) : [{
|
|
1246
|
-
prompt_text: suggestion,
|
|
1247
|
-
prompt_type: 'SUGGESTED_PROMPT',
|
|
1248
|
-
__typename: 'GenAIFollowUpSuggestionPillPrimitive',
|
|
1249
|
-
}, ];
|
|
1251
|
+
addSuggest(suggestion) {
|
|
1252
|
+
if (!(typeof suggestion === 'string' || (Array.isArray(suggestion) && suggestion.every((v) => typeof v === 'string')))) {
|
|
1253
|
+
throw new TypeError('Suggestion must be a string or array of strings');
|
|
1254
|
+
}
|
|
1250
1255
|
|
|
1251
|
-
|
|
1256
|
+
const suggest = Array.isArray(suggestion) ?
|
|
1257
|
+
suggestion.map((text) => ({
|
|
1258
|
+
prompt_text: text,
|
|
1259
|
+
prompt_type: 'SUGGESTED_PROMPT',
|
|
1260
|
+
__typename: 'GenAIFollowUpSuggestionPillPrimitive',
|
|
1261
|
+
})) : [{
|
|
1262
|
+
prompt_text: suggestion,
|
|
1263
|
+
prompt_type: 'SUGGESTED_PROMPT',
|
|
1264
|
+
__typename: 'GenAIFollowUpSuggestionPillPrimitive',
|
|
1265
|
+
}, ];
|
|
1252
1266
|
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1267
|
+
this._sections.push(AIRich.newLayout('ActionRow', suggest));
|
|
1255
1268
|
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
includesUnifiedResponse = true,
|
|
1259
|
-
includesSubmessages = true,
|
|
1260
|
-
quoted,
|
|
1261
|
-
quotedParticipant,
|
|
1262
|
-
...options
|
|
1263
|
-
} = {}) {
|
|
1264
|
-
const forward = forwarded ? {
|
|
1265
|
-
forwardingScore: 1,
|
|
1266
|
-
isForwarded: true,
|
|
1267
|
-
forwardedAiBotMessageInfo: {
|
|
1268
|
-
botJid: '0@bot'
|
|
1269
|
-
},
|
|
1270
|
-
forwardOrigin: 4,
|
|
1271
|
-
} : {};
|
|
1272
|
-
|
|
1273
|
-
const qObj = quoted ? {
|
|
1274
|
-
stanzaId: quoted?.key?.id || quoted?.id,
|
|
1275
|
-
participant: quotedParticipant || quoted?.key?.participant || quoted?.key?.remoteJid,
|
|
1276
|
-
quotedType: 0,
|
|
1277
|
-
quotedMessage: typeof quoted === 'object' && quoted !== null ? (quoted.message ?? quoted) : undefined,
|
|
1278
|
-
} : {};
|
|
1279
|
-
|
|
1280
|
-
const sections = this._footer ? [
|
|
1281
|
-
...this._sections,
|
|
1282
|
-
AIRich.newLayout('Single', {
|
|
1283
|
-
text: this._footer,
|
|
1284
|
-
__typename: 'GenAIMetadataTextPrimitive',
|
|
1285
|
-
}),
|
|
1286
|
-
] : [...this._sections];
|
|
1269
|
+
return this;
|
|
1270
|
+
}
|
|
1287
1271
|
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1272
|
+
build({
|
|
1273
|
+
forwarded = true,
|
|
1274
|
+
includesUnifiedResponse = true,
|
|
1275
|
+
includesSubmessages = true,
|
|
1276
|
+
quoted,
|
|
1277
|
+
quotedParticipant,
|
|
1278
|
+
...options
|
|
1279
|
+
} = {}) {
|
|
1280
|
+
const forward = forwarded ? {
|
|
1281
|
+
forwardingScore: 1,
|
|
1282
|
+
isForwarded: true,
|
|
1283
|
+
forwardedAiBotMessageInfo: {
|
|
1284
|
+
botJid: '0@bot'
|
|
1297
1285
|
},
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1286
|
+
forwardOrigin: 4,
|
|
1287
|
+
} : {};
|
|
1288
|
+
|
|
1289
|
+
const qObj = quoted ? {
|
|
1290
|
+
stanzaId: quoted?.key?.id || quoted?.id,
|
|
1291
|
+
participant: quotedParticipant || quoted?.key?.participant || quoted?.key?.remoteJid,
|
|
1292
|
+
quotedType: 0,
|
|
1293
|
+
quotedMessage: typeof quoted === 'object' && quoted !== null ? (quoted.message ?? quoted) : undefined,
|
|
1294
|
+
} : {};
|
|
1295
|
+
|
|
1296
|
+
const sections = this._footer ? [
|
|
1297
|
+
...this._sections,
|
|
1298
|
+
AIRich.newLayout('Single', {
|
|
1299
|
+
text: this._footer,
|
|
1300
|
+
__typename: 'GenAIMetadataTextPrimitive',
|
|
1301
|
+
}),
|
|
1302
|
+
] : [...this._sections];
|
|
1303
|
+
|
|
1304
|
+
return {
|
|
1305
|
+
messageContextInfo: {
|
|
1306
|
+
deviceListMetadata: {},
|
|
1307
|
+
deviceListMetadataVersion: 2,
|
|
1308
|
+
botMetadata: {
|
|
1309
|
+
messageDisclaimerText: this._title,
|
|
1310
|
+
richResponseSourcesMetadata: {
|
|
1311
|
+
sources: this._richResponseSources
|
|
1310
1312
|
},
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1313
|
+
},
|
|
1314
|
+
},
|
|
1315
|
+
...this._extraPayload,
|
|
1316
|
+
botForwardedMessage: {
|
|
1317
|
+
message: {
|
|
1318
|
+
richResponseMessage: {
|
|
1319
|
+
messageType: 1,
|
|
1320
|
+
submessages: includesSubmessages ? this._submessages : [],
|
|
1321
|
+
unifiedResponse: {
|
|
1322
|
+
data: includesUnifiedResponse ? Buffer.from(JSON.stringify({
|
|
1323
|
+
response_id: crypto.randomUUID(),
|
|
1324
|
+
sections
|
|
1325
|
+
})).toString("base64") : ''
|
|
1326
|
+
},
|
|
1327
|
+
contextInfo: {
|
|
1328
|
+
...forward,
|
|
1329
|
+
...qObj,
|
|
1330
|
+
...this._contextInfo,
|
|
1331
|
+
},
|
|
1315
1332
|
},
|
|
1316
1333
|
},
|
|
1317
1334
|
},
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1321
1337
|
|
|
1322
|
-
|
|
1323
|
-
forwarded,
|
|
1324
|
-
includesUnifiedResponse,
|
|
1325
|
-
includesSubmessages,
|
|
1326
|
-
...options
|
|
1327
|
-
} = {}) {
|
|
1328
|
-
const msg = this.build({
|
|
1338
|
+
async send(jid, {
|
|
1329
1339
|
forwarded,
|
|
1330
1340
|
includesUnifiedResponse,
|
|
1341
|
+
includesSubmessages,
|
|
1331
1342
|
...options
|
|
1332
|
-
})
|
|
1343
|
+
} = {}) {
|
|
1344
|
+
const msg = this.build({
|
|
1345
|
+
forwarded,
|
|
1346
|
+
includesUnifiedResponse,
|
|
1347
|
+
...options
|
|
1348
|
+
});
|
|
1333
1349
|
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1350
|
+
await this.#client.relayMessage(jid, msg, {
|
|
1351
|
+
...options
|
|
1352
|
+
});
|
|
1353
|
+
return msg
|
|
1354
|
+
}
|
|
1339
1355
|
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1356
|
+
static tokenizer(code, lang = 'javascript') {
|
|
1357
|
+
const keywordsMap = {
|
|
1358
|
+
javascript: new Set([
|
|
1359
|
+
'break',
|
|
1360
|
+
'case',
|
|
1361
|
+
'catch',
|
|
1362
|
+
'continue',
|
|
1363
|
+
'debugger',
|
|
1364
|
+
'delete',
|
|
1365
|
+
'do',
|
|
1366
|
+
'else',
|
|
1367
|
+
'finally',
|
|
1368
|
+
'for',
|
|
1369
|
+
'function',
|
|
1370
|
+
'if',
|
|
1371
|
+
'in',
|
|
1372
|
+
'instanceof',
|
|
1373
|
+
'new',
|
|
1374
|
+
'return',
|
|
1375
|
+
'switch',
|
|
1376
|
+
'this',
|
|
1377
|
+
'throw',
|
|
1378
|
+
'try',
|
|
1379
|
+
'typeof',
|
|
1380
|
+
'var',
|
|
1381
|
+
'void',
|
|
1382
|
+
'while',
|
|
1383
|
+
'with',
|
|
1384
|
+
'true',
|
|
1385
|
+
'false',
|
|
1386
|
+
'null',
|
|
1387
|
+
'undefined',
|
|
1388
|
+
'class',
|
|
1389
|
+
'const',
|
|
1390
|
+
'let',
|
|
1391
|
+
'super',
|
|
1392
|
+
'extends',
|
|
1393
|
+
'export',
|
|
1394
|
+
'import',
|
|
1395
|
+
'yield',
|
|
1396
|
+
'static',
|
|
1397
|
+
'constructor',
|
|
1398
|
+
'async',
|
|
1399
|
+
'await',
|
|
1400
|
+
'get',
|
|
1401
|
+
'set',
|
|
1402
|
+
]),
|
|
1403
|
+
};
|
|
1388
1404
|
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1405
|
+
const TYPE_MAP = {
|
|
1406
|
+
0: 'DEFAULT',
|
|
1407
|
+
1: 'KEYWORD',
|
|
1408
|
+
2: 'METHOD',
|
|
1409
|
+
3: 'STR',
|
|
1410
|
+
4: 'NUMBER',
|
|
1411
|
+
5: 'COMMENT',
|
|
1412
|
+
};
|
|
1397
1413
|
|
|
1398
|
-
|
|
1399
|
-
|
|
1414
|
+
const keywords = keywordsMap[lang] || new Set();
|
|
1415
|
+
const tokens = [];
|
|
1400
1416
|
|
|
1401
|
-
|
|
1417
|
+
let i = 0;
|
|
1402
1418
|
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1419
|
+
const push = (content, type) => {
|
|
1420
|
+
if (!content) return;
|
|
1421
|
+
const last = tokens[tokens.length - 1];
|
|
1422
|
+
if (last && last.highlightType === type) last.codeContent += content;
|
|
1423
|
+
else tokens.push({
|
|
1424
|
+
codeContent: content,
|
|
1425
|
+
highlightType: type
|
|
1426
|
+
});
|
|
1427
|
+
};
|
|
1412
1428
|
|
|
1413
|
-
|
|
1414
|
-
|
|
1429
|
+
while (i < code.length) {
|
|
1430
|
+
const c = code[i];
|
|
1415
1431
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1432
|
+
if (/\s/.test(c)) {
|
|
1433
|
+
let s = i;
|
|
1434
|
+
while (i < code.length && /\s/.test(code[i])) i++;
|
|
1435
|
+
push(code.slice(s, i), 0);
|
|
1436
|
+
continue;
|
|
1437
|
+
}
|
|
1422
1438
|
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1439
|
+
if (c === '/' && code[i + 1] === '/') {
|
|
1440
|
+
let s = i;
|
|
1441
|
+
i += 2;
|
|
1442
|
+
while (i < code.length && code[i] !== '\n') i++;
|
|
1443
|
+
push(code.slice(s, i), 5);
|
|
1444
|
+
continue;
|
|
1445
|
+
}
|
|
1430
1446
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1447
|
+
if (c === '"' || c === "'" || c === '`') {
|
|
1448
|
+
let s = i;
|
|
1449
|
+
const q = c;
|
|
1450
|
+
i++;
|
|
1451
|
+
while (i < code.length) {
|
|
1452
|
+
if (code[i] === '\\' && i + 1 < code.length) i += 2;
|
|
1453
|
+
else if (code[i] === q) {
|
|
1454
|
+
i++;
|
|
1455
|
+
break;
|
|
1456
|
+
} else i++;
|
|
1457
|
+
}
|
|
1458
|
+
push(code.slice(s, i), 3);
|
|
1459
|
+
continue;
|
|
1441
1460
|
}
|
|
1442
|
-
push(code.slice(s, i), 3);
|
|
1443
|
-
continue;
|
|
1444
|
-
}
|
|
1445
1461
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1462
|
+
if (/[0-9]/.test(c)) {
|
|
1463
|
+
let s = i;
|
|
1464
|
+
while (i < code.length && /[0-9.]/.test(code[i])) i++;
|
|
1465
|
+
push(code.slice(s, i), 4);
|
|
1466
|
+
continue;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
if (/[a-zA-Z_$]/.test(c)) {
|
|
1470
|
+
let s = i;
|
|
1471
|
+
while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) i++;
|
|
1472
|
+
const word = code.slice(s, i);
|
|
1473
|
+
|
|
1474
|
+
let type = 0;
|
|
1475
|
+
if (keywords.has(word)) type = 1;
|
|
1476
|
+
else {
|
|
1477
|
+
let j = i;
|
|
1478
|
+
while (j < code.length && /\s/.test(code[j])) j++;
|
|
1479
|
+
if (code[j] === '(') type = 2;
|
|
1480
|
+
}
|
|
1452
1481
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) i++;
|
|
1456
|
-
const word = code.slice(s, i);
|
|
1457
|
-
|
|
1458
|
-
let type = 0;
|
|
1459
|
-
if (keywords.has(word)) type = 1;
|
|
1460
|
-
else {
|
|
1461
|
-
let j = i;
|
|
1462
|
-
while (j < code.length && /\s/.test(code[j])) j++;
|
|
1463
|
-
if (code[j] === '(') type = 2;
|
|
1482
|
+
push(word, type);
|
|
1483
|
+
continue;
|
|
1464
1484
|
}
|
|
1465
1485
|
|
|
1466
|
-
push(
|
|
1467
|
-
|
|
1486
|
+
push(c, 0);
|
|
1487
|
+
i++;
|
|
1468
1488
|
}
|
|
1469
1489
|
|
|
1470
|
-
|
|
1471
|
-
|
|
1490
|
+
return {
|
|
1491
|
+
codeBlock: tokens,
|
|
1492
|
+
unified_codeBlock: tokens.map((t) => ({
|
|
1493
|
+
content: t.codeContent,
|
|
1494
|
+
type: TYPE_MAP[t.highlightType],
|
|
1495
|
+
})),
|
|
1496
|
+
};
|
|
1472
1497
|
}
|
|
1473
1498
|
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
type: TYPE_MAP[t.highlightType],
|
|
1479
|
-
})),
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
static toTableMetadata(arr) {
|
|
1484
|
-
if (!Array.isArray(arr) || !arr.every((row) => Array.isArray(row) && row.every((cell) => typeof cell === 'string'))) {
|
|
1485
|
-
throw new TypeError('Table must be a nested array of strings');
|
|
1486
|
-
}
|
|
1499
|
+
static toTableMetadata(arr) {
|
|
1500
|
+
if (!Array.isArray(arr) || !arr.every((row) => Array.isArray(row) && row.every((cell) => typeof cell === 'string'))) {
|
|
1501
|
+
throw new TypeError('Table must be a nested array of strings');
|
|
1502
|
+
}
|
|
1487
1503
|
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1504
|
+
const [header, ...rows] = arr;
|
|
1505
|
+
const maxLen = Math.max(header.length, ...rows.map((r) => r.length));
|
|
1506
|
+
const normalize = (r) => [...r, ...Array(maxLen - r.length).fill('')];
|
|
1491
1507
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
text: cell
|
|
1497
|
-
}))
|
|
1498
|
-
},
|
|
1499
|
-
...rows.map((r) => {
|
|
1500
|
-
const normalizedRow = normalize(r);
|
|
1501
|
-
return {
|
|
1502
|
-
is_header: false,
|
|
1503
|
-
cells: normalizedRow,
|
|
1504
|
-
markdown_cells: normalizedRow.map(cell => ({
|
|
1508
|
+
const unified_rows = [{
|
|
1509
|
+
is_header: true,
|
|
1510
|
+
cells: normalize(header),
|
|
1511
|
+
markdown_cells: normalize(header).map(cell => ({
|
|
1505
1512
|
text: cell
|
|
1506
1513
|
}))
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1514
|
+
},
|
|
1515
|
+
...rows.map((r) => {
|
|
1516
|
+
const normalizedRow = normalize(r);
|
|
1517
|
+
return {
|
|
1518
|
+
is_header: false,
|
|
1519
|
+
cells: normalizedRow,
|
|
1520
|
+
markdown_cells: normalizedRow.map(cell => ({
|
|
1521
|
+
text: cell
|
|
1522
|
+
}))
|
|
1523
|
+
};
|
|
1524
|
+
}),
|
|
1525
|
+
];
|
|
1510
1526
|
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1527
|
+
const rowsMeta = unified_rows.map((r) => ({
|
|
1528
|
+
items: r.cells,
|
|
1529
|
+
...(r.is_header ? {
|
|
1530
|
+
isHeading: true
|
|
1531
|
+
} : {}),
|
|
1532
|
+
}));
|
|
1517
1533
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1534
|
+
return {
|
|
1535
|
+
title: '',
|
|
1536
|
+
rows: rowsMeta,
|
|
1537
|
+
unified_rows,
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1523
1540
|
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
*/
|
|
1529
|
-
|
|
1530
|
-
function addProperty(socket, baileys) {
|
|
1531
|
-
const {
|
|
1532
|
-
proto,
|
|
1533
|
-
generateWAMessageFromContent,
|
|
1534
|
-
jidDecode,
|
|
1535
|
-
downloadContentFromMessage,
|
|
1536
|
-
prepareWAMessageMedia,
|
|
1537
|
-
generateMessageID,
|
|
1538
|
-
generateWAMessage
|
|
1539
|
-
} = baileys;
|
|
1540
|
-
let sendMessage = socket.sendMessage;
|
|
1541
|
+
global.Button = Button;
|
|
1542
|
+
global.ButtonV2 = ButtonV2;
|
|
1543
|
+
global.Carousel = Carousel;
|
|
1544
|
+
global.AIRich = AIRich;
|
|
1541
1545
|
Object.assign(socket, {
|
|
1542
1546
|
sendMessage: async (jid, content, options = {}) => {
|
|
1543
1547
|
let {
|
|
@@ -2440,9 +2444,7 @@ function addProperty(socket, baileys) {
|
|
|
2440
2444
|
};
|
|
2441
2445
|
|
|
2442
2446
|
export default addProperty;
|
|
2443
|
-
export
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
AIRich
|
|
2448
|
-
};
|
|
2447
|
+
export const Button = global.Button;
|
|
2448
|
+
export const ButtonV2 = global.ButtonV2;
|
|
2449
|
+
export const Carousel = global.Carousel;
|
|
2450
|
+
export const AIRich = global.AIRich;
|