@badzz88/baileys 8.5.7 → 8.5.8
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/README.md +337 -1055
- package/WAProto/WAProto.proto +284 -264
- package/WAProto/index.js +5 -5
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +130 -187
- package/lib/Signal/Group/ciphertext-message.js +11 -14
- package/lib/Signal/Group/group-session-builder.js +29 -91
- package/lib/Signal/Group/group_cipher.js +81 -88
- package/lib/Signal/Group/index.js +12 -136
- package/lib/Signal/Group/keyhelper.js +15 -70
- package/lib/Signal/Group/sender-chain-key.js +25 -31
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
- package/lib/Signal/Group/sender-key-message.js +65 -68
- package/lib/Signal/Group/sender-key-name.js +41 -43
- package/lib/Signal/Group/sender-key-record.js +40 -43
- package/lib/Signal/Group/sender-key-state.js +83 -96
- package/lib/Signal/Group/sender-message-key.js +25 -29
- package/lib/Signal/libsignal.js +425 -453
- package/lib/Signal/lid-mapping.js +276 -259
- package/lib/Socket/Client/index.js +3 -30
- package/lib/Socket/Client/types.js +10 -12
- package/lib/Socket/Client/websocket.js +53 -61
- package/lib/Socket/business.js +379 -422
- package/lib/Socket/chats.js +1193 -1816
- package/lib/Socket/communities.js +431 -549
- package/lib/Socket/graphql.js +672 -612
- package/lib/Socket/groups.js +374 -764
- package/lib/Socket/index.js +17 -38
- package/lib/Socket/interop.js +417 -503
- package/lib/Socket/messages-recv.js +1915 -2441
- package/lib/Socket/messages-send.js +1213 -1630
- package/lib/Socket/mex.js +9 -15
- package/lib/Socket/newsletter.js +747 -808
- package/lib/Socket/privacy.js +310 -441
- package/lib/Socket/socket.js +1025 -1022
- package/lib/Socket/username.js +8 -15
- package/lib/Store/index.js +10 -36
- package/lib/Store/make-cache-manager-store.js +80 -85
- package/lib/Store/make-in-memory-store.js +231 -591
- package/lib/Store/make-ordered-dictionary.js +72 -78
- package/lib/Store/object-repository.js +28 -25
- package/lib/Types/Auth.js +2 -38
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +11 -95
- package/lib/Types/Mex.js +111 -112
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -70
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +26 -55
- package/lib/Utils/auth-utils.js +288 -292
- package/lib/Utils/browser-utils.js +47 -113
- package/lib/Utils/business.js +224 -240
- package/lib/Utils/chat-utils.js +869 -1205
- package/lib/Utils/companion-reg-client-utils.js +34 -41
- package/lib/Utils/crypto.js +107 -144
- package/lib/Utils/decode-wa-message.js +308 -518
- package/lib/Utils/event-buffer.js +611 -596
- package/lib/Utils/generics.js +355 -515
- package/lib/Utils/history.js +134 -244
- package/lib/Utils/identity-change-handler.js +49 -51
- package/lib/Utils/index.js +23 -57
- package/lib/Utils/link-preview.js +77 -135
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.js +6 -37
- package/lib/Utils/make-mutex.js +33 -36
- package/lib/Utils/message-composer.js +233 -439
- package/lib/Utils/message-retry-manager.js +260 -265
- package/lib/Utils/messages-media.js +829 -855
- package/lib/Utils/messages.js +961 -2528
- package/lib/Utils/noise-handler.js +200 -195
- package/lib/Utils/offline-node-processor.js +33 -35
- package/lib/Utils/pre-key-manager.js +102 -103
- package/lib/Utils/process-message.js +560 -978
- package/lib/Utils/reporting-utils.js +253 -257
- package/lib/Utils/signal.js +195 -218
- package/lib/Utils/stanza-ack.js +29 -31
- package/lib/Utils/sticker.js +109 -144
- package/lib/Utils/sync-action-utils.js +45 -50
- package/lib/Utils/tc-token-utils.js +139 -137
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +202 -218
- package/lib/WABinary/constants.js +1299 -1302
- package/lib/WABinary/decode.js +262 -343
- package/lib/WABinary/encode.js +4 -12
- package/lib/WABinary/generic-utils.js +187 -223
- package/lib/WABinary/index.js +6 -33
- package/lib/WABinary/jid-utils.js +88 -351
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -12
- package/lib/WAM/constants.js +22853 -39486
- package/lib/WAM/encode.js +140 -132
- package/lib/WAM/index.js +4 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
- package/lib/WAUSync/Protocols/index.js +12 -39
- package/lib/WAUSync/USyncQuery.js +67 -49
- package/lib/WAUSync/USyncUser.js +11 -5
- package/lib/WAUSync/index.js +3 -31
- package/lib/index.js +15 -48
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/text-router.js +0 -83
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/antiban.js +0 -4637
|
@@ -1,479 +1,273 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { proto } = require('../../WAProto/index.js')
|
|
4
|
-
const { generateMessageIDV2 } = require('./generics.js')
|
|
1
|
+
import { proto } from '../../WAProto/index.js'
|
|
2
|
+
import { generateMessageIDV2 } from './generics.js'
|
|
5
3
|
|
|
6
4
|
const JS_KEYWORDS = new Set([
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
'let',
|
|
14
|
-
'var',
|
|
15
|
-
'function',
|
|
16
|
-
'class',
|
|
17
|
-
'extends',
|
|
18
|
-
'new',
|
|
19
|
-
'return',
|
|
20
|
-
'if',
|
|
21
|
-
'else',
|
|
22
|
-
'for',
|
|
23
|
-
'while',
|
|
24
|
-
'do',
|
|
25
|
-
'switch',
|
|
26
|
-
'case',
|
|
27
|
-
'break',
|
|
28
|
-
'continue',
|
|
29
|
-
'try',
|
|
30
|
-
'catch',
|
|
31
|
-
'finally',
|
|
32
|
-
'throw',
|
|
33
|
-
'async',
|
|
34
|
-
'await',
|
|
35
|
-
'yield',
|
|
36
|
-
'typeof',
|
|
37
|
-
'instanceof',
|
|
38
|
-
'in',
|
|
39
|
-
'of',
|
|
40
|
-
'delete',
|
|
41
|
-
'void',
|
|
42
|
-
'true',
|
|
43
|
-
'false',
|
|
44
|
-
'null',
|
|
45
|
-
'undefined',
|
|
46
|
-
'NaN',
|
|
47
|
-
'Infinity',
|
|
48
|
-
'this',
|
|
49
|
-
'super',
|
|
50
|
-
'static',
|
|
51
|
-
'get',
|
|
52
|
-
'set',
|
|
53
|
-
'debugger',
|
|
54
|
-
'with'
|
|
5
|
+
'import', 'export', 'from', 'default', 'as', 'const', 'let', 'var',
|
|
6
|
+
'function', 'class', 'extends', 'new', 'return', 'if', 'else', 'for',
|
|
7
|
+
'while', 'do', 'switch', 'case', 'break', 'continue', 'try', 'catch',
|
|
8
|
+
'finally', 'throw', 'async', 'await', 'yield', 'typeof', 'instanceof',
|
|
9
|
+
'in', 'of', 'delete', 'void', 'true', 'false', 'null', 'undefined',
|
|
10
|
+
'NaN', 'Infinity', 'this', 'super', 'static', 'get', 'set', 'debugger', 'with'
|
|
55
11
|
])
|
|
56
12
|
|
|
57
13
|
const PYTHON_KEYWORDS = new Set([
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'return',
|
|
64
|
-
'if',
|
|
65
|
-
'elif',
|
|
66
|
-
'else',
|
|
67
|
-
'for',
|
|
68
|
-
'while',
|
|
69
|
-
'break',
|
|
70
|
-
'continue',
|
|
71
|
-
'try',
|
|
72
|
-
'except',
|
|
73
|
-
'finally',
|
|
74
|
-
'raise',
|
|
75
|
-
'with',
|
|
76
|
-
'yield',
|
|
77
|
-
'lambda',
|
|
78
|
-
'pass',
|
|
79
|
-
'del',
|
|
80
|
-
'global',
|
|
81
|
-
'nonlocal',
|
|
82
|
-
'assert',
|
|
83
|
-
'True',
|
|
84
|
-
'False',
|
|
85
|
-
'None',
|
|
86
|
-
'and',
|
|
87
|
-
'or',
|
|
88
|
-
'not',
|
|
89
|
-
'in',
|
|
90
|
-
'is',
|
|
91
|
-
'async',
|
|
92
|
-
'await',
|
|
93
|
-
'self',
|
|
94
|
-
'print'
|
|
14
|
+
'import', 'from', 'as', 'def', 'class', 'return', 'if', 'elif', 'else',
|
|
15
|
+
'for', 'while', 'break', 'continue', 'try', 'except', 'finally', 'raise',
|
|
16
|
+
'with', 'yield', 'lambda', 'pass', 'del', 'global', 'nonlocal', 'assert',
|
|
17
|
+
'True', 'False', 'None', 'and', 'or', 'not', 'in', 'is', 'async', 'await',
|
|
18
|
+
'self', 'print'
|
|
95
19
|
])
|
|
96
20
|
|
|
97
21
|
const LANGUAGE_KEYWORDS = {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
22
|
+
javascript: JS_KEYWORDS,
|
|
23
|
+
typescript: JS_KEYWORDS,
|
|
24
|
+
js: JS_KEYWORDS,
|
|
25
|
+
ts: JS_KEYWORDS,
|
|
26
|
+
python: PYTHON_KEYWORDS,
|
|
27
|
+
py: PYTHON_KEYWORDS
|
|
104
28
|
}
|
|
105
29
|
|
|
106
|
-
var CodeHighlightType
|
|
30
|
+
export var CodeHighlightType
|
|
107
31
|
;(function (CodeHighlightType) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
32
|
+
CodeHighlightType[(CodeHighlightType['DEFAULT'] = 0)] = 'DEFAULT'
|
|
33
|
+
CodeHighlightType[(CodeHighlightType['KEYWORD'] = 1)] = 'KEYWORD'
|
|
34
|
+
CodeHighlightType[(CodeHighlightType['METHOD'] = 2)] = 'METHOD'
|
|
35
|
+
CodeHighlightType[(CodeHighlightType['STRING'] = 3)] = 'STRING'
|
|
36
|
+
CodeHighlightType[(CodeHighlightType['NUMBER'] = 4)] = 'NUMBER'
|
|
37
|
+
CodeHighlightType[(CodeHighlightType['COMMENT'] = 5)] = 'COMMENT'
|
|
114
38
|
})(CodeHighlightType || (CodeHighlightType = {}))
|
|
115
39
|
|
|
116
|
-
var RichSubMessageType
|
|
40
|
+
export var RichSubMessageType
|
|
117
41
|
;(function (RichSubMessageType) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
42
|
+
RichSubMessageType[(RichSubMessageType['UNKNOWN'] = 0)] = 'UNKNOWN'
|
|
43
|
+
RichSubMessageType[(RichSubMessageType['GRID_IMAGE'] = 1)] = 'GRID_IMAGE'
|
|
44
|
+
RichSubMessageType[(RichSubMessageType['TEXT'] = 2)] = 'TEXT'
|
|
45
|
+
RichSubMessageType[(RichSubMessageType['INLINE_IMAGE'] = 3)] = 'INLINE_IMAGE'
|
|
46
|
+
RichSubMessageType[(RichSubMessageType['TABLE'] = 4)] = 'TABLE'
|
|
47
|
+
RichSubMessageType[(RichSubMessageType['CODE'] = 5)] = 'CODE'
|
|
48
|
+
RichSubMessageType[(RichSubMessageType['DYNAMIC'] = 6)] = 'DYNAMIC'
|
|
49
|
+
RichSubMessageType[(RichSubMessageType['MAP'] = 7)] = 'MAP'
|
|
50
|
+
RichSubMessageType[(RichSubMessageType['LATEX'] = 8)] = 'LATEX'
|
|
51
|
+
RichSubMessageType[(RichSubMessageType['CONTENT_ITEMS'] = 9)] = 'CONTENT_ITEMS'
|
|
128
52
|
})(RichSubMessageType || (RichSubMessageType = {}))
|
|
129
53
|
|
|
130
|
-
const tokenizeCode = (codeStr, language = 'javascript') => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
} else {
|
|
194
|
-
tokens.push({
|
|
195
|
-
highlightType: CodeHighlightType.DEFAULT,
|
|
196
|
-
codeContent: val
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (tokens.length === 0) {
|
|
201
|
-
blocks.push({
|
|
202
|
-
highlightType: CodeHighlightType.DEFAULT,
|
|
203
|
-
codeContent: line + nl
|
|
204
|
-
})
|
|
205
|
-
continue
|
|
206
|
-
}
|
|
207
|
-
const merged = []
|
|
208
|
-
for (const t of tokens) {
|
|
209
|
-
const prev = merged.length > 0 ? merged[merged.length - 1] : undefined
|
|
210
|
-
if (prev && prev.highlightType === t.highlightType) {
|
|
211
|
-
prev.codeContent += t.codeContent
|
|
212
|
-
} else {
|
|
213
|
-
merged.push({ ...t })
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (merged.length > 0) {
|
|
217
|
-
merged[merged.length - 1].codeContent += nl
|
|
218
|
-
}
|
|
219
|
-
blocks.push(...merged)
|
|
220
|
-
}
|
|
221
|
-
return blocks
|
|
54
|
+
export const tokenizeCode = (codeStr, language = 'javascript') => {
|
|
55
|
+
const keywords = LANGUAGE_KEYWORDS[language] || JS_KEYWORDS
|
|
56
|
+
const blocks = []
|
|
57
|
+
const lines = codeStr.split('\n')
|
|
58
|
+
for (let li = 0; li < lines.length; li++) {
|
|
59
|
+
const line = lines[li]
|
|
60
|
+
const isLast = li === lines.length - 1
|
|
61
|
+
const nl = isLast? '' : '\n'
|
|
62
|
+
if (!line.trim()) {
|
|
63
|
+
blocks.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: line + nl })
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
if (line.trim().startsWith('//') || line.trim().startsWith('#')) {
|
|
67
|
+
blocks.push({ highlightType: CodeHighlightType.COMMENT, codeContent: line + nl })
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
const regex = /(\/\/.*$|#.*$)|(["'`](?:[^"'`\\]|\\.)*["'`])|(\b\d+(?:\.\d+)?\b)|(\b[a-zA-Z_$][\w$]*\b)|([^\s\w$"'`]+)|(\s+)/g
|
|
71
|
+
let match
|
|
72
|
+
const tokens = []
|
|
73
|
+
while ((match = regex.exec(line))!== null) {
|
|
74
|
+
const val = match[0]
|
|
75
|
+
if (match[1]) {
|
|
76
|
+
tokens.push({ highlightType: CodeHighlightType.COMMENT, codeContent: val })
|
|
77
|
+
} else if (match[2]) {
|
|
78
|
+
tokens.push({ highlightType: CodeHighlightType.STRING, codeContent: val })
|
|
79
|
+
} else if (match[3]) {
|
|
80
|
+
tokens.push({ highlightType: CodeHighlightType.NUMBER, codeContent: val })
|
|
81
|
+
} else if (match[4]) {
|
|
82
|
+
if (keywords.has(val)) {
|
|
83
|
+
tokens.push({ highlightType: CodeHighlightType.KEYWORD, codeContent: val })
|
|
84
|
+
} else {
|
|
85
|
+
const after = line.slice(regex.lastIndex).trimStart()
|
|
86
|
+
if (after.startsWith('(')) {
|
|
87
|
+
tokens.push({ highlightType: CodeHighlightType.METHOD, codeContent: val })
|
|
88
|
+
} else {
|
|
89
|
+
tokens.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: val })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
tokens.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: val })
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (tokens.length === 0) {
|
|
97
|
+
blocks.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: line + nl })
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
const merged = []
|
|
101
|
+
for (const t of tokens) {
|
|
102
|
+
const prev = merged.length > 0? merged[merged.length - 1] : undefined
|
|
103
|
+
if (prev && prev.highlightType === t.highlightType) {
|
|
104
|
+
prev.codeContent += t.codeContent
|
|
105
|
+
} else {
|
|
106
|
+
merged.push({...t })
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (merged.length > 0) {
|
|
110
|
+
merged[merged.length - 1].codeContent += nl
|
|
111
|
+
}
|
|
112
|
+
blocks.push(...merged)
|
|
113
|
+
}
|
|
114
|
+
return blocks
|
|
222
115
|
}
|
|
223
116
|
|
|
224
|
-
const buildRichContextInfo = (quoted, options) => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
117
|
+
export const buildRichContextInfo = (quoted, options) => {
|
|
118
|
+
const ctxInfo = {
|
|
119
|
+
forwardingScore: 1,
|
|
120
|
+
isForwarded: true,
|
|
121
|
+
forwardedAiBotMessageInfo: { botJid: options?.botJid? options.botJid : '867051314767696@bot' },
|
|
122
|
+
forwardOrigin: 4,
|
|
123
|
+
...(options?.mentions? { mentionedJid: options.mentions } : {})
|
|
124
|
+
}
|
|
125
|
+
if (quoted?.key) {
|
|
126
|
+
ctxInfo.stanzaId = quoted.key.id
|
|
127
|
+
ctxInfo.participant = quoted.key.participant || quoted.sender || quoted.key.remoteJid
|
|
128
|
+
ctxInfo.quotedMessage = quoted.message
|
|
129
|
+
}
|
|
130
|
+
return ctxInfo
|
|
238
131
|
}
|
|
239
132
|
|
|
240
|
-
const buildBotForwardedMessage = (submessages, contextInfo, unifiedResponse) => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
botForwardedMessage: {
|
|
251
|
-
message: {
|
|
252
|
-
richResponseMessage: richResponse
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
133
|
+
export const buildBotForwardedMessage = (submessages, contextInfo, unifiedResponse) => {
|
|
134
|
+
const richResponse = { messageType: 1, submessages, contextInfo }
|
|
135
|
+
if (unifiedResponse) {
|
|
136
|
+
richResponse.unifiedResponse = unifiedResponse
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
botForwardedMessage: {
|
|
140
|
+
message: { richResponseMessage: richResponse }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
256
143
|
}
|
|
257
144
|
|
|
258
|
-
const generateTableContent = (title, headers, rows, quoted, options = {}) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
tableMetadata: { title, rows: tableRows }
|
|
268
|
-
})
|
|
269
|
-
if (footer) {
|
|
270
|
-
submessages.push({ messageType: 2, messageText: footer })
|
|
271
|
-
}
|
|
272
|
-
const ctxInfo = buildRichContextInfo(quoted)
|
|
273
|
-
return {
|
|
274
|
-
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
275
|
-
messageId: generateMessageIDV2()
|
|
276
|
-
}
|
|
145
|
+
export const generateTableContent = (title, headers, rows, quoted, options = {}) => {
|
|
146
|
+
const { footer, headerText } = options
|
|
147
|
+
const tableRows = [{ items: headers, isHeading: true },...rows.map(row => ({ items: row.map(String) }))]
|
|
148
|
+
const submessages = []
|
|
149
|
+
if (headerText) submessages.push({ messageType: 2, messageText: headerText })
|
|
150
|
+
submessages.push({ messageType: 4, tableMetadata: { title, rows: tableRows } })
|
|
151
|
+
if (footer) submessages.push({ messageType: 2, messageText: footer })
|
|
152
|
+
const ctxInfo = buildRichContextInfo(quoted)
|
|
153
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: generateMessageIDV2() }
|
|
277
154
|
}
|
|
278
155
|
|
|
279
|
-
const generateListContent = (title, items, quoted, options = {}) => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
tableMetadata: { title, rows: tableRows }
|
|
291
|
-
})
|
|
292
|
-
if (footer) {
|
|
293
|
-
submessages.push({ messageType: 2, messageText: footer })
|
|
294
|
-
}
|
|
295
|
-
const ctxInfo = buildRichContextInfo(quoted)
|
|
296
|
-
return {
|
|
297
|
-
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
298
|
-
messageId: generateMessageIDV2()
|
|
299
|
-
}
|
|
156
|
+
export const generateListContent = (title, items, quoted, options = {}) => {
|
|
157
|
+
const { footer, headerText } = options
|
|
158
|
+
const tableRows = items.map(item => ({
|
|
159
|
+
items: Array.isArray(item)? item.map(String) : [String(item)]
|
|
160
|
+
}))
|
|
161
|
+
const submessages = []
|
|
162
|
+
if (headerText) submessages.push({ messageType: 2, messageText: headerText })
|
|
163
|
+
submessages.push({ messageType: 4, tableMetadata: { title, rows: tableRows } })
|
|
164
|
+
if (footer) submessages.push({ messageType: 2, messageText: footer })
|
|
165
|
+
const ctxInfo = buildRichContextInfo(quoted)
|
|
166
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: generateMessageIDV2() }
|
|
300
167
|
}
|
|
301
168
|
|
|
302
|
-
const generateCodeBlockContent = (code, quoted, options = {}) => {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
})
|
|
315
|
-
if (footer) {
|
|
316
|
-
submessages.push({ messageType: 2, messageText: footer })
|
|
317
|
-
}
|
|
318
|
-
const ctxInfo = buildRichContextInfo(quoted)
|
|
319
|
-
return {
|
|
320
|
-
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
321
|
-
messageId: generateMessageIDV2()
|
|
322
|
-
}
|
|
169
|
+
export const generateCodeBlockContent = (code, quoted, options = {}) => {
|
|
170
|
+
const { title, footer, language = 'javascript' } = options
|
|
171
|
+
const submessages = []
|
|
172
|
+
if (title) submessages.push({ messageType: 2, messageText: title })
|
|
173
|
+
submessages.push({
|
|
174
|
+
messageType: 5,
|
|
175
|
+
codeMetadata: { codeLanguage: language, codeBlocks: tokenizeCode(code, language) }
|
|
176
|
+
})
|
|
177
|
+
if (footer) submessages.push({ messageType: 2, messageText: footer })
|
|
178
|
+
const ctxInfo = buildRichContextInfo(quoted)
|
|
179
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: generateMessageIDV2() }
|
|
323
180
|
}
|
|
324
181
|
|
|
325
|
-
const generateLatexContent = (quoted, options) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
latexMetadata: {
|
|
348
|
-
text: text || '',
|
|
349
|
-
expressions: latexExpressions
|
|
350
|
-
}
|
|
351
|
-
})
|
|
352
|
-
if (footer) {
|
|
353
|
-
submessages.push({ messageType: 2, messageText: footer })
|
|
354
|
-
}
|
|
355
|
-
const ctxInfo = buildRichContextInfo(quoted)
|
|
356
|
-
return {
|
|
357
|
-
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
358
|
-
messageId: generateMessageIDV2()
|
|
359
|
-
}
|
|
182
|
+
export const generateLatexContent = (quoted, options) => {
|
|
183
|
+
const { text, expressions, headerText, footer } = options
|
|
184
|
+
const submessages = []
|
|
185
|
+
if (headerText) submessages.push({ messageType: 2, messageText: headerText })
|
|
186
|
+
const latexExpressions = expressions.map(expr => {
|
|
187
|
+
const entry = {
|
|
188
|
+
latexExpression: expr.latexExpression,
|
|
189
|
+
url: expr.url,
|
|
190
|
+
width: expr.width,
|
|
191
|
+
height: expr.height
|
|
192
|
+
}
|
|
193
|
+
if (expr.fontHeight!== undefined) entry.fontHeight = expr.fontHeight
|
|
194
|
+
if (expr.imageTopPadding!== undefined) entry.imageTopPadding = expr.imageTopPadding
|
|
195
|
+
if (expr.imageLeadingPadding!== undefined) entry.imageLeadingPadding = expr.imageLeadingPadding
|
|
196
|
+
if (expr.imageBottomPadding!== undefined) entry.imageBottomPadding = expr.imageBottomPadding
|
|
197
|
+
if (expr.imageTrailingPadding!== undefined) entry.imageTrailingPadding = expr.imageTrailingPadding
|
|
198
|
+
return entry
|
|
199
|
+
})
|
|
200
|
+
submessages.push({ messageType: 8, latexMetadata: { text: text || '', expressions: latexExpressions } })
|
|
201
|
+
if (footer) submessages.push({ messageType: 2, messageText: footer })
|
|
202
|
+
const ctxInfo = buildRichContextInfo(quoted)
|
|
203
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: generateMessageIDV2() }
|
|
360
204
|
}
|
|
361
205
|
|
|
362
|
-
const generateLatexImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
})
|
|
380
|
-
)
|
|
381
|
-
submessages.push({
|
|
382
|
-
messageType: 8,
|
|
383
|
-
latexMetadata: {
|
|
384
|
-
text: text || '',
|
|
385
|
-
expressions: latexExpressions
|
|
386
|
-
}
|
|
387
|
-
})
|
|
388
|
-
if (footer) {
|
|
389
|
-
submessages.push({ messageType: 2, messageText: footer })
|
|
390
|
-
}
|
|
391
|
-
const ctxInfo = buildRichContextInfo(quoted)
|
|
392
|
-
return {
|
|
393
|
-
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
394
|
-
messageId: generateMessageIDV2()
|
|
395
|
-
}
|
|
206
|
+
export const generateLatexImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
207
|
+
const { text, expressions, headerText, footer } = options
|
|
208
|
+
const submessages = []
|
|
209
|
+
if (headerText) submessages.push({ messageType: 2, messageText: headerText })
|
|
210
|
+
const latexExpressions = await Promise.all(
|
|
211
|
+
expressions.map(async expr => {
|
|
212
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression)
|
|
213
|
+
const uploadResult = await uploadFn(buffer, 'image')
|
|
214
|
+
const imageUrl = uploadResult.url || uploadResult.directPath
|
|
215
|
+
return { latexExpression: expr.latexExpression, url: imageUrl, width, height }
|
|
216
|
+
})
|
|
217
|
+
)
|
|
218
|
+
submessages.push({ messageType: 8, latexMetadata: { text: text || '', expressions: latexExpressions } })
|
|
219
|
+
if (footer) submessages.push({ messageType: 2, messageText: footer })
|
|
220
|
+
const ctxInfo = buildRichContextInfo(quoted)
|
|
221
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: generateMessageIDV2() }
|
|
396
222
|
}
|
|
397
223
|
|
|
398
|
-
const generateLatexInlineImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
alignment: 2
|
|
420
|
-
}
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
if (footer) {
|
|
424
|
-
submessages.push({ messageType: 2, messageText: footer })
|
|
425
|
-
}
|
|
426
|
-
const ctxInfo = buildRichContextInfo(quoted)
|
|
427
|
-
return {
|
|
428
|
-
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
429
|
-
messageId: generateMessageIDV2()
|
|
430
|
-
}
|
|
224
|
+
export const generateLatexInlineImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
225
|
+
const { text, expressions, headerText, footer } = options
|
|
226
|
+
const submessages = []
|
|
227
|
+
if (headerText) submessages.push({ messageType: 2, messageText: headerText })
|
|
228
|
+
if (text) submessages.push({ messageType: 2, messageText: text })
|
|
229
|
+
for (const expr of expressions) {
|
|
230
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression)
|
|
231
|
+
const uploadResult = await uploadFn(buffer, 'image')
|
|
232
|
+
const imageUrl = uploadResult.url || uploadResult.directPath
|
|
233
|
+
submessages.push({
|
|
234
|
+
messageType: 3,
|
|
235
|
+
imageMetadata: {
|
|
236
|
+
imageUrl: { imagePreviewUrl: imageUrl, imageHighResUrl: imageUrl },
|
|
237
|
+
imageText: expr.latexExpression,
|
|
238
|
+
alignment: 2
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
if (footer) submessages.push({ messageType: 2, messageText: footer })
|
|
243
|
+
const ctxInfo = buildRichContextInfo(quoted)
|
|
244
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: generateMessageIDV2() }
|
|
431
245
|
}
|
|
432
246
|
|
|
433
|
-
const captureUnifiedResponse = msg => {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
247
|
+
export const captureUnifiedResponse = msg => {
|
|
248
|
+
const botFwd = msg?.botForwardedMessage?.message
|
|
249
|
+
if (!botFwd) return null
|
|
250
|
+
const rich = botFwd.richResponseMessage
|
|
251
|
+
if (!rich?.unifiedResponse?.data) return null
|
|
252
|
+
return {
|
|
253
|
+
unifiedResponse: { data: rich.unifiedResponse.data },
|
|
254
|
+
submessages: rich.submessages || [],
|
|
255
|
+
contextInfo: rich.contextInfo || {}
|
|
256
|
+
}
|
|
443
257
|
}
|
|
444
258
|
|
|
445
|
-
const generateUnifiedResponseContent = (quoted, captured) => {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
message: buildBotForwardedMessage(captured.submessages, ctxInfo, captured.unifiedResponse),
|
|
449
|
-
messageId: generateMessageIDV2()
|
|
450
|
-
}
|
|
259
|
+
export const generateUnifiedResponseContent = (quoted, captured) => {
|
|
260
|
+
const ctxInfo = buildRichContextInfo(quoted)
|
|
261
|
+
return { message: buildBotForwardedMessage(captured.submessages, ctxInfo, captured.unifiedResponse), messageId: generateMessageIDV2() }
|
|
451
262
|
}
|
|
452
263
|
|
|
453
|
-
const generateRichMessageContent = (submessages, quoted, options) => {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
message: buildBotForwardedMessage(submessages, ctxInfo),
|
|
457
|
-
messageId: generateMessageIDV2()
|
|
458
|
-
}
|
|
264
|
+
export const generateRichMessageContent = (submessages, quoted, options) => {
|
|
265
|
+
const ctxInfo = buildRichContextInfo(quoted, options)
|
|
266
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: generateMessageIDV2() }
|
|
459
267
|
}
|
|
460
268
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
RichSubMessageType,
|
|
467
|
-
tokenizeCode,
|
|
468
|
-
buildRichContextInfo,
|
|
469
|
-
buildBotForwardedMessage,
|
|
470
|
-
generateTableContent,
|
|
471
|
-
generateListContent,
|
|
472
|
-
generateCodeBlockContent,
|
|
473
|
-
generateLatexContent,
|
|
474
|
-
generateLatexImageContent,
|
|
475
|
-
generateLatexInlineImageContent,
|
|
476
|
-
captureUnifiedResponse,
|
|
477
|
-
generateUnifiedResponseContent,
|
|
478
|
-
generateRichMessageContent
|
|
479
|
-
}
|
|
269
|
+
export {
|
|
270
|
+
JS_KEYWORDS,
|
|
271
|
+
PYTHON_KEYWORDS,
|
|
272
|
+
LANGUAGE_KEYWORDS
|
|
273
|
+
}
|