@x4r1s3/baileys 0.0.0-stage → 1.0.1
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 +1245 -2
- package/SECURITY.md +47 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8892 -0
- package/WAProto/index.d.ts +104128 -0
- package/WAProto/index.js +334920 -0
- package/assets/rolling-circle.svg +133 -0
- package/assets/x4r1s3-banner.svg +32 -0
- package/engine-requirements.js +27 -0
- package/lib/Builders/A2UI.js +245 -0
- package/lib/Builders/AIRich.js +179 -0
- package/lib/Builders/Button.js +108 -0
- package/lib/Builders/CFC.js +284 -0
- package/lib/Builders/Carousel.js +81 -0
- package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
- package/lib/Call/astralena-v3.mjs +96 -0
- package/lib/Call/audio-feeder.mjs +201 -0
- package/lib/Call/audio-recorder.mjs +250 -0
- package/lib/Call/fetch-wasm-resources.mjs +104 -0
- package/lib/Call/index.mjs +707 -0
- package/lib/Call/relay-transport.mjs +563 -0
- package/lib/Call/signaling.mjs +660 -0
- package/lib/Call/types.mjs +17 -0
- package/lib/Call/video-feeder.mjs +94 -0
- package/lib/Call/voip-resources.mjs +259 -0
- package/lib/Call/wasm-engine.mjs +1372 -0
- package/lib/Call/worker-bootstrap.mjs +1042 -0
- package/lib/Defaults/ban-checker.js +56 -0
- package/lib/Defaults/index.js +170 -0
- package/lib/Signal/Group/ciphertext-message.js +23 -0
- package/lib/Signal/Group/group-session-builder.js +41 -0
- package/lib/Signal/Group/group_cipher.js +93 -0
- package/lib/Signal/Group/index.js +23 -0
- package/lib/Signal/Group/keyhelper.js +29 -0
- package/lib/Signal/Group/sender-chain-key.js +37 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
- package/lib/Signal/Group/sender-key-message.js +77 -0
- package/lib/Signal/Group/sender-key-name.js +59 -0
- package/lib/Signal/Group/sender-key-record.js +52 -0
- package/lib/Signal/Group/sender-key-state.js +95 -0
- package/lib/Signal/Group/sender-message-key.js +37 -0
- package/lib/Signal/libsignal.js +440 -0
- package/lib/Signal/lid-mapping.js +292 -0
- package/lib/Socket/Client/index.js +14 -0
- package/lib/Socket/Client/types.js +22 -0
- package/lib/Socket/Client/websocket.js +65 -0
- package/lib/Socket/aigroups.js +327 -0
- package/lib/Socket/ban-checker.js +165 -0
- package/lib/Socket/business.js +419 -0
- package/lib/Socket/chats.js +1921 -0
- package/lib/Socket/communities.js +443 -0
- package/lib/Socket/graphql.js +911 -0
- package/lib/Socket/groups.js +561 -0
- package/lib/Socket/index.js +49 -0
- package/lib/Socket/interactive-handler.js +612 -0
- package/lib/Socket/interop.js +575 -0
- package/lib/Socket/managed-account.js +220 -0
- package/lib/Socket/messages-recv.js +2193 -0
- package/lib/Socket/messages-send.js +4141 -0
- package/lib/Socket/mex.js +53 -0
- package/lib/Socket/newsletter.js +291 -0
- package/lib/Socket/privacy.js +458 -0
- package/lib/Socket/registration.js +440 -0
- package/lib/Socket/socket.js +1042 -0
- package/lib/Socket/status-actions.js +287 -0
- package/lib/Socket/username.js +241 -0
- package/lib/Store/index.js +16 -0
- package/lib/Store/make-cache-manager-store.js +101 -0
- package/lib/Store/make-in-memory-store.js +432 -0
- package/lib/Store/make-ordered-dictionary.js +90 -0
- package/lib/Store/object-repository.js +35 -0
- package/lib/Types/Auth.js +13 -0
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -0
- package/lib/Types/Chat.js +19 -0
- package/lib/Types/Contact.js +13 -0
- package/lib/Types/Events.js +13 -0
- package/lib/Types/GroupMetadata.js +13 -0
- package/lib/Types/Label.js +36 -0
- package/lib/Types/LabelAssociation.js +18 -0
- package/lib/Types/Message.js +30 -0
- package/lib/Types/Mex.js +53 -0
- package/lib/Types/Product.js +13 -0
- package/lib/Types/RichType.js +34 -0
- package/lib/Types/Signal.js +13 -0
- package/lib/Types/Socket.js +14 -0
- package/lib/Types/State.js +60 -0
- package/lib/Types/USync.js +13 -0
- package/lib/Types/index.js +37 -0
- package/lib/Utils/auth-utils.js +313 -0
- package/lib/Utils/ban-checker.js +48 -0
- package/lib/Utils/bot-capabilities.js +96 -0
- package/lib/Utils/bot-planning-replay.js +177 -0
- package/lib/Utils/browser-utils.js +40 -0
- package/lib/Utils/business.js +242 -0
- package/lib/Utils/c2582.js +147 -0
- package/lib/Utils/chat-utils.js +905 -0
- package/lib/Utils/companion-reg-client-utils.js +104 -0
- package/lib/Utils/consumer-application.js +114 -0
- package/lib/Utils/crypto.js +129 -0
- package/lib/Utils/decode-wa-message.js +496 -0
- package/lib/Utils/direct-chat-theme.js +164 -0
- package/lib/Utils/event-buffer.js +601 -0
- package/lib/Utils/experimental-proto.js +206 -0
- package/lib/Utils/games/miniapp.js +17 -0
- package/lib/Utils/games/slot-machine.js +270 -0
- package/lib/Utils/games/website-preview.js +306 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/group-history.js +68 -0
- package/lib/Utils/group-wallpaper.js +168 -0
- package/lib/Utils/history.js +162 -0
- package/lib/Utils/identity-change-handler.js +60 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/jid-display-normalization.js +221 -0
- package/lib/Utils/link-preview.js +96 -0
- package/lib/Utils/logger.js +14 -0
- package/lib/Utils/lt-hash.js +19 -0
- package/lib/Utils/make-mutex.js +44 -0
- package/lib/Utils/message-composer.js +709 -0
- package/lib/Utils/message-inspect.js +79 -0
- package/lib/Utils/message-retry-manager.js +253 -0
- package/lib/Utils/message-security.js +167 -0
- package/lib/Utils/messages-media.js +1027 -0
- package/lib/Utils/messages.js +2467 -0
- package/lib/Utils/meta-ai-msmsg.js +215 -0
- package/lib/Utils/meta-compositing.js +239 -0
- package/lib/Utils/native-flow.js +158 -0
- package/lib/Utils/newsletter-live-update-utils.js +74 -0
- package/lib/Utils/newsletter-status-utils.js +152 -0
- package/lib/Utils/noise-handler.js +212 -0
- package/lib/Utils/offline-node-processor.js +51 -0
- package/lib/Utils/poll-manager.js +206 -0
- package/lib/Utils/portable-compat.js +12 -0
- package/lib/Utils/pre-key-manager.js +117 -0
- package/lib/Utils/process-message.js +610 -0
- package/lib/Utils/reporting-utils.js +269 -0
- package/lib/Utils/rich-message-utils.js +2841 -0
- package/lib/Utils/scheduled-message.js +107 -0
- package/lib/Utils/signal.js +212 -0
- package/lib/Utils/source-grep.js +57 -0
- package/lib/Utils/stanza-ack.js +49 -0
- package/lib/Utils/sticker-annotation.js +87 -0
- package/lib/Utils/sync-action-utils.js +59 -0
- package/lib/Utils/tc-token-utils.js +174 -0
- package/lib/Utils/use-multi-file-auth-state.js +132 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +120 -0
- package/lib/Utils/validate-connection.js +221 -0
- package/lib/Utils/view-once-utils.js +218 -0
- package/lib/Utils/voip-rekey.js +32 -0
- package/lib/Utils/website-preview.js +27 -0
- package/lib/Utils/welcome-flow.js +228 -0
- package/lib/Utils/x4r1s3.js +144 -0
- package/lib/WABinary/constants.js +1475 -0
- package/lib/WABinary/decode.js +273 -0
- package/lib/WABinary/encode.js +231 -0
- package/lib/WABinary/generic-utils.js +242 -0
- package/lib/WABinary/index.js +17 -0
- package/lib/WABinary/jid-utils.js +107 -0
- package/lib/WABinary/types.js +13 -0
- package/lib/WAM/BinaryInfo.js +21 -0
- package/lib/WAM/constants.js +22864 -0
- package/lib/WAM/encode.js +161 -0
- package/lib/WAM/index.js +15 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
- package/lib/WAUSync/Protocols/index.js +24 -0
- package/lib/WAUSync/USyncQuery.js +213 -0
- package/lib/WAUSync/USyncUser.js +66 -0
- package/lib/WAUSync/index.js +15 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +1895 -0
- package/lib/index.js +41 -0
- package/package.json +125 -4
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 X4R1S3x — @X4R1S3/baileys
|
|
3
|
+
*/
|
|
4
|
+
export class Button {
|
|
5
|
+
#socket;
|
|
6
|
+
|
|
7
|
+
constructor(socket) {
|
|
8
|
+
if (!socket) throw new Error('Socket is required');
|
|
9
|
+
this.#socket = socket;
|
|
10
|
+
this._media = {};
|
|
11
|
+
this._title = '';
|
|
12
|
+
this._subtitle = '';
|
|
13
|
+
this._body = '';
|
|
14
|
+
this._footer = '';
|
|
15
|
+
this._buttons = [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setImage(source, options = {}) {
|
|
19
|
+
if (!source) throw new Error('Image URL or buffer is required');
|
|
20
|
+
this._media = { image: Buffer.isBuffer(source) ? source : { url: source }, ...options };
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setVideo(source, options = {}) {
|
|
25
|
+
if (!source) throw new Error('Video URL or buffer is required');
|
|
26
|
+
this._media = { video: Buffer.isBuffer(source) ? source : { url: source }, ...options };
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setTitle(title) {
|
|
31
|
+
if (typeof title !== 'string') throw new TypeError('Title must be a string');
|
|
32
|
+
this._title = title;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setSubtitle(subtitle) {
|
|
37
|
+
if (typeof subtitle !== 'string') throw new TypeError('Subtitle must be a string');
|
|
38
|
+
this._subtitle = subtitle;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setBody(body) {
|
|
43
|
+
if (typeof body !== 'string') throw new TypeError('Body must be a string');
|
|
44
|
+
this._body = body;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setFooter(footer) {
|
|
49
|
+
if (typeof footer !== 'string') throw new TypeError('Footer must be a string');
|
|
50
|
+
this._footer = footer;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
addUrl(displayText, url, useWebview = false) {
|
|
55
|
+
if (!displayText || !url) throw new TypeError('addUrl(displayText, url) requires both values');
|
|
56
|
+
this._buttons.push({ text: displayText, url, useWebview });
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
addReply(displayText, id) {
|
|
61
|
+
if (!displayText || !id) throw new TypeError('addReply(displayText, id) requires both values');
|
|
62
|
+
this._buttons.push({ text: displayText, id });
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
addReminder(displayText, id, options = {}) {
|
|
67
|
+
if (!displayText || !id) throw new TypeError('addReminder(displayText, id) requires both values');
|
|
68
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
69
|
+
throw new TypeError('addReminder options must be an object');
|
|
70
|
+
}
|
|
71
|
+
this._buttons.push({
|
|
72
|
+
name: 'cta_reminder',
|
|
73
|
+
buttonParamsJson: JSON.stringify({ ...options, display_text: displayText, id })
|
|
74
|
+
});
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
addCancelReminder(displayText, id, options = {}) {
|
|
79
|
+
if (!displayText || !id) throw new TypeError('addCancelReminder(displayText, id) requires both values');
|
|
80
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
81
|
+
throw new TypeError('addCancelReminder options must be an object');
|
|
82
|
+
}
|
|
83
|
+
this._buttons.push({
|
|
84
|
+
name: 'cta_cancel_reminder',
|
|
85
|
+
buttonParamsJson: JSON.stringify({ ...options, display_text: displayText, id })
|
|
86
|
+
});
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async toCard() {
|
|
91
|
+
return {
|
|
92
|
+
...this._media,
|
|
93
|
+
title: this._title,
|
|
94
|
+
subtitle: this._subtitle,
|
|
95
|
+
...(this._body ? { text: this._body } : {}),
|
|
96
|
+
...(this._footer ? { footer: this._footer } : {}),
|
|
97
|
+
...(this._buttons.length ? { nativeFlow: [...this._buttons] } : {})
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async send(jid, options = {}) {
|
|
102
|
+
if (typeof this.#socket.sendMessage !== 'function') {
|
|
103
|
+
throw new Error('Socket does not provide sendMessage');
|
|
104
|
+
}
|
|
105
|
+
const card = await this.toCard();
|
|
106
|
+
return this.#socket.sendMessage(jid, card, options);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 X4R1S3 — @x4r1s3/baileys
|
|
3
|
+
*
|
|
4
|
+
* CFC builds and sends a WhatsApp group-history bundle using the socket's
|
|
5
|
+
* native upload and group-message encryption methods.
|
|
6
|
+
*/
|
|
7
|
+
import crypto from 'node:crypto';
|
|
8
|
+
import { deflate } from 'node:zlib';
|
|
9
|
+
import { promisify } from 'node:util';
|
|
10
|
+
import { proto } from '../../WAProto/index.js';
|
|
11
|
+
import { prepareWAMessageMedia } from '../Utils/messages.js';
|
|
12
|
+
|
|
13
|
+
const deflateAsync = promisify(deflate);
|
|
14
|
+
const GROUP_HISTORY_HKDF_INFO = Buffer.from('Group History');
|
|
15
|
+
const GROUP_HISTORY_HMAC_LENGTH = 10;
|
|
16
|
+
|
|
17
|
+
const assertString = (value, name) => {
|
|
18
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
19
|
+
throw new TypeError(`${name} is required`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const assertTimestamp = (value) => {
|
|
24
|
+
const timestamp = Number(value);
|
|
25
|
+
if (!Number.isSafeInteger(timestamp) || timestamp <= 0) {
|
|
26
|
+
throw new TypeError('timestamp must be a positive Unix timestamp in seconds');
|
|
27
|
+
}
|
|
28
|
+
return timestamp;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const encodeGroupHistory = (messages) => {
|
|
32
|
+
const normalizedMessages = messages.map(message => proto.WebMessageInfo.fromObject({
|
|
33
|
+
key: {
|
|
34
|
+
remoteJid: message.key?.remoteJid,
|
|
35
|
+
fromMe: !!message.key?.fromMe,
|
|
36
|
+
id: message.key?.id,
|
|
37
|
+
participant: message.key?.participant || message.participant
|
|
38
|
+
},
|
|
39
|
+
message: message.message,
|
|
40
|
+
messageTimestamp: Number(message.messageTimestamp),
|
|
41
|
+
participant: message.participant || message.key?.participant,
|
|
42
|
+
pushName: message.pushName,
|
|
43
|
+
status: message.status ?? proto.WebMessageInfo.Status.SERVER_ACK
|
|
44
|
+
}));
|
|
45
|
+
return Buffer.from(proto.GroupHistory.encode({ messages: normalizedMessages }).finish());
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const encryptGroupHistory = (plaintext) => {
|
|
49
|
+
const mediaKey = crypto.randomBytes(32);
|
|
50
|
+
const expanded = Buffer.from(crypto.hkdfSync('sha256', mediaKey, Buffer.alloc(0), GROUP_HISTORY_HKDF_INFO, 80));
|
|
51
|
+
const iv = expanded.subarray(0, 16);
|
|
52
|
+
const encryptionKey = expanded.subarray(16, 48);
|
|
53
|
+
const macKey = expanded.subarray(48, 80);
|
|
54
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', encryptionKey, iv);
|
|
55
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
56
|
+
const mac = crypto.createHmac('sha256', macKey).update(iv).update(ciphertext).digest().subarray(0, GROUP_HISTORY_HMAC_LENGTH);
|
|
57
|
+
const encryptedFile = Buffer.concat([ciphertext, mac]);
|
|
58
|
+
return {
|
|
59
|
+
mediaKey,
|
|
60
|
+
fileSha256: crypto.createHash('sha256').update(plaintext).digest(),
|
|
61
|
+
fileEncSha256: crypto.createHash('sha256').update(encryptedFile).digest(),
|
|
62
|
+
encryptedFile
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const decorateMessage = (info, builder) => {
|
|
67
|
+
const methods = {
|
|
68
|
+
addText: (...args) => builder.addText(...args),
|
|
69
|
+
addImage: (...args) => builder.addImage(...args),
|
|
70
|
+
addRaw: (...args) => builder.addRaw(...args),
|
|
71
|
+
addReaction: (emoji, options) => builder.addReaction(info, emoji, options),
|
|
72
|
+
send: (...args) => builder.send(...args)
|
|
73
|
+
};
|
|
74
|
+
for (const [name, method] of Object.entries(methods)) {
|
|
75
|
+
Object.defineProperty(info, name, { value: method, enumerable: false, configurable: true });
|
|
76
|
+
}
|
|
77
|
+
Object.defineProperty(info, 'builder', { value: builder, enumerable: false, configurable: true });
|
|
78
|
+
return info;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** CFC factory for composing group-history shares. */
|
|
82
|
+
export class CFC {
|
|
83
|
+
constructor(sock) {
|
|
84
|
+
if (!sock) throw new TypeError('CFC requires a Baileys socket');
|
|
85
|
+
this.sock = sock;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
builder() {
|
|
89
|
+
return new CFCBuilder(this.sock);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Compose historical messages, upload an encrypted history bundle, and share
|
|
95
|
+
* it with a selected member through the connected Baileys socket.
|
|
96
|
+
*/
|
|
97
|
+
export class CFCBuilder {
|
|
98
|
+
constructor(sock) {
|
|
99
|
+
if (!sock || typeof sock.uploadGroupHistory !== 'function' || typeof sock.sendGroupHistory !== 'function') {
|
|
100
|
+
throw new TypeError('CFCBuilder requires a socket with uploadGroupHistory and sendGroupHistory');
|
|
101
|
+
}
|
|
102
|
+
this.sock = sock;
|
|
103
|
+
this.messages = [];
|
|
104
|
+
this.reactions = [];
|
|
105
|
+
this.byId = new Map();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_quoteContext(quoted) {
|
|
109
|
+
if (!quoted) return undefined;
|
|
110
|
+
if (typeof quoted === 'string') {
|
|
111
|
+
const found = this.byId.get(quoted);
|
|
112
|
+
if (!found) throw new Error(`quoted messageId is not in this builder: ${quoted}`);
|
|
113
|
+
return {
|
|
114
|
+
stanzaId: quoted,
|
|
115
|
+
participant: found.participant,
|
|
116
|
+
quotedMessage: found.message
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const key = quoted.key || {};
|
|
120
|
+
const id = key.id || quoted.id;
|
|
121
|
+
let participant = key.participant || quoted.participant;
|
|
122
|
+
let message = quoted.message;
|
|
123
|
+
if (id && this.byId.has(id)) {
|
|
124
|
+
const found = this.byId.get(id);
|
|
125
|
+
participant ||= found.participant;
|
|
126
|
+
message ||= found.message;
|
|
127
|
+
}
|
|
128
|
+
if (!id || !participant || !message) {
|
|
129
|
+
throw new TypeError('quoted needs id, participant, and message, or a messageId in this builder');
|
|
130
|
+
}
|
|
131
|
+
return { stanzaId: id, participant, quotedMessage: message };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
addRaw({ participant, timestamp, message, fromMe = false, messageId, pushName } = {}) {
|
|
135
|
+
assertString(participant, 'participant');
|
|
136
|
+
const messageTimestamp = assertTimestamp(timestamp);
|
|
137
|
+
if (!message || typeof message !== 'object' || Array.isArray(message)) {
|
|
138
|
+
throw new TypeError('message must be a Proto.IMessage object');
|
|
139
|
+
}
|
|
140
|
+
if ('fromMe' in message || 'participant' in message || 'messageTimestamp' in message) {
|
|
141
|
+
throw new TypeError('fromMe, participant, and messageTimestamp belong in addRaw options');
|
|
142
|
+
}
|
|
143
|
+
const id = messageId || crypto.randomBytes(8).toString('hex').toUpperCase();
|
|
144
|
+
const info = {
|
|
145
|
+
key: { remoteJid: null, fromMe: !!fromMe, id, participant },
|
|
146
|
+
message,
|
|
147
|
+
messageTimestamp,
|
|
148
|
+
participant,
|
|
149
|
+
pushName,
|
|
150
|
+
status: proto.WebMessageInfo.Status.SERVER_ACK
|
|
151
|
+
};
|
|
152
|
+
this.messages.push(info);
|
|
153
|
+
this.byId.set(id, info);
|
|
154
|
+
return decorateMessage(info, this);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
addText(text, { participant, timestamp, fromMe = false, messageId, pushName, quoted = null } = {}) {
|
|
158
|
+
if (typeof text !== 'string') throw new TypeError('text must be a string');
|
|
159
|
+
const message = { extendedTextMessage: { text } };
|
|
160
|
+
if (quoted) message.extendedTextMessage.contextInfo = this._quoteContext(quoted);
|
|
161
|
+
return this.addRaw({ participant, timestamp, fromMe, messageId, pushName, message });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async addImage(source, { participant, timestamp, fromMe = false, messageId, pushName, caption, quoted = null } = {}) {
|
|
165
|
+
assertString(participant, 'participant');
|
|
166
|
+
assertTimestamp(timestamp);
|
|
167
|
+
if (source == null) throw new TypeError('image source is required');
|
|
168
|
+
const isImageHandle = source && typeof source === 'object' && !Buffer.isBuffer(source) && !(source instanceof Uint8Array) && (source.directPath || source.url);
|
|
169
|
+
const prepared = isImageHandle
|
|
170
|
+
? source
|
|
171
|
+
: (await prepareWAMessageMedia({ image: source }, {
|
|
172
|
+
upload: this.sock.waUploadToServer,
|
|
173
|
+
logger: this.sock.logger
|
|
174
|
+
}))?.imageMessage;
|
|
175
|
+
if (!prepared) throw new Error('Could not prepare group-history image');
|
|
176
|
+
const imageMessage = { ...prepared };
|
|
177
|
+
if (typeof caption === 'string') imageMessage.caption = caption;
|
|
178
|
+
if (quoted) imageMessage.contextInfo = { ...(imageMessage.contextInfo || {}), ...this._quoteContext(quoted) };
|
|
179
|
+
return this.addRaw({
|
|
180
|
+
participant,
|
|
181
|
+
timestamp,
|
|
182
|
+
fromMe,
|
|
183
|
+
messageId,
|
|
184
|
+
pushName,
|
|
185
|
+
message: { imageMessage }
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
addReaction(target, emoji, { participant, timestamp, fromMe = false, messageId, pushName } = {}) {
|
|
190
|
+
if (typeof emoji !== 'string' || !emoji) throw new TypeError('emoji must be a non-empty string');
|
|
191
|
+
assertString(participant, 'participant');
|
|
192
|
+
const messageTimestamp = assertTimestamp(timestamp);
|
|
193
|
+
const info = typeof target === 'string' ? this.byId.get(target) : target;
|
|
194
|
+
if (!info || !info.key?.id) throw new TypeError('reaction target must be a message in this builder');
|
|
195
|
+
this.reactions.push({
|
|
196
|
+
participant,
|
|
197
|
+
timestamp: messageTimestamp,
|
|
198
|
+
fromMe: !!fromMe,
|
|
199
|
+
messageId: messageId || crypto.randomBytes(8).toString('hex').toUpperCase(),
|
|
200
|
+
pushName,
|
|
201
|
+
message: {
|
|
202
|
+
reactionMessage: {
|
|
203
|
+
key: {
|
|
204
|
+
remoteJid: null,
|
|
205
|
+
fromMe: !!info.key.fromMe,
|
|
206
|
+
id: info.key.id,
|
|
207
|
+
participant: info.participant
|
|
208
|
+
},
|
|
209
|
+
text: emoji,
|
|
210
|
+
senderTimestampMs: messageTimestamp * 1000
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
return decorateMessage(info, this);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
build() {
|
|
218
|
+
return [...this.messages];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
materialize(groupJid) {
|
|
222
|
+
assertString(groupJid, 'groupJid');
|
|
223
|
+
return [...this.messages].reverse().map(message => ({
|
|
224
|
+
...message,
|
|
225
|
+
key: { ...message.key, remoteJid: groupJid }
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async send(groupJid, targetJid) {
|
|
230
|
+
assertString(groupJid, 'groupJid');
|
|
231
|
+
assertString(targetJid, 'targetJid');
|
|
232
|
+
if (!this.messages.length) throw new Error('Cannot send an empty group-history bundle');
|
|
233
|
+
|
|
234
|
+
const messages = this.materialize(groupJid);
|
|
235
|
+
const reactions = this.reactions.map(reaction => ({
|
|
236
|
+
...reaction,
|
|
237
|
+
key: { ...reaction.key, remoteJid: groupJid },
|
|
238
|
+
message: {
|
|
239
|
+
...reaction.message,
|
|
240
|
+
reactionMessage: {
|
|
241
|
+
...reaction.message.reactionMessage,
|
|
242
|
+
key: { ...reaction.message.reactionMessage.key, remoteJid: groupJid }
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}));
|
|
246
|
+
const allMessages = [...messages, ...reactions];
|
|
247
|
+
const encoded = encodeGroupHistory(allMessages);
|
|
248
|
+
const compressed = await deflateAsync(encoded);
|
|
249
|
+
const encrypted = encryptGroupHistory(compressed);
|
|
250
|
+
const mediaKeyTimestamp = Math.floor(Date.now() / 1000);
|
|
251
|
+
const uploaded = await this.sock.uploadGroupHistory(encrypted.encryptedFile, encrypted.fileEncSha256);
|
|
252
|
+
if (!uploaded?.directPath) throw new Error('Group-history upload returned no direct path');
|
|
253
|
+
|
|
254
|
+
const timestamps = allMessages.map(message => Number(message.messageTimestamp)).filter(timestamp => timestamp > 0);
|
|
255
|
+
const oldestTimestamp = timestamps.length ? Math.min(...timestamps) : mediaKeyTimestamp;
|
|
256
|
+
const media = {
|
|
257
|
+
mimetype: 'application/protobuf',
|
|
258
|
+
fileSha256: encrypted.fileSha256,
|
|
259
|
+
mediaKey: encrypted.mediaKey,
|
|
260
|
+
fileEncSha256: encrypted.fileEncSha256,
|
|
261
|
+
directPath: uploaded.directPath,
|
|
262
|
+
mediaKeyTimestamp
|
|
263
|
+
};
|
|
264
|
+
const metadata = {
|
|
265
|
+
historyReceivers: [targetJid],
|
|
266
|
+
nonHistoryReceivers: [],
|
|
267
|
+
messageCount: messages.length,
|
|
268
|
+
oldestMessageTimestampInWindow: oldestTimestamp,
|
|
269
|
+
oldestMessageTimestampInBundle: oldestTimestamp
|
|
270
|
+
};
|
|
271
|
+
const result = await this.sock.sendGroupHistory(groupJid, targetJid, { media, metadata });
|
|
272
|
+
return {
|
|
273
|
+
...result,
|
|
274
|
+
group: groupJid,
|
|
275
|
+
target: targetJid,
|
|
276
|
+
messages: messages.length,
|
|
277
|
+
reactions: reactions.length,
|
|
278
|
+
media,
|
|
279
|
+
metadata,
|
|
280
|
+
encodedBytes: encoded.length,
|
|
281
|
+
compressedBytes: compressed.length
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 X4R1S3x — @X4R1S3/baileys
|
|
3
|
+
*/
|
|
4
|
+
const MAX_CARDS = 10;
|
|
5
|
+
|
|
6
|
+
export class Carousel {
|
|
7
|
+
#socket;
|
|
8
|
+
|
|
9
|
+
static MAX_CARDS = MAX_CARDS;
|
|
10
|
+
|
|
11
|
+
constructor(socket) {
|
|
12
|
+
if (!socket) throw new Error('Socket is required');
|
|
13
|
+
this.#socket = socket;
|
|
14
|
+
this._cards = [];
|
|
15
|
+
this._body = '';
|
|
16
|
+
this._footer = '';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setBody(body) {
|
|
20
|
+
if (typeof body !== 'string') throw new TypeError('Body must be a string');
|
|
21
|
+
this._body = body;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setFooter(footer) {
|
|
26
|
+
if (typeof footer !== 'string') throw new TypeError('Footer must be a string');
|
|
27
|
+
this._footer = footer;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
addCard(cardOrCards) {
|
|
32
|
+
const cards = Array.isArray(cardOrCards) ? cardOrCards : [cardOrCards];
|
|
33
|
+
for (const [index, card] of cards.entries()) {
|
|
34
|
+
if (!card || typeof card !== 'object' || Array.isArray(card)) {
|
|
35
|
+
throw new TypeError(`Carousel card ${index + 1} must be an object`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (this._cards.length + cards.length > MAX_CARDS) {
|
|
39
|
+
throw new Error(`Carousel supports at most ${MAX_CARDS} cards`);
|
|
40
|
+
}
|
|
41
|
+
this._cards.push(...cards);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
clearCards() {
|
|
46
|
+
this._cards = [];
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
countCards() {
|
|
51
|
+
return this._cards.length;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getCards() {
|
|
55
|
+
return [...this._cards];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
validate() {
|
|
59
|
+
const errors = [];
|
|
60
|
+
if (!this._cards.length) errors.push('Add at least one card');
|
|
61
|
+
if (this._cards.length > MAX_CARDS) errors.push(`Maximum is ${MAX_CARDS} cards`);
|
|
62
|
+
for (const [index, card] of this._cards.entries()) {
|
|
63
|
+
const hasMedia = !!(card.image || card.video || card.product);
|
|
64
|
+
if (!hasMedia) errors.push(`Card ${index + 1} requires image, video, or product media`);
|
|
65
|
+
}
|
|
66
|
+
return { ok: errors.length === 0, errors, warnings: [] };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async send(jid, options = {}) {
|
|
70
|
+
const validation = this.validate();
|
|
71
|
+
if (!validation.ok) throw new Error(`Carousel.validate failed:\n- ${validation.errors.join('\n- ')}`);
|
|
72
|
+
if (typeof this.#socket.sendCarousel !== 'function') {
|
|
73
|
+
throw new Error('Socket does not provide sendCarousel; use a compatible X4R1S3 socket');
|
|
74
|
+
}
|
|
75
|
+
return this.#socket.sendCarousel(jid, this._cards, {
|
|
76
|
+
...options,
|
|
77
|
+
text: options.text ?? this._body,
|
|
78
|
+
footer: options.footer ?? this._footer
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ShellTear
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CODY V2 same-socket VoIP orchestration for Plogme.
|
|
3
|
+
*
|
|
4
|
+
* This controller does not create a second Baileys client or authentication
|
|
5
|
+
* directory. It wraps the existing Plogme VoipClient and keeps the call
|
|
6
|
+
* lifecycle in the same CODY WhatsApp session.
|
|
7
|
+
*
|
|
8
|
+
* Based on @crysnovax/baileys by Crysnovax.
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from 'node:events';
|
|
11
|
+
import { VoipClient } from './index.mjs';
|
|
12
|
+
|
|
13
|
+
const asBoolean = (value, fallback = false) => {
|
|
14
|
+
if (value === undefined || value === null || value === '') return fallback;
|
|
15
|
+
return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export class AstralenaV3VoipClient extends EventEmitter {
|
|
19
|
+
#client;
|
|
20
|
+
#config;
|
|
21
|
+
#bound = false;
|
|
22
|
+
#activeCalls = new Map();
|
|
23
|
+
#onIncoming;
|
|
24
|
+
#onEnded;
|
|
25
|
+
|
|
26
|
+
constructor(config = {}) {
|
|
27
|
+
super();
|
|
28
|
+
if (!config.sock) {
|
|
29
|
+
throw new Error('AstralenaV3VoipClient requires the existing Astralena socket as { sock }.');
|
|
30
|
+
}
|
|
31
|
+
this.#config = { ...config };
|
|
32
|
+
this.#client = config.client || new VoipClient(config);
|
|
33
|
+
this.#onIncoming = info => this.#handleIncoming(info);
|
|
34
|
+
this.#onEnded = info => this.#handleEnded(info);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get client() { return this.#client; }
|
|
38
|
+
get activeCalls() { return [...this.#activeCalls.values()]; }
|
|
39
|
+
|
|
40
|
+
async connect() {
|
|
41
|
+
this.#client.on('incomingCall', this.#onIncoming);
|
|
42
|
+
this.#client.on('incomingCallEnded', this.#onEnded);
|
|
43
|
+
this.#bound = true;
|
|
44
|
+
try {
|
|
45
|
+
await this.#client.connect();
|
|
46
|
+
this.emit('ready', { client: this.#client });
|
|
47
|
+
return this;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
this.disconnectListeners();
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async disconnect() {
|
|
55
|
+
this.disconnectListeners();
|
|
56
|
+
await this.#client.disconnect();
|
|
57
|
+
this.#activeCalls.clear();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
disconnectListeners() {
|
|
61
|
+
if (!this.#bound) return;
|
|
62
|
+
this.#client.off('incomingCall', this.#onIncoming);
|
|
63
|
+
this.#client.off('incomingCallEnded', this.#onEnded);
|
|
64
|
+
this.#bound = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
answerIncomingCall(callId, options = {}) {
|
|
68
|
+
return this.#client.answerIncomingCall(callId, options);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
rejectIncomingCall(callId) {
|
|
72
|
+
return this.#client.rejectIncomingCall(callId);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#handleIncoming(info) {
|
|
76
|
+
this.emit('incomingCall', info);
|
|
77
|
+
const autoAnswer = this.#config.autoAnswer ?? asBoolean(process.env.ASTRALENAV3_VOIP_AUTO_ANSWER, false);
|
|
78
|
+
if (!autoAnswer || info?.isVideo && this.#config.answerVideo !== true) return;
|
|
79
|
+
void this.answerIncomingCall(info.callId, this.#config.answerOptions || {})
|
|
80
|
+
.then(call => {
|
|
81
|
+
this.#activeCalls.set(info.callId, call);
|
|
82
|
+
call.once('ended', () => this.#activeCalls.delete(info.callId));
|
|
83
|
+
this.emit('callAnswered', call, info);
|
|
84
|
+
})
|
|
85
|
+
.catch(error => this.emit('answerError', error, info));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#handleEnded(info) {
|
|
89
|
+
if (info?.callId) this.#activeCalls.delete(info.callId);
|
|
90
|
+
this.emit('incomingCallEnded', info);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const createAstralenaV3VoipClient = config => new AstralenaV3VoipClient(config);
|
|
95
|
+
|
|
96
|
+
export { asBoolean as astralenaV3Boolean };
|