@kyyinfinite/lumina 1.0.0
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/LICENSE +21 -0
- package/README.md +629 -0
- package/examples/ai-rich.js +84 -0
- package/examples/button.js +57 -0
- package/examples/carousel.js +51 -0
- package/examples/interactive.js +102 -0
- package/examples/media.js +66 -0
- package/examples/simple-bot.js +56 -0
- package/package.json +86 -0
- package/src/builders/ai-rich.js +644 -0
- package/src/builders/base.js +109 -0
- package/src/builders/button-v2.js +159 -0
- package/src/builders/button.js +398 -0
- package/src/builders/card.js +168 -0
- package/src/builders/carousel.js +122 -0
- package/src/builders/index.d.ts +1 -0
- package/src/builders/index.js +13 -0
- package/src/client/bot.js +192 -0
- package/src/client/connection.js +180 -0
- package/src/errors.js +88 -0
- package/src/index.d.ts +458 -0
- package/src/index.js +152 -0
- package/src/media/fetch.js +67 -0
- package/src/media/image.js +86 -0
- package/src/media/index.d.ts +1 -0
- package/src/media/index.js +12 -0
- package/src/media/resolver.js +115 -0
- package/src/media/uploader.js +65 -0
- package/src/media/video.js +195 -0
- package/src/parsers/code-tokenizer-keywords.js +128 -0
- package/src/parsers/code-tokenizer.js +191 -0
- package/src/parsers/index.d.ts +1 -0
- package/src/parsers/index.js +11 -0
- package/src/parsers/inline-entity.js +231 -0
- package/src/parsers/table-metadata.js +69 -0
- package/src/proto/enums.js +170 -0
- package/src/proto/index.d.ts +1 -0
- package/src/proto/index.js +13 -0
- package/src/proto/layouts.js +89 -0
- package/src/proto/primitives.js +181 -0
- package/src/proto/relay-nodes.js +55 -0
- package/src/proto/rich-response.js +144 -0
- package/src/proto/updater.js +318 -0
- package/src/services/index.d.ts +1 -0
- package/src/services/index.js +10 -0
- package/src/services/media-service.js +184 -0
- package/src/services/message-service.js +288 -0
- package/src/services/proto-service.js +90 -0
- package/src/utils/id.js +42 -0
- package/src/utils/logger.js +65 -0
- package/src/utils/mime.js +104 -0
- package/src/utils/promise.js +52 -0
- package/src/utils/validator.js +129 -0
package/src/errors.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file errors.js
|
|
3
|
+
* @module lumina/errors
|
|
4
|
+
*
|
|
5
|
+
* Error hierarchy for Lumina. Every Lumina-thrown error subclasses
|
|
6
|
+
* {@link LuminaError} and carries a stable `code`, the originating `module`,
|
|
7
|
+
* and (optionally) a `cause` field that follows the ES2022 Error.cause convention.
|
|
8
|
+
*
|
|
9
|
+
* Hierarchy:
|
|
10
|
+
* LuminaError
|
|
11
|
+
* ├── ValidationError (bad input — subclass of TypeError)
|
|
12
|
+
* ├── MediaError (fetch / resize / upload / ffmpeg failure)
|
|
13
|
+
* ├── ProtoError (assemble / generate / relay failure)
|
|
14
|
+
* ├── ConnectionError (Baileys socket missing or incompatible)
|
|
15
|
+
* └── ProtocolError (WAProto mismatch — emitted by ProtoUpdater)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Base class for every error thrown by Lumina.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* if (err instanceof LuminaError) {
|
|
23
|
+
* console.error(err.code, err.module, err.message)
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
export class LuminaError extends Error {
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} message Human-readable message.
|
|
29
|
+
* @param {object} [opts]
|
|
30
|
+
* @param {string} [opts.code='LUMINA_ERROR'] Stable machine code.
|
|
31
|
+
* @param {string} [opts.module='lumina'] Logical module that threw.
|
|
32
|
+
* @param {Error} [opts.cause] Original error (ES2022).
|
|
33
|
+
*/
|
|
34
|
+
constructor(message, opts = {}) {
|
|
35
|
+
super(message, { cause: opts.cause })
|
|
36
|
+
this.name = new.target.name
|
|
37
|
+
this.code = opts.code ?? 'LUMINA_ERROR'
|
|
38
|
+
this.module = opts.module ?? 'lumina'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Thrown when an argument fails validation. Subclass of TypeError for compat. */
|
|
43
|
+
export class ValidationError extends TypeError {
|
|
44
|
+
constructor(message, opts = {}) {
|
|
45
|
+
super(message, { cause: opts.cause })
|
|
46
|
+
this.name = 'ValidationError'
|
|
47
|
+
this.code = opts.code ?? 'LUMINA_VALIDATION'
|
|
48
|
+
this.module = opts.module ?? 'lumina'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Thrown when a media operation (fetch/resize/upload/ffmpeg) fails. */
|
|
53
|
+
export class MediaError extends LuminaError {
|
|
54
|
+
constructor(message, opts = {}) {
|
|
55
|
+
super(message, opts)
|
|
56
|
+
this.code = opts.code ?? 'LUMINA_MEDIA'
|
|
57
|
+
this.module = opts.module ?? 'media'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Thrown when a proto assembly / message generation / relay fails. */
|
|
62
|
+
export class ProtoError extends LuminaError {
|
|
63
|
+
constructor(message, opts = {}) {
|
|
64
|
+
super(message, opts)
|
|
65
|
+
this.code = opts.code ?? 'LUMINA_PROTO'
|
|
66
|
+
this.module = opts.module ?? 'proto'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Thrown when the Baileys socket is missing or its API is incompatible. */
|
|
71
|
+
export class ConnectionError extends LuminaError {
|
|
72
|
+
constructor(message, opts = {}) {
|
|
73
|
+
super(message, opts)
|
|
74
|
+
this.code = opts.code ?? 'LUMINA_CONNECTION'
|
|
75
|
+
this.module = opts.module ?? 'connection'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Thrown by {@link ProtoUpdater} when WAProto validation fails. */
|
|
80
|
+
export class ProtocolError extends LuminaError {
|
|
81
|
+
constructor(message, opts = {}) {
|
|
82
|
+
super(message, opts)
|
|
83
|
+
this.code = opts.code ?? 'LUMINA_PROTOCOL'
|
|
84
|
+
this.module = opts.module ?? 'proto-updater'
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default LuminaError
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.d.ts
|
|
3
|
+
* @module @kyyinfinite/lumina
|
|
4
|
+
*
|
|
5
|
+
* Manual TypeScript declaration for Lumina. Every builder, service, parser,
|
|
6
|
+
* and error is fully typed. Generated `.d.ts` files were rejected to keep
|
|
7
|
+
* the public surface auditable and to expose rich per-method overloads
|
|
8
|
+
* that auto-generation would lose.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// ─── External dependencies ─────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
declare module '@whiskeysockets/baileys' {
|
|
14
|
+
export interface WASocket {
|
|
15
|
+
relayMessage(jid: string, message: any, opts?: any): Promise<void>
|
|
16
|
+
generateMessageTag(): string
|
|
17
|
+
waUploadToServer: any
|
|
18
|
+
ev: {
|
|
19
|
+
on(event: string, handler: (...args: any[]) => void): void
|
|
20
|
+
off(event: string, handler: (...args: any[]) => void): void
|
|
21
|
+
emit(event: string, ...args: any[]): void
|
|
22
|
+
}
|
|
23
|
+
sendMessage(jid: string, content: any, opts?: any): Promise<any>
|
|
24
|
+
forwardMessage(jid: string, message: any, opts?: any): Promise<any>
|
|
25
|
+
[k: string]: any
|
|
26
|
+
}
|
|
27
|
+
export function generateWAMessageFromContent(jid: string, content: any, opts?: any): any
|
|
28
|
+
export function prepareWAMessageMedia(media: any, opts?: any): Promise<any>
|
|
29
|
+
export function generatePollMessage(jid: string, opts: any): any
|
|
30
|
+
export function generateReactionMessage(jid: string, opts: any): any
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ─── Errors ────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
export class LuminaError extends Error {
|
|
36
|
+
readonly code: string
|
|
37
|
+
readonly module: string
|
|
38
|
+
constructor(message: string, opts?: { code?: string; module?: string; cause?: Error })
|
|
39
|
+
}
|
|
40
|
+
export class ValidationError extends TypeError {
|
|
41
|
+
readonly code: string
|
|
42
|
+
readonly module: string
|
|
43
|
+
constructor(message: string, opts?: { code?: string; module?: string; cause?: Error })
|
|
44
|
+
}
|
|
45
|
+
export class MediaError extends LuminaError {}
|
|
46
|
+
export class ProtoError extends LuminaError {}
|
|
47
|
+
export class ConnectionError extends LuminaError {}
|
|
48
|
+
export class ProtocolError extends LuminaError {}
|
|
49
|
+
|
|
50
|
+
// ─── Logger ────────────────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug'
|
|
53
|
+
|
|
54
|
+
export interface Logger {
|
|
55
|
+
error(...args: any[]): void
|
|
56
|
+
warn(...args: any[]): void
|
|
57
|
+
info(...args: any[]): void
|
|
58
|
+
debug(...args: any[]): void
|
|
59
|
+
child(scope: string): Logger
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function createLogger(opts?: {
|
|
63
|
+
level?: LogLevel
|
|
64
|
+
silent?: boolean
|
|
65
|
+
scope?: string
|
|
66
|
+
transport?: (level: string, scope: string, args: any[]) => void
|
|
67
|
+
}): Logger
|
|
68
|
+
|
|
69
|
+
// ─── Enums & catalog ───────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
export const MessageType: Readonly<{
|
|
72
|
+
RICH_RESPONSE: 1
|
|
73
|
+
TEXT: 2
|
|
74
|
+
TABLE: 4
|
|
75
|
+
CODE: 5
|
|
76
|
+
REELS: 9
|
|
77
|
+
}>
|
|
78
|
+
|
|
79
|
+
export const ForwardOrigin: Readonly<{ BOT: 4 }>
|
|
80
|
+
export const HeaderType: Readonly<{
|
|
81
|
+
EMPTY: 0
|
|
82
|
+
TEXT: 1
|
|
83
|
+
IMAGE: 3
|
|
84
|
+
VIDEO: 4
|
|
85
|
+
DOCUMENT: 5
|
|
86
|
+
LOCATION_THUMBNAIL: 6
|
|
87
|
+
}>
|
|
88
|
+
|
|
89
|
+
export const NativeFlow: Readonly<{
|
|
90
|
+
OUTER_VERSION: '1'
|
|
91
|
+
FLOW_VERSION: '9'
|
|
92
|
+
FLOW_NAME_MIXED: 'mixed'
|
|
93
|
+
TYPE: 'native_flow'
|
|
94
|
+
BIZ_TAG: 'biz'
|
|
95
|
+
INTERACTIVE_TAG: 'interactive'
|
|
96
|
+
}>
|
|
97
|
+
|
|
98
|
+
export const BOT_JID: '0@bot'
|
|
99
|
+
|
|
100
|
+
export const LayoutKind: Readonly<{
|
|
101
|
+
SINGLE: 'Single'
|
|
102
|
+
HSCROLL: 'HScroll'
|
|
103
|
+
ACTION_ROW: 'ActionRow'
|
|
104
|
+
}>
|
|
105
|
+
|
|
106
|
+
export const HighlightType: Readonly<{
|
|
107
|
+
DEFAULT: 0
|
|
108
|
+
KEYWORD: 1
|
|
109
|
+
METHOD: 2
|
|
110
|
+
STRING: 3
|
|
111
|
+
NUMBER: 4
|
|
112
|
+
COMMENT: 5
|
|
113
|
+
}>
|
|
114
|
+
|
|
115
|
+
export const ImagineType: Readonly<{ IMAGE: 'IMAGE'; ANIMATE: 'ANIMATE' }>
|
|
116
|
+
|
|
117
|
+
export const TYPENAME: Readonly<{
|
|
118
|
+
MARKDOWN_TEXT: 'GenAIMarkdownTextUXPrimitive'
|
|
119
|
+
CODE: 'GenAICodeUXPrimitive'
|
|
120
|
+
TABLE: 'GenAITableUXPrimitive'
|
|
121
|
+
SEARCH_RESULT: 'GenAISearchResultPrimitive'
|
|
122
|
+
REEL: 'GenAIReelPrimitive'
|
|
123
|
+
IMAGINE: 'GenAIImaginePrimitive'
|
|
124
|
+
PRODUCT_CARD: 'GenAIProductItemCardPrimitive'
|
|
125
|
+
POST: 'GenAIPostPrimitive'
|
|
126
|
+
METADATA_TEXT: 'GenAIMetadataTextPrimitive'
|
|
127
|
+
FOLLOW_UP_PILL: 'GenAIFollowUpSuggestionPillPrimitive'
|
|
128
|
+
UNIFIED_SECTION: 'GenAIUnifiedResponseSection'
|
|
129
|
+
layout(kind: string): string
|
|
130
|
+
}>
|
|
131
|
+
|
|
132
|
+
// ─── Parsers ───────────────────────────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
export interface ExtractOptions {
|
|
135
|
+
extract?: boolean
|
|
136
|
+
hyperlink?: boolean
|
|
137
|
+
citation?: boolean
|
|
138
|
+
latex?: boolean
|
|
139
|
+
prefix?: string
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface ExtractResult {
|
|
143
|
+
text: string
|
|
144
|
+
entities: Array<{ type: 'hyperlink' | 'citation' | 'latex'; key: string; [k: string]: any }>
|
|
145
|
+
metadata: Array<{ key: string; metadata: any }>
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function extractInlineEntities(text: string, opts?: ExtractOptions): ExtractResult
|
|
149
|
+
|
|
150
|
+
export interface TokenizedCode {
|
|
151
|
+
codeBlock: Array<{ codeContent: string; highlightType: number }>
|
|
152
|
+
unifiedBlocks: Array<{ content: string; type: string }>
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function tokenizeCode(code: string, lang?: string): TokenizedCode
|
|
156
|
+
|
|
157
|
+
export interface TableMetadata {
|
|
158
|
+
title: string
|
|
159
|
+
rows: Array<{ items: string[]; isHeading?: boolean }>
|
|
160
|
+
unifiedRows: Array<{ is_header: boolean; cells: string[]; markdown_cells?: Array<{ text: string; inline_entities?: any[] }> }>
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function toTableMetadata(
|
|
164
|
+
table: string[][],
|
|
165
|
+
opts?: { title?: string; hyperlink?: boolean; citation?: boolean; latex?: boolean },
|
|
166
|
+
): TableMetadata
|
|
167
|
+
|
|
168
|
+
// ─── Connection ────────────────────────────────────────────────────────
|
|
169
|
+
|
|
170
|
+
export interface ConnectionOptions {
|
|
171
|
+
uploadJid?: string
|
|
172
|
+
logger?: Logger
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export class Connection {
|
|
176
|
+
constructor(socket: import('@whiskeysockets/baileys').WASocket, opts?: ConnectionOptions)
|
|
177
|
+
uploadJid?: string
|
|
178
|
+
logger?: Logger
|
|
179
|
+
|
|
180
|
+
uploadMedia(media: any, opts?: any): Promise<any>
|
|
181
|
+
generateMessage(jid: string, content: any, opts?: any): Promise<any>
|
|
182
|
+
generatePoll(jid: string, opts: any): Promise<any>
|
|
183
|
+
generateReaction(jid: string, opts: any): Promise<any>
|
|
184
|
+
relayMessage(jid: string, message: any, opts?: any): Promise<string>
|
|
185
|
+
on(event: string, handler: (...args: any[]) => void): () => void
|
|
186
|
+
once(event: string, handler: (...args: any[]) => void): () => void
|
|
187
|
+
off(event: string, handler: (...args: any[]) => void): void
|
|
188
|
+
get raw(): import('@whiskeysockets/baileys').WASocket
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ─── Services ──────────────────────────────────────────────────────────
|
|
192
|
+
|
|
193
|
+
export class MediaService {
|
|
194
|
+
constructor(conn: Connection, opts?: { cache?: boolean; cacheMax?: number; logger?: Logger; uploadJid?: string })
|
|
195
|
+
fetch(url: string, opts?: any): Promise<Buffer>
|
|
196
|
+
resize(buf: Buffer, opts: any): Promise<Buffer>
|
|
197
|
+
thumbnail(buf: Buffer, size?: number, format?: 'png' | 'jpeg' | 'webp'): Promise<Buffer>
|
|
198
|
+
duration(buf: Buffer): number
|
|
199
|
+
videoThumbnail(buf: Buffer, opts?: any): Promise<Buffer | string>
|
|
200
|
+
upload(source: Buffer | { url: string }, mediaType: 'image' | 'video' | 'audio' | 'document', opts?: any): Promise<string>
|
|
201
|
+
resolve(source: string | Buffer | Array<string | Buffer>, opts?: any): Promise<string | Buffer | Array<string | Buffer>>
|
|
202
|
+
sniff(buf: Buffer, filename?: string): string
|
|
203
|
+
category(mime: string): 'image' | 'video' | 'audio' | 'document'
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export class ProtoService {
|
|
207
|
+
constructor(conn: Connection)
|
|
208
|
+
generate(jid: string, content: any, opts?: any): Promise<any>
|
|
209
|
+
relay(jid: string, message: any, opts?: any): Promise<string>
|
|
210
|
+
relayInteractive(jid: string, message: any, opts?: any): Promise<string>
|
|
211
|
+
generateAndRelay(jid: string, content: any, opts?: any & { interactive?: boolean }): Promise<any>
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class MessageService {
|
|
215
|
+
constructor(conn: Connection, proto: ProtoService, media: MediaService)
|
|
216
|
+
text(jid: string, text: string, opts?: any): Promise<any>
|
|
217
|
+
image(jid: string, source: string | Buffer, caption?: string, opts?: any): Promise<any>
|
|
218
|
+
video(jid: string, source: string | Buffer, caption?: string, opts?: any): Promise<any>
|
|
219
|
+
audio(jid: string, source: string | Buffer, opts?: any): Promise<any>
|
|
220
|
+
document(jid: string, source: string | Buffer, opts?: any): Promise<any>
|
|
221
|
+
sticker(jid: string, source: string | Buffer, opts?: any): Promise<any>
|
|
222
|
+
contact(jid: string, contacts: Array<{ name: string; number: string }>, opts?: any): Promise<any>
|
|
223
|
+
location(jid: string, lat: number, lng: number, opts?: any): Promise<any>
|
|
224
|
+
poll(jid: string, name: string, options: string[], opts?: any): Promise<any>
|
|
225
|
+
reply(jid: string, text: string, quoted: any, opts?: any): Promise<any>
|
|
226
|
+
react(jid: string, key: any, emoji: string, opts?: any): Promise<any>
|
|
227
|
+
delete(jid: string, key: any): Promise<any>
|
|
228
|
+
forward(jid: string, message: any, opts?: any): Promise<any>
|
|
229
|
+
copy(jid: string, message: any, opts?: any): Promise<any>
|
|
230
|
+
edit(jid: string, key: any, newText: string, opts?: any): Promise<any>
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ─── Builders ──────────────────────────────────────────────────────────
|
|
234
|
+
|
|
235
|
+
export interface ContentFields {
|
|
236
|
+
title(t: string): this
|
|
237
|
+
subtitle(t: string): this
|
|
238
|
+
body(t: string): this
|
|
239
|
+
footer(t: string): this
|
|
240
|
+
contextInfo(o: object): this
|
|
241
|
+
payload(o: object): this
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export class ButtonBuilder implements ContentFields {
|
|
245
|
+
constructor(conn: Connection, proto: ProtoService, media: MediaService)
|
|
246
|
+
|
|
247
|
+
// Content
|
|
248
|
+
title(t: string): this
|
|
249
|
+
subtitle(t: string): this
|
|
250
|
+
body(t: string): this
|
|
251
|
+
footer(t: string): this
|
|
252
|
+
contextInfo(o: object): this
|
|
253
|
+
payload(o: object): this
|
|
254
|
+
|
|
255
|
+
// Media
|
|
256
|
+
media(type: 'image' | 'video' | 'document', source: string | Buffer | object, opts?: object): this
|
|
257
|
+
image(source: string | Buffer, opts?: object): this
|
|
258
|
+
video(source: string | Buffer, opts?: object): this
|
|
259
|
+
document(source: string | Buffer, opts?: object): this
|
|
260
|
+
|
|
261
|
+
// Buttons
|
|
262
|
+
button(name: string, params: object | string, extra?: object): this
|
|
263
|
+
params(obj: object): this
|
|
264
|
+
reply(displayText: string, id?: string, opts?: object): this
|
|
265
|
+
call(displayText: string, id?: string, opts?: object): this
|
|
266
|
+
reminder(displayText: string, id?: string, opts?: object): this
|
|
267
|
+
cancelReminder(displayText: string, id?: string, opts?: object): this
|
|
268
|
+
address(displayText: string, id?: string, opts?: object): this
|
|
269
|
+
url(displayText: string, url: string, opts?: object): this
|
|
270
|
+
copy(displayText: string, copyCode: string, opts?: object): this
|
|
271
|
+
location(opts?: object): this
|
|
272
|
+
selection(title: string, builder: (sel: SelectionBuilder) => void, extra?: object): this
|
|
273
|
+
clear(): this
|
|
274
|
+
|
|
275
|
+
// Lifecycle
|
|
276
|
+
toCard(): Promise<object>
|
|
277
|
+
build(jid: string, opts?: object): Promise<object>
|
|
278
|
+
send(jid: string, opts?: object): Promise<object>
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface SelectionBuilder {
|
|
282
|
+
title(t: string): this
|
|
283
|
+
section(title: string, builder: (s: SectionBuilder) => void): this
|
|
284
|
+
build(): object
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface SectionBuilder {
|
|
288
|
+
row(header: string, title: string, description: string, id: string): this
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export class ButtonV2Builder implements ContentFields {
|
|
292
|
+
constructor(conn: Connection)
|
|
293
|
+
title(t: string): this
|
|
294
|
+
subtitle(t: string): this
|
|
295
|
+
body(t: string): this
|
|
296
|
+
footer(t: string): this
|
|
297
|
+
contextInfo(o: object): this
|
|
298
|
+
payload(o: object): this
|
|
299
|
+
button(displayText: string, id?: string): this
|
|
300
|
+
rawButton(obj: object): this
|
|
301
|
+
thumbnail(source: string | Buffer): this
|
|
302
|
+
media(obj: object): this
|
|
303
|
+
build(jid: string, opts?: object): Promise<object>
|
|
304
|
+
send(jid: string, opts?: object): Promise<object>
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export class CardBuilder implements ContentFields {
|
|
308
|
+
constructor(conn: Connection)
|
|
309
|
+
title(t: string): this
|
|
310
|
+
subtitle(t: string): this
|
|
311
|
+
body(t: string): this
|
|
312
|
+
footer(t: string): this
|
|
313
|
+
contextInfo(o: object): this
|
|
314
|
+
payload(o: object): this
|
|
315
|
+
media(type: 'image' | 'video' | 'document', source: string | Buffer | object, opts?: object): this
|
|
316
|
+
image(source: string | Buffer, opts?: object): this
|
|
317
|
+
video(source: string | Buffer, opts?: object): this
|
|
318
|
+
document(source: string | Buffer, opts?: object): this
|
|
319
|
+
params(obj: object): this
|
|
320
|
+
button(name: string, params: object | string, extra?: object): this
|
|
321
|
+
reply(displayText: string, id?: string, opts?: object): this
|
|
322
|
+
url(displayText: string, url: string, opts?: object): this
|
|
323
|
+
copy(displayText: string, copyCode: string, opts?: object): this
|
|
324
|
+
build(): Promise<object>
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export class CarouselBuilder implements ContentFields {
|
|
328
|
+
constructor(conn: Connection, proto: ProtoService, media: MediaService)
|
|
329
|
+
title(t: string): this
|
|
330
|
+
subtitle(t: string): this
|
|
331
|
+
body(t: string): this
|
|
332
|
+
footer(t: string): this
|
|
333
|
+
contextInfo(o: object): this
|
|
334
|
+
payload(o: object): this
|
|
335
|
+
newCard(): CardBuilder
|
|
336
|
+
card(card: object | object[]): this
|
|
337
|
+
cards(...cards: object[]): this
|
|
338
|
+
build(jid: string, opts?: object): Promise<object>
|
|
339
|
+
send(jid: string, opts?: object): Promise<object>
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export class AIRichBuilder implements ContentFields {
|
|
343
|
+
constructor(conn: Connection, proto: ProtoService, media: MediaService)
|
|
344
|
+
title(t: string): this
|
|
345
|
+
subtitle(t: string): this
|
|
346
|
+
body(t: string): this
|
|
347
|
+
footer(t: string): this
|
|
348
|
+
contextInfo(o: object): this
|
|
349
|
+
payload(o: object): this
|
|
350
|
+
|
|
351
|
+
forwarded(v?: boolean): this
|
|
352
|
+
notification(v: boolean | object): this
|
|
353
|
+
quoted(quoted: object, quotedParticipant?: string): this
|
|
354
|
+
includesUnifiedResponse(v?: boolean): this
|
|
355
|
+
includesSubmessages(v?: boolean): this
|
|
356
|
+
submessage(msg: object | object[]): this
|
|
357
|
+
|
|
358
|
+
text(text: string, opts?: { hyperlink?: boolean; citation?: boolean; latex?: boolean }): Promise<this>
|
|
359
|
+
code(language: string, code: string): Promise<this>
|
|
360
|
+
table(table: string[][], opts?: { title?: string; hyperlink?: boolean; citation?: boolean; latex?: boolean }): Promise<this>
|
|
361
|
+
image(source: string | Buffer | Array<string | Buffer>, opts?: { resolveUrl?: boolean }): Promise<this>
|
|
362
|
+
video(source: string | Buffer | object | Array<any>, opts?: { autoFill?: boolean }): Promise<this>
|
|
363
|
+
source(sources: Array<string> | Array<Array<string>>): Promise<this>
|
|
364
|
+
reels(items: object | object[]): Promise<this>
|
|
365
|
+
product(item: object | object[]): Promise<this>
|
|
366
|
+
post(item: object | object[]): Promise<this>
|
|
367
|
+
tip(text: string): Promise<this>
|
|
368
|
+
suggest(suggestion: string | string[], opts?: { scroll?: boolean; layout?: 'Single' | 'HScroll' | 'ActionRow' }): Promise<this>
|
|
369
|
+
|
|
370
|
+
build(opts?: object): Promise<object>
|
|
371
|
+
send(jid: string, opts?: object): Promise<string>
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// ─── ProtoUpdater ──────────────────────────────────────────────────────
|
|
375
|
+
|
|
376
|
+
export class ProtoUpdater {
|
|
377
|
+
constructor(opts?: { protoPath?: string; backupDir?: string; logger?: Logger })
|
|
378
|
+
backup(): Promise<{ id: string; timestamp: number; path: string; hash: string }>
|
|
379
|
+
restore(id: string): Promise<void>
|
|
380
|
+
rollback(): Promise<void>
|
|
381
|
+
validate(): Promise<{ ok: boolean; errors: Array<{ file: string; message: string }> }>
|
|
382
|
+
update(opts?: { autoRollback?: boolean; dryRun?: boolean }): Promise<{
|
|
383
|
+
success: boolean
|
|
384
|
+
fromHash: string
|
|
385
|
+
toHash: string
|
|
386
|
+
backupId: string | null
|
|
387
|
+
appliedFixes: string[]
|
|
388
|
+
errors: any[]
|
|
389
|
+
}>
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export function transformToESM(src: string): string
|
|
393
|
+
export function applyKnownFixes(filename: string, content: string): { content: string; applied: string[] }
|
|
394
|
+
export function assembleRichResponse(opts?: any): Promise<object>
|
|
395
|
+
export function createInteractiveNodes(opts?: any): any[]
|
|
396
|
+
export function createBareInteractiveNodes(opts?: any): any[]
|
|
397
|
+
|
|
398
|
+
// ─── Bot ───────────────────────────────────────────────────────────────
|
|
399
|
+
|
|
400
|
+
export interface BotOptions {
|
|
401
|
+
uploadJid?: string
|
|
402
|
+
logger?: Logger
|
|
403
|
+
mediaCache?: boolean
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface UtilFacade {
|
|
407
|
+
extractInlineEntities: typeof extractInlineEntities
|
|
408
|
+
tokenizeCode: typeof tokenizeCode
|
|
409
|
+
toTableMetadata: typeof toTableMetadata
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export class Bot {
|
|
413
|
+
constructor(socket: import('@whiskeysockets/baileys').WASocket, opts?: BotOptions)
|
|
414
|
+
|
|
415
|
+
readonly connection: Connection
|
|
416
|
+
readonly media: MediaService
|
|
417
|
+
readonly proto: ProtoService
|
|
418
|
+
readonly message: MessageService
|
|
419
|
+
readonly logger: Logger
|
|
420
|
+
readonly util: UtilFacade
|
|
421
|
+
|
|
422
|
+
// Basic senders
|
|
423
|
+
text(jid: string, text: string, opts?: any): Promise<any>
|
|
424
|
+
image(jid: string, source: string | Buffer, caption?: string, opts?: any): Promise<any>
|
|
425
|
+
video(jid: string, source: string | Buffer, caption?: string, opts?: any): Promise<any>
|
|
426
|
+
audio(jid: string, source: string | Buffer, opts?: any): Promise<any>
|
|
427
|
+
document(jid: string, source: string | Buffer, opts?: any): Promise<any>
|
|
428
|
+
sticker(jid: string, source: string | Buffer, opts?: any): Promise<any>
|
|
429
|
+
contact(jid: string, contacts: Array<{ name: string; number: string }>, opts?: any): Promise<any>
|
|
430
|
+
location(jid: string, lat: number, lng: number, opts?: any): Promise<any>
|
|
431
|
+
poll(jid: string, name: string, options: string[], opts?: any): Promise<any>
|
|
432
|
+
reply(jid: string, text: string, quoted: any, opts?: any): Promise<any>
|
|
433
|
+
react(jid: string, key: any, emoji: string, opts?: any): Promise<any>
|
|
434
|
+
delete(jid: string, key: any): Promise<any>
|
|
435
|
+
forward(jid: string, message: any, opts?: any): Promise<any>
|
|
436
|
+
copy(jid: string, message: any, opts?: any): Promise<any>
|
|
437
|
+
edit(jid: string, key: any, newText: string, opts?: any): Promise<any>
|
|
438
|
+
|
|
439
|
+
// Builder factories
|
|
440
|
+
button(): ButtonBuilder
|
|
441
|
+
buttonV2(): ButtonV2Builder
|
|
442
|
+
carousel(): CarouselBuilder
|
|
443
|
+
ai(): AIRichBuilder
|
|
444
|
+
|
|
445
|
+
// Event bus
|
|
446
|
+
on(event: string, handler: (...args: any[]) => void): () => void
|
|
447
|
+
once(event: string, handler: (...args: any[]) => void): () => void
|
|
448
|
+
off(event: string, handler: (...args: any[]) => void): void
|
|
449
|
+
|
|
450
|
+
// Raw escape
|
|
451
|
+
get raw(): import('@whiskeysockets/baileys').WASocket
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// ─── Version ───────────────────────────────────────────────────────────
|
|
455
|
+
|
|
456
|
+
export const VERSION: string
|
|
457
|
+
|
|
458
|
+
export default Bot
|
package/src/index.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.js
|
|
3
|
+
* @module @kyyinfinite/lumina
|
|
4
|
+
*
|
|
5
|
+
* Lumina — Modern WhatsApp framework built on top of Baileys.
|
|
6
|
+
*
|
|
7
|
+
* Public API surface:
|
|
8
|
+
*
|
|
9
|
+
* import { Bot } from '@kyyinfinite/lumina'
|
|
10
|
+
* const bot = new Bot(socket)
|
|
11
|
+
* await bot.text(jid, 'Halo')
|
|
12
|
+
*
|
|
13
|
+
* Subpath exports (tree-shakable):
|
|
14
|
+
*
|
|
15
|
+
* import { extractInlineEntities } from '@kyyinfinite/lumina/parsers'
|
|
16
|
+
* import { MediaService } from '@kyyinfinite/lumina/services'
|
|
17
|
+
* import { ButtonBuilder } from '@kyyinfinite/lumina/builders'
|
|
18
|
+
* import { ProtoUpdater } from '@kyyinfinite/lumina/proto'
|
|
19
|
+
* import { resize } from '@kyyinfinite/lumina/media'
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { Bot } from './client/bot.js'
|
|
23
|
+
import { Connection } from './client/connection.js'
|
|
24
|
+
|
|
25
|
+
import { ButtonBuilder } from './builders/button.js'
|
|
26
|
+
import { ButtonV2Builder } from './builders/button-v2.js'
|
|
27
|
+
import { CarouselBuilder } from './builders/carousel.js'
|
|
28
|
+
import { CardBuilder } from './builders/card.js'
|
|
29
|
+
import { AIRichBuilder } from './builders/ai-rich.js'
|
|
30
|
+
|
|
31
|
+
import { MediaService } from './services/media-service.js'
|
|
32
|
+
import { ProtoService } from './services/proto-service.js'
|
|
33
|
+
import { MessageService } from './services/message-service.js'
|
|
34
|
+
|
|
35
|
+
import { extractInlineEntities } from './parsers/inline-entity.js'
|
|
36
|
+
import { tokenizeCode } from './parsers/code-tokenizer.js'
|
|
37
|
+
import { toTableMetadata } from './parsers/table-metadata.js'
|
|
38
|
+
|
|
39
|
+
import { ProtoUpdater, transformToESM, applyKnownFixes } from './proto/updater.js'
|
|
40
|
+
import { assembleRichResponse } from './proto/rich-response.js'
|
|
41
|
+
import { createInteractiveNodes, createBareInteractiveNodes } from './proto/relay-nodes.js'
|
|
42
|
+
|
|
43
|
+
// Catalog re-exports — these are imported so that the named exports below
|
|
44
|
+
// are available from the root `@kyyinfinite/lumina` entry point.
|
|
45
|
+
import {
|
|
46
|
+
MessageType,
|
|
47
|
+
ForwardOrigin,
|
|
48
|
+
HeaderType,
|
|
49
|
+
NativeFlow,
|
|
50
|
+
BOT_JID,
|
|
51
|
+
LayoutKind,
|
|
52
|
+
HighlightType,
|
|
53
|
+
HighlightLabel,
|
|
54
|
+
ImagineType,
|
|
55
|
+
SourceType,
|
|
56
|
+
PromptType,
|
|
57
|
+
SessionTransparencyType,
|
|
58
|
+
TYPENAME,
|
|
59
|
+
} from './proto/enums.js'
|
|
60
|
+
|
|
61
|
+
import {
|
|
62
|
+
markdownTextPrimitive,
|
|
63
|
+
codePrimitive,
|
|
64
|
+
tablePrimitive,
|
|
65
|
+
searchResultPrimitive,
|
|
66
|
+
reelPrimitive,
|
|
67
|
+
imaginePrimitive,
|
|
68
|
+
productCardPrimitive,
|
|
69
|
+
postPrimitive,
|
|
70
|
+
metadataTextPrimitive,
|
|
71
|
+
followUpSuggestionPillPrimitive,
|
|
72
|
+
shapeSourceEntry,
|
|
73
|
+
shapeReelEntry,
|
|
74
|
+
} from './proto/primitives.js'
|
|
75
|
+
|
|
76
|
+
import { singleLayout, hscrollLayout, actionRowLayout, layoutFor } from './proto/layouts.js'
|
|
77
|
+
|
|
78
|
+
import { LuminaError, ValidationError, MediaError, ProtoError, ConnectionError, ProtocolError } from './errors.js'
|
|
79
|
+
import { createLogger } from './utils/logger.js'
|
|
80
|
+
|
|
81
|
+
/** Semver version of the Lumina package. */
|
|
82
|
+
export const VERSION = '1.0.0'
|
|
83
|
+
|
|
84
|
+
// Public API
|
|
85
|
+
export {
|
|
86
|
+
Bot,
|
|
87
|
+
Connection,
|
|
88
|
+
// Builders
|
|
89
|
+
ButtonBuilder,
|
|
90
|
+
ButtonV2Builder,
|
|
91
|
+
CarouselBuilder,
|
|
92
|
+
CardBuilder,
|
|
93
|
+
AIRichBuilder,
|
|
94
|
+
// Services
|
|
95
|
+
MediaService,
|
|
96
|
+
ProtoService,
|
|
97
|
+
MessageService,
|
|
98
|
+
// Parsers
|
|
99
|
+
extractInlineEntities,
|
|
100
|
+
tokenizeCode,
|
|
101
|
+
toTableMetadata,
|
|
102
|
+
// Proto
|
|
103
|
+
ProtoUpdater,
|
|
104
|
+
transformToESM,
|
|
105
|
+
applyKnownFixes,
|
|
106
|
+
assembleRichResponse,
|
|
107
|
+
createInteractiveNodes,
|
|
108
|
+
createBareInteractiveNodes,
|
|
109
|
+
// Catalog
|
|
110
|
+
MessageType,
|
|
111
|
+
ForwardOrigin,
|
|
112
|
+
HeaderType,
|
|
113
|
+
NativeFlow,
|
|
114
|
+
BOT_JID,
|
|
115
|
+
LayoutKind,
|
|
116
|
+
HighlightType,
|
|
117
|
+
HighlightLabel,
|
|
118
|
+
ImagineType,
|
|
119
|
+
SourceType,
|
|
120
|
+
PromptType,
|
|
121
|
+
SessionTransparencyType,
|
|
122
|
+
TYPENAME,
|
|
123
|
+
// Primitive factories
|
|
124
|
+
markdownTextPrimitive,
|
|
125
|
+
codePrimitive,
|
|
126
|
+
tablePrimitive,
|
|
127
|
+
searchResultPrimitive,
|
|
128
|
+
reelPrimitive,
|
|
129
|
+
imaginePrimitive,
|
|
130
|
+
productCardPrimitive,
|
|
131
|
+
postPrimitive,
|
|
132
|
+
metadataTextPrimitive,
|
|
133
|
+
followUpSuggestionPillPrimitive,
|
|
134
|
+
shapeSourceEntry,
|
|
135
|
+
shapeReelEntry,
|
|
136
|
+
// Layout factories
|
|
137
|
+
singleLayout,
|
|
138
|
+
hscrollLayout,
|
|
139
|
+
actionRowLayout,
|
|
140
|
+
layoutFor,
|
|
141
|
+
// Errors
|
|
142
|
+
LuminaError,
|
|
143
|
+
ValidationError,
|
|
144
|
+
MediaError,
|
|
145
|
+
ProtoError,
|
|
146
|
+
ConnectionError,
|
|
147
|
+
ProtocolError,
|
|
148
|
+
// Utils
|
|
149
|
+
createLogger,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export default Bot
|