lyxe-baileys 1.0.2 → 2.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.
@@ -1,53 +1,60 @@
1
- import WebSocket from 'ws';
2
- import { DEFAULT_ORIGIN } from '../../Defaults/index.js';
3
- import { AbstractSocketClient } from './types.js';
4
- export class WebSocketClient extends AbstractSocketClient {
5
- constructor() {
6
- super(...arguments);
7
- this.socket = null;
8
- }
9
- get isOpen() {
10
- return this.socket?.readyState === WebSocket.OPEN;
11
- }
12
- get isClosed() {
13
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
14
- }
15
- get isClosing() {
16
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
17
- }
18
- get isConnecting() {
19
- return this.socket?.readyState === WebSocket.CONNECTING;
20
- }
21
- connect() {
22
- if (this.socket) {
23
- return;
24
- }
25
- this.socket = new WebSocket(this.url, {
26
- origin: DEFAULT_ORIGIN,
27
- headers: this.config.options?.headers,
28
- handshakeTimeout: this.config.connectTimeoutMs,
29
- timeout: this.config.connectTimeoutMs,
30
- agent: this.config.agent
31
- });
32
- this.socket.setMaxListeners(0);
33
- const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
34
- for (const event of events) {
35
- this.socket?.on(event, (...args) => this.emit(event, ...args));
36
- }
37
- }
38
- async close() {
39
- if (!this.socket) {
40
- return;
41
- }
42
- const closePromise = new Promise(resolve => {
43
- this.socket?.once('close', resolve);
44
- });
45
- this.socket.close();
46
- await closePromise;
47
- this.socket = null;
48
- }
49
- send(str, cb) {
50
- this.socket?.send(str, cb);
51
- return Boolean(this.socket);
52
- }
53
- }
1
+ import WebSocket from 'ws';
2
+ import { DEFAULT_ORIGIN } from '../../Defaults/index.js';
3
+ import { AbstractSocketClient } from './types.js';
4
+ import { createProxyAgent, CHROME_BROWSER_HEADERS } from './proxy-agent.js';
5
+
6
+ export class WebSocketClient extends AbstractSocketClient {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.socket = null;
10
+ }
11
+ get isOpen() {
12
+ return this.socket?.readyState === WebSocket.OPEN;
13
+ }
14
+ get isClosed() {
15
+ return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
16
+ }
17
+ get isClosing() {
18
+ return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
19
+ }
20
+ get isConnecting() {
21
+ return this.socket?.readyState === WebSocket.CONNECTING;
22
+ }
23
+ connect() {
24
+ if (this.socket) {
25
+ return;
26
+ }
27
+ const agent = this.config.agent || createProxyAgent(this.config.proxy);
28
+ const headers = {
29
+ ...CHROME_BROWSER_HEADERS,
30
+ ...(this.config.options?.headers || {})
31
+ };
32
+ this.socket = new WebSocket(this.url, {
33
+ origin: DEFAULT_ORIGIN,
34
+ headers: headers,
35
+ handshakeTimeout: this.config.connectTimeoutMs,
36
+ timeout: this.config.connectTimeoutMs,
37
+ agent: agent
38
+ });
39
+ this.socket.setMaxListeners(0);
40
+ const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
41
+ for (const event of events) {
42
+ this.socket?.on(event, (...args) => this.emit(event, ...args));
43
+ }
44
+ }
45
+ async close() {
46
+ if (!this.socket) {
47
+ return;
48
+ }
49
+ const closePromise = new Promise(resolve => {
50
+ this.socket?.once('close', resolve);
51
+ });
52
+ this.socket.close();
53
+ await closePromise;
54
+ this.socket = null;
55
+ }
56
+ send(str, cb) {
57
+ this.socket?.send(str, cb);
58
+ return Boolean(this.socket);
59
+ }
60
+ }
@@ -1,7 +1,8 @@
1
1
  import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
2
2
  import { prepareModernMessageContent } from '../Utils/modern-messages.js';
3
3
  import { makeNewsletterStatusFetcher, makeNewsletterStatusUpdatesFetcher, makeNewsletterStatusReactionSender, makeNewsletterStatusRevokeSender, makeNewsletterStatusSender } from '../Utils/newsletter-status.js';
4
- import { bindVoiceRecognition } from '../Utils/voice-recognition.js';
4
+ import { bindVoiceRecognition } from '../Utils/voice-recognition.js';
5
+ import { bindLyxeHelpers } from '../Lyxe/index.js';
5
6
  import { makeCommunitiesSocket } from './communities.js';
6
7
  import { makeEmailCoordinator } from './email.js';
7
8
  import { makeMobileCoordinator } from './mobile.js';
