@ubedsockets/baileys 1.6.7 → 1.6.9
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/WAProto/index.js +17 -17
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.d.ts.map +1 -0
- package/lib/Types/RichType.js +31 -0
- package/lib/Utils/messages.js +11 -1
- package/lib/Utils/rich-message-utils.js +387 -0
- package/package.json +1 -1
package/WAProto/index.js
CHANGED
|
@@ -7970,6 +7970,23 @@ $root.proto = (function() {
|
|
|
7970
7970
|
|
|
7971
7971
|
return AIRichResponseMessage;
|
|
7972
7972
|
})();
|
|
7973
|
+
|
|
7974
|
+
// ===== AIRich top-level alias fix =====
|
|
7975
|
+
proto.AIRichResponseSubMessage = proto.AIRichResponseMessage.AIRichResponseSubMessage
|
|
7976
|
+
proto.AIRichResponseCodeMetadata = proto.AIRichResponseMessage.AIRichResponseCodeMetadata
|
|
7977
|
+
proto.AIRichResponseTableMetadata = proto.AIRichResponseMessage.AIRichResponseTableMetadata
|
|
7978
|
+
proto.AIRichResponseUnifiedResponse = proto.AIRichResponseMessage.AIRichResponseUnifiedResponse
|
|
7979
|
+
proto.AIRichResponseMessageType = proto.AIRichResponseMessage.AIRichResponseMessageType
|
|
7980
|
+
proto.AIRichResponseSubMessageType = proto.AIRichResponseMessage.AIRichResponseSubMessageType
|
|
7981
|
+
|
|
7982
|
+
proto.AIRichResponseContentItemsMetadata = proto.AIRichResponseMessage.AIRichResponseContentItemsMetadata
|
|
7983
|
+
proto.AIRichResponseDynamicMetadata = proto.AIRichResponseMessage.AIRichResponseDynamicMetadata
|
|
7984
|
+
proto.AIRichResponseGridImageMetadata = proto.AIRichResponseMessage.AIRichResponseGridImageMetadata
|
|
7985
|
+
proto.AIRichResponseImageURL = proto.AIRichResponseMessage.AIRichResponseImageURL
|
|
7986
|
+
proto.AIRichResponseInlineImageMetadata = proto.AIRichResponseMessage.AIRichResponseInlineImageMetadata
|
|
7987
|
+
proto.AIRichResponseLatexMetadata = proto.AIRichResponseMessage.AIRichResponseLatexMetadata
|
|
7988
|
+
proto.AIRichResponseMapMetadata = proto.AIRichResponseMessage.AIRichResponseMapMetadata
|
|
7989
|
+
// ===== END AIRich top-level alias fix =====
|
|
7973
7990
|
|
|
7974
7991
|
proto.Account = (function() {
|
|
7975
7992
|
|
|
@@ -33870,12 +33887,6 @@ $root.proto = (function() {
|
|
|
33870
33887
|
$root.proto.ContextInfo.BusinessMessageForwardInfo.encode(message.businessMessageForwardInfo, writer.uint32(/* id 44, wireType 2 =*/354).fork()).ldelim();
|
|
33871
33888
|
if (message.smbClientCampaignId != null && Object.hasOwnProperty.call(message, "smbClientCampaignId"))
|
|
33872
33889
|
writer.uint32(/* id 45, wireType 2 =*/362).string(message.smbClientCampaignId);
|
|
33873
|
-
|
|
33874
|
-
// ─── SUNTIKKAN KODE AREA KE-2 DI SINI ───
|
|
33875
|
-
if (message.richResponseMessage != null && Object.hasOwnProperty.call(message, "richResponseMessage"))
|
|
33876
|
-
$root.proto.AIRichResponseMessage.encode(message.richResponseMessage, writer.uint32(778).fork()).ldelim();
|
|
33877
|
-
// ────────────────────────────────────────
|
|
33878
|
-
|
|
33879
33890
|
if (message.smbServerCampaignId != null && Object.hasOwnProperty.call(message, "smbServerCampaignId"))
|
|
33880
33891
|
writer.uint32(/* id 46, wireType 2 =*/370).string(message.smbServerCampaignId);
|
|
33881
33892
|
if (message.dataSharingContext != null && Object.hasOwnProperty.call(message, "dataSharingContext"))
|
|
@@ -59503,7 +59514,6 @@ $root.proto = (function() {
|
|
|
59503
59514
|
}
|
|
59504
59515
|
if (message.interactiveMessage != null && message.hasOwnProperty("interactiveMessage")) {
|
|
59505
59516
|
properties._interactiveMessage = 1;
|
|
59506
|
-
|
|
59507
59517
|
{
|
|
59508
59518
|
var error = $root.proto.Message.InteractiveMessage.verify(message.interactiveMessage);
|
|
59509
59519
|
if (error)
|
|
@@ -60571,21 +60581,11 @@ $root.proto = (function() {
|
|
|
60571
60581
|
if (options.oneofs)
|
|
60572
60582
|
object._interactiveMessage = "interactiveMessage";
|
|
60573
60583
|
}
|
|
60574
|
-
|
|
60575
|
-
// ─── SUNTIKKAN KODE INI DI SINI ───
|
|
60576
|
-
if (message.richResponseMessage != null && message.hasOwnProperty("richResponseMessage")) {
|
|
60577
|
-
object.richResponseMessage = $root.proto.AIRichResponseMessage.toObject(message.richResponseMessage, options);
|
|
60578
|
-
if (options.oneofs)
|
|
60579
|
-
object._richResponseMessage = "richResponseMessage";
|
|
60580
|
-
}
|
|
60581
|
-
// ──────────────────────────────────
|
|
60582
|
-
|
|
60583
60584
|
if (message.reactionMessage != null && message.hasOwnProperty("reactionMessage")) {
|
|
60584
60585
|
object.reactionMessage = $root.proto.Message.ReactionMessage.toObject(message.reactionMessage, options);
|
|
60585
60586
|
if (options.oneofs)
|
|
60586
60587
|
object._reactionMessage = "reactionMessage";
|
|
60587
60588
|
}
|
|
60588
|
-
|
|
60589
60589
|
if (message.stickerSyncRmrMessage != null && message.hasOwnProperty("stickerSyncRmrMessage")) {
|
|
60590
60590
|
object.stickerSyncRmrMessage = $root.proto.Message.StickerSyncRMRMessage.toObject(message.stickerSyncRmrMessage, options);
|
|
60591
60591
|
if (options.oneofs)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichType.d.ts","sourceRoot":"","sources":["../../src/Types/RichType.js"],"names":[],"mappings":"AAAA,oCAA6B;AAS7B,qCAA8B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var CodeHighlightType;
|
|
2
|
+
(function (CodeHighlightType) {
|
|
3
|
+
CodeHighlightType[CodeHighlightType["DEFAULT"] = 0] = "DEFAULT";
|
|
4
|
+
CodeHighlightType[CodeHighlightType["KEYWORD"] = 1] = "KEYWORD";
|
|
5
|
+
CodeHighlightType[CodeHighlightType["METHOD"] = 2] = "METHOD";
|
|
6
|
+
CodeHighlightType[CodeHighlightType["STRING"] = 3] = "STRING";
|
|
7
|
+
CodeHighlightType[CodeHighlightType["NUMBER"] = 4] = "NUMBER";
|
|
8
|
+
CodeHighlightType[CodeHighlightType["COMMENT"] = 5] = "COMMENT";
|
|
9
|
+
})(CodeHighlightType || (CodeHighlightType = {}));
|
|
10
|
+
|
|
11
|
+
var RichSubMessageType;
|
|
12
|
+
(function (RichSubMessageType) {
|
|
13
|
+
RichSubMessageType[RichSubMessageType["UNKNOWN"] = 0] = "UNKNOWN";
|
|
14
|
+
RichSubMessageType[RichSubMessageType["GRID_IMAGE"] = 1] = "GRID_IMAGE";
|
|
15
|
+
RichSubMessageType[RichSubMessageType["TEXT"] = 2] = "TEXT";
|
|
16
|
+
RichSubMessageType[RichSubMessageType["INLINE_IMAGE"] = 3] = "INLINE_IMAGE";
|
|
17
|
+
RichSubMessageType[RichSubMessageType["TABLE"] = 4] = "TABLE";
|
|
18
|
+
RichSubMessageType[RichSubMessageType["CODE"] = 5] = "CODE";
|
|
19
|
+
RichSubMessageType[RichSubMessageType["DYNAMIC"] = 6] = "DYNAMIC";
|
|
20
|
+
RichSubMessageType[RichSubMessageType["MAP"] = 7] = "MAP";
|
|
21
|
+
RichSubMessageType[RichSubMessageType["LATEX"] = 8] = "LATEX";
|
|
22
|
+
RichSubMessageType[RichSubMessageType["CONTENT_ITEMS"] = 9] = "CONTENT_ITEMS";
|
|
23
|
+
})(RichSubMessageType || (RichSubMessageType = {}));
|
|
24
|
+
|
|
25
|
+
// Ekspor menggunakan format CommonJS agar bisa dibaca oleh require()
|
|
26
|
+
module.exports = {
|
|
27
|
+
CodeHighlightType,
|
|
28
|
+
RichSubMessageType
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=RichType.js.map
|
package/lib/Utils/messages.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
3
|
+
const { prepareRichResponseMessage } = require('./rich-message-utils');
|
|
2
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
6
|
};
|
|
@@ -299,7 +301,15 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
299
301
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
300
302
|
var _p, _q;
|
|
301
303
|
let m = {};
|
|
302
|
-
if (
|
|
304
|
+
if (
|
|
305
|
+
'code' in message ||
|
|
306
|
+
'links' in message ||
|
|
307
|
+
'table' in message ||
|
|
308
|
+
'richResponse' in message
|
|
309
|
+
) {
|
|
310
|
+
m = prepareRichResponseMessage(message);
|
|
311
|
+
}
|
|
312
|
+
else if ('text' in message) {
|
|
303
313
|
const extContent = { text: message.text };
|
|
304
314
|
let urlInfo = message.linkPreview;
|
|
305
315
|
if (typeof urlInfo === 'undefined') {
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lia@Changes 09-04-26 [WIP]
|
|
3
|
+
* Adds support for tables and code blocks with richResponseMessage (wrapped inside botForwardedMessage).
|
|
4
|
+
*
|
|
5
|
+
* If you use or copy this code, please credit my name or project. AND DO NOT CHANGE THIS NOTE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { getRandomValues, randomUUID } = require('crypto');
|
|
9
|
+
const { DONATE_URL, LEXER_REGEX } = require('../Defaults/index.js');
|
|
10
|
+
const { LANGUAGE_KEYWORDS } = require('../WABinary/constants.js');
|
|
11
|
+
const { CodeHighlightType, RichSubMessageType } = require('../Types/RichType.js');
|
|
12
|
+
const { proto } = require('../../WAProto/index.js');
|
|
13
|
+
const { unixTimestampSeconds } = require('./generics.js');
|
|
14
|
+
|
|
15
|
+
const NOOP = new Set([]);
|
|
16
|
+
|
|
17
|
+
const tokenizeCode = (code, language = 'javascript') => {
|
|
18
|
+
const keywords = LANGUAGE_KEYWORDS[language] || NOOP;
|
|
19
|
+
const blocks = [];
|
|
20
|
+
LEXER_REGEX.lastIndex = 0;
|
|
21
|
+
let match;
|
|
22
|
+
while ((match = LEXER_REGEX.exec(code)) !== null) {
|
|
23
|
+
if (match[1]) {
|
|
24
|
+
blocks.push({ highlightType: CodeHighlightType.COMMENT, codeContent: match[1] });
|
|
25
|
+
}
|
|
26
|
+
else if (match[2]) {
|
|
27
|
+
blocks.push({ highlightType: CodeHighlightType.STRING, codeContent: match[2] });
|
|
28
|
+
}
|
|
29
|
+
else if (match[3]) {
|
|
30
|
+
blocks.push({
|
|
31
|
+
highlightType: keywords.has(match[3]) ? CodeHighlightType.KEYWORD : CodeHighlightType.METHOD,
|
|
32
|
+
codeContent: match[3],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else if (match[4]) {
|
|
36
|
+
blocks.push({
|
|
37
|
+
highlightType: keywords.has(match[4]) ? CodeHighlightType.KEYWORD : CodeHighlightType.DEFAULT,
|
|
38
|
+
codeContent: match[4],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (match[5]) {
|
|
42
|
+
blocks.push({ highlightType: CodeHighlightType.NUMBER, codeContent: match[5] });
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
blocks.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: match[6] });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return blocks;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Lia@Changes 09-04-26 --- Inject buffer into unifiedResponse.data to support proper rendering of rich messages (ex: tables and code blocks)
|
|
52
|
+
const toUnified = (submessages, uuid) => ({
|
|
53
|
+
response_id: uuid || randomUUID(),
|
|
54
|
+
sections: submessages.map((submessage, index) => {
|
|
55
|
+
switch (submessage.messageType) {
|
|
56
|
+
case RichSubMessageType.CODE:
|
|
57
|
+
const codeMetadata = submessage.codeMetadata;
|
|
58
|
+
return {
|
|
59
|
+
view_model: {
|
|
60
|
+
primitive: {
|
|
61
|
+
language: codeMetadata.codeLanguage,
|
|
62
|
+
code_blocks: codeMetadata.codeBlocks.map((block) => ({ content: block.codeContent, type: CodeHighlightType[block.highlightType] })),
|
|
63
|
+
__typename: 'GenAICodeUXPrimitive'
|
|
64
|
+
},
|
|
65
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
case RichSubMessageType.CONTENT_ITEMS:
|
|
69
|
+
return {};
|
|
70
|
+
case RichSubMessageType.INLINE_IMAGE:
|
|
71
|
+
return {};
|
|
72
|
+
case RichSubMessageType.LATEX:
|
|
73
|
+
return {};
|
|
74
|
+
case RichSubMessageType.TABLE:
|
|
75
|
+
const tableMetadata = submessage.tableMetadata;
|
|
76
|
+
return {
|
|
77
|
+
view_model: {
|
|
78
|
+
primitive: {
|
|
79
|
+
title: tableMetadata.title,
|
|
80
|
+
rows: tableMetadata.rows.map((row) => ({
|
|
81
|
+
is_header: row.isHeading,
|
|
82
|
+
cells: row.items,
|
|
83
|
+
markdown_cells: row.items.map((item) => ({ text: item }))
|
|
84
|
+
})),
|
|
85
|
+
__typename: 'GenATableUXPrimitive'
|
|
86
|
+
},
|
|
87
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
case RichSubMessageType.TEXT:
|
|
91
|
+
return {
|
|
92
|
+
view_model: {
|
|
93
|
+
primitive: {
|
|
94
|
+
text: submessage.messageText,
|
|
95
|
+
inline_entities: submessage.inlineEntities || [],
|
|
96
|
+
__typename: 'GenAIMarkdownTextUXPrimitive'
|
|
97
|
+
},
|
|
98
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return submessage;
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const prepareRichResponseMessage = (content) => {
|
|
107
|
+
const { alignment, code, contentText, disclaimerText, footerText, headerText, imageText, inlineImage, inlineVideo, items, language, latex, links, noHeading, posts, products, suggested, richResponse, table, tapLinkUrl, title } = content;
|
|
108
|
+
let submessages = [];
|
|
109
|
+
if (Array.isArray(richResponse)) {
|
|
110
|
+
submessages = richResponse.map((submessage) => {
|
|
111
|
+
if (submessage.text) {
|
|
112
|
+
return {
|
|
113
|
+
messageType: RichSubMessageType.TEXT,
|
|
114
|
+
messageText: submessage.text,
|
|
115
|
+
inlineEntities: submessage.inlineEntities
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else if (submessage.code) {
|
|
119
|
+
return {
|
|
120
|
+
messageType: RichSubMessageType.CODE,
|
|
121
|
+
codeMetadata: {
|
|
122
|
+
codeLanguage: submessage.language,
|
|
123
|
+
codeBlocks: submessage.code
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else if (submessage.items) {
|
|
128
|
+
return {
|
|
129
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
130
|
+
contentItemsMetadata: {
|
|
131
|
+
itemsMetadata: submessage.items,
|
|
132
|
+
contentType: proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
else if (submessage.inlineImage) {
|
|
137
|
+
return {
|
|
138
|
+
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
139
|
+
imageMetadata: {
|
|
140
|
+
imageUrl: submessage.inlineImage,
|
|
141
|
+
imageText: submessage.imageText,
|
|
142
|
+
alignment: submessage.alignment,
|
|
143
|
+
tapLinkUrl: submessage.tapLinkUrl
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
else if (submessage.inlineVideo) {
|
|
148
|
+
return {
|
|
149
|
+
messageType: RichSubMessageType.TEXT,
|
|
150
|
+
messageText: 'INLINE_VIDEO'
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
else if (submessage.latex) {
|
|
154
|
+
return {
|
|
155
|
+
messageType: RichSubMessageType.LATEX,
|
|
156
|
+
latexMetadata: {
|
|
157
|
+
text: submessage.text,
|
|
158
|
+
expressions: submessage.latex
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
else if (submessage.posts) {
|
|
163
|
+
return {
|
|
164
|
+
messageType: RichSubMessageType.TEXT,
|
|
165
|
+
messageText: 'POSTS'
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
else if (submessage.products) {
|
|
169
|
+
return {
|
|
170
|
+
messageType: RichSubMessageType.TEXT,
|
|
171
|
+
messageText: 'PRODUCTS'
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
else if (submessage.suggested) {
|
|
175
|
+
return {
|
|
176
|
+
messageType: RichSubMessageType.TEXT,
|
|
177
|
+
messageText: 'SUGGESTED_PROMPT'
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
else if (submessage.table) {
|
|
181
|
+
return {
|
|
182
|
+
messageType: RichSubMessageType.TABLE,
|
|
183
|
+
tableMetadata: {
|
|
184
|
+
title: submessage.title,
|
|
185
|
+
rows: submessage.table
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return submessage;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
if (headerText) {
|
|
194
|
+
submessages.push({
|
|
195
|
+
messageType: RichSubMessageType.TEXT,
|
|
196
|
+
messageText: headerText
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (contentText) {
|
|
200
|
+
submessages.push({
|
|
201
|
+
messageType: RichSubMessageType.TEXT,
|
|
202
|
+
messageText: contentText
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (code) {
|
|
206
|
+
let selectedLanguage = language || 'javascript';
|
|
207
|
+
submessages.push({
|
|
208
|
+
messageType: RichSubMessageType.CODE,
|
|
209
|
+
codeMetadata: {
|
|
210
|
+
codeLanguage: selectedLanguage,
|
|
211
|
+
codeBlocks: tokenizeCode(code, selectedLanguage)
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (items) {
|
|
216
|
+
submessages.push({
|
|
217
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
218
|
+
contentItemsMetadata: {
|
|
219
|
+
itemsMetadata: items,
|
|
220
|
+
contentType: proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (inlineImage) {
|
|
225
|
+
submessages.push({
|
|
226
|
+
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
227
|
+
imageMetadata: {
|
|
228
|
+
imageUrl: inlineImage,
|
|
229
|
+
imageText,
|
|
230
|
+
alignment,
|
|
231
|
+
tapLinkUrl
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (inlineVideo) {
|
|
236
|
+
submessages.push({
|
|
237
|
+
messageType: RichSubMessageType.TEXT,
|
|
238
|
+
messageText: 'INLINE_VIDEO'
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
if (latex) {
|
|
242
|
+
submessages.push({
|
|
243
|
+
messageType: RichSubMessageType.LATEX,
|
|
244
|
+
latexMetadata: {
|
|
245
|
+
text,
|
|
246
|
+
expressions: latex
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
if (links) {
|
|
251
|
+
links.forEach((linkField, index) => {
|
|
252
|
+
const prefix = 'SS_' + index;
|
|
253
|
+
const url = linkField.url || DONATE_URL;
|
|
254
|
+
const sources = linkField.sources?.map((sourceField) => ({
|
|
255
|
+
source_type: 'THIRD_PARTY',
|
|
256
|
+
source_display_name: sourceField.displayName || 'Donate',
|
|
257
|
+
source_subtitle: sourceField.subtitle || 'Saweria',
|
|
258
|
+
source_url: sourceField.url || url
|
|
259
|
+
}));
|
|
260
|
+
submessages.push({
|
|
261
|
+
messageType: RichSubMessageType.TEXT,
|
|
262
|
+
messageText: linkField.text + ` {{${prefix}}}¹{{/${prefix}}} `,
|
|
263
|
+
inlineEntities: [{
|
|
264
|
+
key: prefix,
|
|
265
|
+
metadata: {
|
|
266
|
+
reference_id: index + 1,
|
|
267
|
+
reference_url: url,
|
|
268
|
+
reference_title: linkField.title || 'For Donation via Saweria',
|
|
269
|
+
reference_display_name: linkField.displayName || 'Donation',
|
|
270
|
+
sources: sources || [],
|
|
271
|
+
__typename: 'GenAISearchCitationItem'
|
|
272
|
+
}
|
|
273
|
+
}]
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
if (posts) {
|
|
278
|
+
submessages.push({
|
|
279
|
+
messageType: RichSubMessageType.TEXT,
|
|
280
|
+
messageText: 'POSTS'
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (products) {
|
|
284
|
+
submessages.push({
|
|
285
|
+
messageType: RichSubMessageType.TEXT,
|
|
286
|
+
messageText: 'PRODUCTS'
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
if (suggested) {
|
|
290
|
+
submessages.push({
|
|
291
|
+
messageType: RichSubMessageType.TEXT,
|
|
292
|
+
messageText: 'SUGGESTED_PROMPT'
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (table) {
|
|
296
|
+
submessages.push({
|
|
297
|
+
messageType: RichSubMessageType.TABLE,
|
|
298
|
+
tableMetadata: {
|
|
299
|
+
title,
|
|
300
|
+
rows: table.map((items, index) => ({
|
|
301
|
+
isHeading: !noHeading && index == 0,
|
|
302
|
+
items
|
|
303
|
+
}))
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
if (footerText) {
|
|
308
|
+
submessages.push({
|
|
309
|
+
messageType: RichSubMessageType.TEXT,
|
|
310
|
+
messageText: footerText
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const uuid = randomUUID();
|
|
315
|
+
const unified = toUnified(submessages, uuid);
|
|
316
|
+
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
317
|
+
submessages,
|
|
318
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
319
|
+
unifiedResponse: {
|
|
320
|
+
data: Buffer.from(JSON.stringify(unified)) // Lia@Note 25-04-26 --- Expects "ArrayBufferLike"
|
|
321
|
+
},
|
|
322
|
+
contextInfo: {
|
|
323
|
+
isForwarded: true,
|
|
324
|
+
forwardingScore: 1,
|
|
325
|
+
forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
|
|
326
|
+
forwardOrigin: 4
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
const message = wrapToBotForwardedMessage(richResponseMessage);
|
|
330
|
+
const botMetadata = message.messageContextInfo.botMetadata;
|
|
331
|
+
// Lia@Note 13-05-26 --- Add disclaimer text on richResponseMessage
|
|
332
|
+
if (disclaimerText) {
|
|
333
|
+
botMetadata.messageDisclaimerText = disclaimerText;
|
|
334
|
+
}
|
|
335
|
+
// Lia@Note 15-05-26 --- Add responseId from unified directly to botMetadata
|
|
336
|
+
botMetadata.botResponseId = uuid;
|
|
337
|
+
return message;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// Lia@Note 17-04-26 --- signature and certificateChain for proofs[] field
|
|
341
|
+
const botMetadataSignature = () => {
|
|
342
|
+
const signature = new Uint8Array(64);
|
|
343
|
+
getRandomValues(signature);
|
|
344
|
+
return signature;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const botMetadataCertificate = (length = 685) => {
|
|
348
|
+
const certificate = new Uint8Array(length);
|
|
349
|
+
certificate[0] = 48;
|
|
350
|
+
certificate[1] = 130;
|
|
351
|
+
getRandomValues(certificate.subarray(2));
|
|
352
|
+
return certificate;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const wrapToBotForwardedMessage = (richResponseMessage) => ({
|
|
356
|
+
messageContextInfo: {
|
|
357
|
+
botMetadata: {
|
|
358
|
+
// Lia@Note 09-04-26 --- TODO: Fill verificationMetadata field
|
|
359
|
+
verificationMetadata: {
|
|
360
|
+
proofs: [
|
|
361
|
+
{
|
|
362
|
+
certificateChain: [
|
|
363
|
+
botMetadataCertificate(),
|
|
364
|
+
botMetadataCertificate(892)
|
|
365
|
+
],
|
|
366
|
+
version: 1,
|
|
367
|
+
useCase: 1,
|
|
368
|
+
signature: botMetadataSignature()
|
|
369
|
+
}
|
|
370
|
+
]
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
botForwardedMessage: {
|
|
375
|
+
message: { richResponseMessage }
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// Ekspor semua fungsi eksternal menggunakan CommonJS
|
|
380
|
+
module.exports = {
|
|
381
|
+
tokenizeCode,
|
|
382
|
+
toUnified,
|
|
383
|
+
prepareRichResponseMessage,
|
|
384
|
+
botMetadataSignature,
|
|
385
|
+
botMetadataCertificate,
|
|
386
|
+
wrapToBotForwardedMessage
|
|
387
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubedsockets/baileys",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.9",
|
|
4
4
|
"description": "@ubedsockets/baileys,baileys A high-performance WhatsApp Web API wrapper based on Baileys, optimized for bot developers with integrated utility scrapers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|