@@ -22,7 +23,8 @@ const makeWASocket = (config) => {
22
23
  sock.sendNewsletterStatusReaction = makeNewsletterStatusReactionSender(sock);
23
24
  sock.revokeNewsletterStatus = makeNewsletterStatusRevokeSender(sock);
24
25
  sock.getNewsletterStatuses = makeNewsletterStatusFetcher(sock);
25
- sock.getNewsletterStatusUpdates = makeNewsletterStatusUpdatesFetcher(sock);
26
+ sock.getNewsletterStatusUpdates = makeNewsletterStatusUpdatesFetcher(sock);
27
+ bindLyxeHelpers(sock, newConfig);
26
28
  if (newConfig.AnchorGuard) {
27
29
  import('@rexxhayanasi/elaina-anchorguard')
28
30
  .then(({ createAntiBugGuard }) => {
package/src/index.d.ts CHANGED
@@ -10,7 +10,8 @@ export * from "./MessageBuilder/index.js";
10
10
  export * from "./MessageBuilder/extras.js";
11
11
  export * from "./MessageBuilder/metaai.js";
12
12
  export * from "./MessageBuilder/bot-signature.js";
13
- export * from "./Voip/index.js";
13
+ export * from "./Voip/index.js";
14
+ export * from "./Lyxe/index.js";
14
15
  import baseMakeWASocket from './Socket/index.js';
15
16
  import type { NewsletterStatusFetchOptions, NewsletterStatusList, NewsletterStatusSendOptions, NewsletterStatusSendResult, NewsletterStatusStanzaResult, NewsletterStatusUpdatesFetchOptions } from './Utils/newsletter-status.js';
16
17
  type BaseWASocket = ReturnType<typeof baseMakeWASocket>;
@@ -19,7 +20,27 @@ export type WASocket = BaseWASocket & {
19
20
  sendNewsletterStatusReaction: (jid: string, parentServerId: string | number, reaction: string, options?: Pick<NewsletterStatusSendOptions, 'messageId' | 'ackTimeoutMs'>) => Promise<NewsletterStatusStanzaResult>;
20
21
  revokeNewsletterStatus: (jid: string, statusId: string, options?: Pick<NewsletterStatusSendOptions, 'ackTimeoutMs'>) => Promise<NewsletterStatusStanzaResult>;
21
22
  getNewsletterStatuses: (jid: string, options?: NewsletterStatusFetchOptions) => Promise<NewsletterStatusList>;
22
- getNewsletterStatusUpdates: (jid: string, options?: NewsletterStatusUpdatesFetchOptions) => Promise<NewsletterStatusList>;
23
+ getNewsletterStatusUpdates: (jid: string, options?: NewsletterStatusUpdatesFetchOptions) => Promise<NewsletterStatusList>;
24
+ smartDelay: (minMs?: number, maxMs?: number) => Promise<void>;
25
+ simulateTyping: (jid: string, durationMs?: number) => Promise<void>;
26
+ simulateRecording: (jid: string, durationMs?: number) => Promise<void>;
27
+ downloadViewOnce: (message: any) => Promise<import('./Lyxe/index.js').ViewOnceDownloadResult>;
28
+ extractRevokedMessage: (store: any, revocationMsg: any) => any | null;
29
+ readStatus: (statusMessage: any, delayMs?: number) => Promise<any>;
30
+ reactStatus: (statusMessageOrKey: any, emoji?: string) => Promise<any>;
31
+ sendStatusMention: (content: string | object, targetJids?: string[] | string, options?: any) => Promise<any>;
32
+ sendVoiceStatus: (audio: Buffer | { url: string } | string, options?: any) => Promise<any>;
33
+ sendVoiceNote: (jid: string, audio: Buffer | { url: string } | string, quoted?: any, options?: any) => Promise<any>;
34
+ sendImageAsSticker: (jid: string, sticker: Buffer | { url: string } | string, quoted?: any, options?: any) => Promise<any>;
35
+ sendHDMedia: (jid: string, mediaContent: { image?: any; video?: any; caption?: string }, options?: any) => Promise<any>;
36
+ streamMessage: (jid: string, stream: AsyncIterable<string> | Iterable<string> | string, options?: { throttleMs?: number; initialPlaceholder?: string; quoted?: any }) => Promise<any>;
37
+ groupAddWithBypass: (groupJid: string, participants: string[] | string, options?: { autoInvite?: boolean; caption?: string }) => Promise<import('./Lyxe/index.js').GroupBypassResult[]>;
38
+ sendVideoNote: (jid: string, video: Buffer | { url: string } | string, options?: any) => Promise<any>;
39
+ vault: import('./Lyxe/index.js').ImmortalVault;
40
+ radar: import('./Lyxe/index.js').PresenceRadar;
41
+ trackPresence: (jid: string, callback?: any) => Promise<string>;
42
+ bridgeTelegram: (options: any) => import('./Lyxe/index.js').TelegramBridge;
43
+ startDashboard: (port?: number) => import('./Lyxe/index.js').LyxeDashboard;
23
44
  };
24
45
  export declare const makeWASocket: (config: Parameters<typeof baseMakeWASocket>[0]) => WASocket;
25
46
  export default makeWASocket;
package/src/index.js CHANGED
@@ -18,7 +18,8 @@ export * from './MessageBuilder/index.js';
18
18
  export * from './MessageBuilder/extras.js';
19
19
  export * from './MessageBuilder/metaai.js';
20
20
  export * from './MessageBuilder/bot-signature.js';
21
- export * from './Voip/index.js';
21
+ export * from './Voip/index.js';
22
+ export * from './Lyxe/index.js';
22
23
 
23
24
  const builderMembers = [
24
25
  ...Object.entries(messageBuilderExtras),