@aseppxyzz12/baileys 1.1.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/LICENSE +25 -0
- package/README.md +2579 -0
- package/WAProto/AICommon/AICommon.js +19396 -0
- package/WAProto/AICommon/AICommon.proto +820 -0
- package/WAProto/Adv/Adv.js +1137 -0
- package/WAProto/Adv/Adv.proto +42 -0
- package/WAProto/BotMetadata/BotMetadata.js +8975 -0
- package/WAProto/BotMetadata/BotMetadata.proto +484 -0
- package/WAProto/Cert/Cert.js +893 -0
- package/WAProto/Cert/Cert.proto +30 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
- package/WAProto/CompanionReg/CompanionReg.js +2457 -0
- package/WAProto/CompanionReg/CompanionReg.proto +103 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
- package/WAProto/E2E/E2E.js +78728 -0
- package/WAProto/E2E/E2E.proto +1970 -0
- package/WAProto/Ephemeral/Ephemeral.js +143 -0
- package/WAProto/Ephemeral/Ephemeral.proto +7 -0
- package/WAProto/HistorySync/HistorySync.js +95931 -0
- package/WAProto/HistorySync/HistorySync.proto +229 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
- package/WAProto/MmsRetry/MmsRetry.js +310 -0
- package/WAProto/MmsRetry/MmsRetry.proto +19 -0
- package/WAProto/Protocol/Protocol.js +399 -0
- package/WAProto/Protocol/Protocol.proto +22 -0
- package/WAProto/Reporting/Reporting.js +535 -0
- package/WAProto/Reporting/Reporting.proto +22 -0
- package/WAProto/ServerSync/ServerSync.js +1830 -0
- package/WAProto/ServerSync/ServerSync.proto +70 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
- package/WAProto/SyncAction/SyncAction.js +17424 -0
- package/WAProto/SyncAction/SyncAction.proto +663 -0
- package/WAProto/UserPassword/UserPassword.js +544 -0
- package/WAProto/UserPassword/UserPassword.proto +28 -0
- package/WAProto/VnameCert/VnameCert.js +1466 -0
- package/WAProto/VnameCert/VnameCert.proto +65 -0
- package/WAProto/Wa6/Wa6.js +4601 -0
- package/WAProto/Wa6/Wa6.proto +241 -0
- package/WAProto/Web/Web.js +90819 -0
- package/WAProto/Web/Web.proto +605 -0
- package/WAProto/index.js +30 -0
- package/engine-requirements.js +9 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -0
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Function/Download/tiktok.js +19 -0
- package/lib/Function/Tools/bypass.js +19 -0
- package/lib/Function/index.js +13 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -0
- package/lib/Signal/Group/group-session-builder.js +46 -0
- package/lib/Signal/Group/group_cipher.js +104 -0
- package/lib/Signal/Group/index.js +42 -0
- package/lib/Signal/Group/keyhelper.js +21 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +78 -0
- package/lib/Signal/Group/sender-key-name.js +49 -0
- package/lib/Signal/Group/sender-key-record.js +45 -0
- package/lib/Signal/Group/sender-key-state.js +100 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +364 -0
- package/lib/Signal/lid-mapping.js +164 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +31 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.js +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +67 -0
- package/lib/Socket/business.js +291 -0
- package/lib/Socket/chats.js +874 -0
- package/lib/Socket/community.js +454 -0
- package/lib/Socket/dugong.js +658 -0
- package/lib/Socket/groups.js +357 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.js +1509 -0
- package/lib/Socket/messages-send.js +1505 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +171 -0
- package/lib/Socket/registration.js +167 -0
- package/lib/Socket/rich-content.js +279 -0
- package/lib/Socket/socket.js +905 -0
- package/lib/Socket/username.js +157 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +37 -0
- package/lib/Store/keyed-db.js +114 -0
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.js +423 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +26 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +4 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +40 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +9 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +60 -0
- package/lib/Utils/auth-utils.js +256 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/bot-toolkit.js +455 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +904 -0
- package/lib/Utils/companion-reg-client-utils.js +41 -0
- package/lib/Utils/crypto.js +144 -0
- package/lib/Utils/decode-wa-message.js +305 -0
- package/lib/Utils/event-buffer.js +555 -0
- package/lib/Utils/generics.js +411 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/identity-change-handler.js +53 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/link-preview.js +76 -0
- package/lib/Utils/logger.js +4 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +289 -0
- package/lib/Utils/message-retry-manager.js +134 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.js +1908 -0
- package/lib/Utils/noise-handler.js +157 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +814 -0
- package/lib/Utils/reporting-utils.js +264 -0
- package/lib/Utils/signal.js +183 -0
- package/lib/Utils/stanza-ack.js +36 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.js +167 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1308 -0
- package/lib/WABinary/decode.js +233 -0
- package/lib/WABinary/encode.js +212 -0
- package/lib/WABinary/generic-utils.js +124 -0
- package/lib/WABinary/index.js +36 -0
- package/lib/WABinary/jid-utils.js +101 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +12 -0
- package/lib/WAM/constants.js +20491 -0
- package/lib/WAM/encode.js +148 -0
- package/lib/WAM/index.js +34 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +38 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.js +33 -0
- package/lib/WAUSync/index.js +34 -0
- package/lib/index.js +113 -0
- package/lib/messages-send.js +1496 -0
- package/package.json +100 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
FLAG_BYTE: FLAG_BYTE,
|
|
5
|
+
FLAG_EVENT: FLAG_EVENT,
|
|
6
|
+
FLAG_EXTENDED: FLAG_EXTENDED,
|
|
7
|
+
FLAG_FIELD: FLAG_FIELD,
|
|
8
|
+
FLAG_GLOBAL: FLAG_GLOBAL,
|
|
9
|
+
WEB_EVENTS: WEB_EVENTS,
|
|
10
|
+
WEB_GLOBALS: WEB_GLOBALS,
|
|
11
|
+
} = require("./constants");
|
|
12
|
+
const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
|
|
13
|
+
const encodeWAM = (binaryInfo) => {
|
|
14
|
+
binaryInfo.buffer = [];
|
|
15
|
+
encodeWAMHeader(binaryInfo);
|
|
16
|
+
encodeEvents(binaryInfo);
|
|
17
|
+
const totalSize = binaryInfo.buffer.map((a) => a.length).reduce((a, b) => a + b);
|
|
18
|
+
const buffer = Buffer.alloc(totalSize);
|
|
19
|
+
let offset = 0;
|
|
20
|
+
for (const buffer_ of binaryInfo.buffer) {
|
|
21
|
+
buffer_.copy(buffer, offset);
|
|
22
|
+
offset += buffer_.length;
|
|
23
|
+
}
|
|
24
|
+
return buffer;
|
|
25
|
+
};
|
|
26
|
+
function encodeWAMHeader(binaryInfo) {
|
|
27
|
+
const headerBuffer = Buffer.alloc(8);
|
|
28
|
+
headerBuffer.write("WAM", 0, "utf8");
|
|
29
|
+
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
|
|
30
|
+
headerBuffer.writeUInt8(1, 4);
|
|
31
|
+
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
|
|
32
|
+
headerBuffer.writeUInt8(0, 7);
|
|
33
|
+
binaryInfo.buffer.push(headerBuffer);
|
|
34
|
+
}
|
|
35
|
+
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
36
|
+
for (const [key, _value] of Object.entries(globals)) {
|
|
37
|
+
const id = WEB_GLOBALS.find((a) => a?.name === key).id;
|
|
38
|
+
let value = _value;
|
|
39
|
+
if (typeof value === "boolean") {
|
|
40
|
+
value = value ? 1 : 0;
|
|
41
|
+
}
|
|
42
|
+
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function encodeEvents(binaryInfo) {
|
|
46
|
+
for (const [name, { props: props, globals: globals }] of binaryInfo.events.map(
|
|
47
|
+
(a) => Object.entries(a)[0]
|
|
48
|
+
)) {
|
|
49
|
+
encodeGlobalAttributes(binaryInfo, globals);
|
|
50
|
+
const event = WEB_EVENTS.find((a) => a.name === name);
|
|
51
|
+
const props_ = Object.entries(props);
|
|
52
|
+
let extended = false;
|
|
53
|
+
for (const [, value] of props_) {
|
|
54
|
+
extended || (extended = value !== null);
|
|
55
|
+
}
|
|
56
|
+
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
|
|
57
|
+
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
|
|
58
|
+
for (let i = 0; i < props_.length; i++) {
|
|
59
|
+
const [key, _value] = props_[i];
|
|
60
|
+
const id = event.props[key]?.[0];
|
|
61
|
+
extended = i < props_.length - 1;
|
|
62
|
+
let value = _value;
|
|
63
|
+
if (typeof value === "boolean") {
|
|
64
|
+
value = value ? 1 : 0;
|
|
65
|
+
}
|
|
66
|
+
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
|
|
67
|
+
binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function serializeData(key, value, flag) {
|
|
72
|
+
const bufferLength = getHeaderBitLength(key);
|
|
73
|
+
let buffer;
|
|
74
|
+
let offset = 0;
|
|
75
|
+
if (value === null) {
|
|
76
|
+
if (flag === FLAG_GLOBAL) {
|
|
77
|
+
buffer = Buffer.alloc(bufferLength);
|
|
78
|
+
offset = serializeHeader(buffer, offset, key, flag);
|
|
79
|
+
return buffer;
|
|
80
|
+
}
|
|
81
|
+
} else if (typeof value === "number" && Number.isInteger(value)) {
|
|
82
|
+
if (value === 0 || value === 1) {
|
|
83
|
+
buffer = Buffer.alloc(bufferLength);
|
|
84
|
+
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
|
|
85
|
+
return buffer;
|
|
86
|
+
} else if (-128 <= value && value < 128) {
|
|
87
|
+
buffer = Buffer.alloc(bufferLength + 1);
|
|
88
|
+
offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
|
|
89
|
+
buffer.writeInt8(value, offset);
|
|
90
|
+
return buffer;
|
|
91
|
+
} else if (-32768 <= value && value < 32768) {
|
|
92
|
+
buffer = Buffer.alloc(bufferLength + 2);
|
|
93
|
+
offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
|
|
94
|
+
buffer.writeInt16LE(value, offset);
|
|
95
|
+
return buffer;
|
|
96
|
+
} else if (-2147483648 <= value && value < 2147483648) {
|
|
97
|
+
buffer = Buffer.alloc(bufferLength + 4);
|
|
98
|
+
offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
|
|
99
|
+
buffer.writeInt32LE(value, offset);
|
|
100
|
+
return buffer;
|
|
101
|
+
} else {
|
|
102
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
103
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
104
|
+
buffer.writeDoubleLE(value, offset);
|
|
105
|
+
return buffer;
|
|
106
|
+
}
|
|
107
|
+
} else if (typeof value === "number") {
|
|
108
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
109
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
110
|
+
buffer.writeDoubleLE(value, offset);
|
|
111
|
+
return buffer;
|
|
112
|
+
} else if (typeof value === "string") {
|
|
113
|
+
const utf8Bytes = Buffer.byteLength(value, "utf8");
|
|
114
|
+
if (utf8Bytes < 256) {
|
|
115
|
+
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
|
|
116
|
+
offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
|
|
117
|
+
buffer.writeUint8(utf8Bytes, offset++);
|
|
118
|
+
} else if (utf8Bytes < 65536) {
|
|
119
|
+
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
|
|
120
|
+
offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
|
|
121
|
+
buffer.writeUInt16LE(utf8Bytes, offset);
|
|
122
|
+
offset += 2;
|
|
123
|
+
} else {
|
|
124
|
+
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
|
|
125
|
+
offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
|
|
126
|
+
buffer.writeUInt32LE(utf8Bytes, offset);
|
|
127
|
+
offset += 4;
|
|
128
|
+
}
|
|
129
|
+
buffer.write(value, offset, "utf8");
|
|
130
|
+
return buffer;
|
|
131
|
+
}
|
|
132
|
+
throw "missing";
|
|
133
|
+
}
|
|
134
|
+
function serializeHeader(buffer, offset, key, flag) {
|
|
135
|
+
if (key < 256) {
|
|
136
|
+
buffer.writeUInt8(flag, offset);
|
|
137
|
+
offset += 1;
|
|
138
|
+
buffer.writeUInt8(key, offset);
|
|
139
|
+
offset += 1;
|
|
140
|
+
} else {
|
|
141
|
+
buffer.writeUInt8(flag | FLAG_BYTE, offset);
|
|
142
|
+
offset += 1;
|
|
143
|
+
buffer.writeUInt16LE(key, offset);
|
|
144
|
+
offset += 2;
|
|
145
|
+
}
|
|
146
|
+
return offset;
|
|
147
|
+
}
|
|
148
|
+
module.exports = { encodeWAM: encodeWAM };
|
package/lib/WAM/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./constants"), exports);
|
|
33
|
+
__exportStar(require("./encode"), exports);
|
|
34
|
+
__exportStar(require("./BinaryInfo"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
5
|
+
getBinaryNodeChildren: getBinaryNodeChildren,
|
|
6
|
+
getBinaryNodeChildString: getBinaryNodeChildString,
|
|
7
|
+
} = require("../../WABinary");
|
|
8
|
+
class USyncBotProfileProtocol {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.name = "bot";
|
|
11
|
+
}
|
|
12
|
+
getQueryElement() {
|
|
13
|
+
return {
|
|
14
|
+
tag: "bot",
|
|
15
|
+
attrs: {},
|
|
16
|
+
content: [{ tag: "profile", attrs: { v: "1" } }],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
getUserElement(user) {
|
|
20
|
+
return {
|
|
21
|
+
tag: "bot",
|
|
22
|
+
attrs: {},
|
|
23
|
+
content: [{ tag: "profile", attrs: { persona_id: user.personaId } }],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
parser(node) {
|
|
27
|
+
const botNode = getBinaryNodeChild(node, "bot");
|
|
28
|
+
const profile = getBinaryNodeChild(botNode, "profile");
|
|
29
|
+
const commandsNode = getBinaryNodeChild(profile, "commands");
|
|
30
|
+
const promptsNode = getBinaryNodeChild(profile, "prompts");
|
|
31
|
+
const commands = [];
|
|
32
|
+
const prompts = [];
|
|
33
|
+
if (commandsNode) {
|
|
34
|
+
for (const command of getBinaryNodeChildren(commandsNode, "command")) {
|
|
35
|
+
commands.push({
|
|
36
|
+
name: getBinaryNodeChildString(command, "name") || "",
|
|
37
|
+
description: getBinaryNodeChildString(command, "description") || "",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (promptsNode) {
|
|
42
|
+
for (const prompt of getBinaryNodeChildren(promptsNode, "prompt")) {
|
|
43
|
+
prompts.push(
|
|
44
|
+
`${getBinaryNodeChildString(prompt, "emoji") || ""} ${getBinaryNodeChildString(prompt, "text") || ""}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
isDefault: !!getBinaryNodeChild(profile, "default"),
|
|
50
|
+
jid: node.attrs.jid,
|
|
51
|
+
name: getBinaryNodeChildString(profile, "name") || "",
|
|
52
|
+
attributes: getBinaryNodeChildString(profile, "attributes") || "",
|
|
53
|
+
description: getBinaryNodeChildString(profile, "description") || "",
|
|
54
|
+
category: getBinaryNodeChildString(profile, "category") || "",
|
|
55
|
+
personaId: profile.attrs["persona_id"] || "",
|
|
56
|
+
commandsDescription: getBinaryNodeChildString(commandsNode, "description") || "",
|
|
57
|
+
commands: commands,
|
|
58
|
+
prompts: prompts,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
module.exports = { USyncBotProfileProtocol: USyncBotProfileProtocol };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
|
|
4
|
+
class USyncContactProtocol {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = "contact";
|
|
7
|
+
}
|
|
8
|
+
getQueryElement() {
|
|
9
|
+
return { tag: "contact", attrs: {} };
|
|
10
|
+
}
|
|
11
|
+
getUserElement(user) {
|
|
12
|
+
if (user.phone) {
|
|
13
|
+
return { tag: "contact", attrs: {}, content: user.phone };
|
|
14
|
+
}
|
|
15
|
+
if (user.username) {
|
|
16
|
+
return {
|
|
17
|
+
tag: "contact",
|
|
18
|
+
attrs: {
|
|
19
|
+
username: user.username,
|
|
20
|
+
...(user.usernameKey ? { pin: user.usernameKey } : {}),
|
|
21
|
+
...(user.lid ? { lid: user.lid } : {}),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (user.type) {
|
|
26
|
+
return { tag: "contact", attrs: { type: user.type } };
|
|
27
|
+
}
|
|
28
|
+
return { tag: "contact", attrs: {} };
|
|
29
|
+
}
|
|
30
|
+
parser(node) {
|
|
31
|
+
if (node.tag === "contact") {
|
|
32
|
+
assertNodeErrorFree(node);
|
|
33
|
+
return node?.attrs?.type === "in";
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
module.exports = { USyncContactProtocol: USyncContactProtocol };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
5
|
+
assertNodeErrorFree: assertNodeErrorFree,
|
|
6
|
+
} = require("../../WABinary");
|
|
7
|
+
class USyncDeviceProtocol {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.name = "devices";
|
|
10
|
+
}
|
|
11
|
+
getQueryElement() {
|
|
12
|
+
return { tag: "devices", attrs: { version: "2" } };
|
|
13
|
+
}
|
|
14
|
+
getUserElement() {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
parser(node) {
|
|
18
|
+
const deviceList = [];
|
|
19
|
+
let keyIndex = undefined;
|
|
20
|
+
if (node.tag === "devices") {
|
|
21
|
+
assertNodeErrorFree(node);
|
|
22
|
+
const deviceListNode = getBinaryNodeChild(node, "device-list");
|
|
23
|
+
const keyIndexNode = getBinaryNodeChild(node, "key-index-list");
|
|
24
|
+
if (Array.isArray(deviceListNode?.content)) {
|
|
25
|
+
for (const { tag: tag, attrs: attrs } of deviceListNode.content) {
|
|
26
|
+
const id = +attrs.id;
|
|
27
|
+
const keyIndex = +attrs["key-index"];
|
|
28
|
+
if (tag === "device") {
|
|
29
|
+
deviceList.push({
|
|
30
|
+
id: id,
|
|
31
|
+
keyIndex: keyIndex,
|
|
32
|
+
isHosted: !!(attrs["is_hosted"] && attrs["is_hosted"] === "true"),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (keyIndexNode?.tag === "key-index-list") {
|
|
38
|
+
keyIndex = {
|
|
39
|
+
timestamp: +keyIndexNode.attrs["ts"],
|
|
40
|
+
signedKeyIndex: keyIndexNode?.content,
|
|
41
|
+
expectedTimestamp: keyIndexNode.attrs["expected_ts"]
|
|
42
|
+
? +keyIndexNode.attrs["expected_ts"]
|
|
43
|
+
: undefined,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { deviceList: deviceList, keyIndex: keyIndex };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
module.exports = { USyncDeviceProtocol: USyncDeviceProtocol };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
|
|
4
|
+
class USyncDisappearingModeProtocol {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = "disappearing_mode";
|
|
7
|
+
}
|
|
8
|
+
getQueryElement() {
|
|
9
|
+
return { tag: "disappearing_mode", attrs: {} };
|
|
10
|
+
}
|
|
11
|
+
getUserElement() {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
parser(node) {
|
|
15
|
+
if (node.tag === "disappearing_mode") {
|
|
16
|
+
assertNodeErrorFree(node);
|
|
17
|
+
const duration = +node?.attrs?.duration;
|
|
18
|
+
const setAt = new Date(+(node?.attrs?.t || 0) * 1e3);
|
|
19
|
+
return { duration: duration, setAt: setAt };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
module.exports = {
|
|
24
|
+
USyncDisappearingModeProtocol: USyncDisappearingModeProtocol,
|
|
25
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class USyncLIDProtocol {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "lid";
|
|
6
|
+
}
|
|
7
|
+
getQueryElement() {
|
|
8
|
+
return { tag: "lid", attrs: {} };
|
|
9
|
+
}
|
|
10
|
+
getUserElement(user) {
|
|
11
|
+
if (user.lid) {
|
|
12
|
+
return { tag: "lid", attrs: { jid: user.lid } };
|
|
13
|
+
} else {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
parser(node) {
|
|
18
|
+
if (node.tag === "lid") {
|
|
19
|
+
return node.attrs.val;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
module.exports = { USyncLIDProtocol: USyncLIDProtocol };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
|
|
4
|
+
class USyncStatusProtocol {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = "status";
|
|
7
|
+
}
|
|
8
|
+
getQueryElement() {
|
|
9
|
+
return { tag: "status", attrs: {} };
|
|
10
|
+
}
|
|
11
|
+
getUserElement() {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
parser(node) {
|
|
15
|
+
if (node.tag === "status") {
|
|
16
|
+
assertNodeErrorFree(node);
|
|
17
|
+
let status = node?.content?.toString() || null;
|
|
18
|
+
const setAt = new Date(+(node?.attrs?.t || 0) * 1e3);
|
|
19
|
+
if (!status) {
|
|
20
|
+
if (+node.attrs?.code === 401) {
|
|
21
|
+
status = "";
|
|
22
|
+
} else {
|
|
23
|
+
status = null;
|
|
24
|
+
}
|
|
25
|
+
} else if (typeof status === "string" && status.length === 0) {
|
|
26
|
+
status = null;
|
|
27
|
+
}
|
|
28
|
+
return { status: status, setAt: setAt };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
module.exports = { USyncStatusProtocol: USyncStatusProtocol };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Ported & adapted from PouCode fork for AsepXyz Baileys
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
|
|
5
|
+
class USyncUsernameProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = "username";
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return { tag: "username", attrs: {} };
|
|
11
|
+
}
|
|
12
|
+
getUserElement(user) {
|
|
13
|
+
void user;
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
parser(node) {
|
|
17
|
+
if (node.tag === "username") {
|
|
18
|
+
assertNodeErrorFree(node);
|
|
19
|
+
return typeof node.content === "string" ? node.content : null;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
module.exports = { USyncUsernameProtocol: USyncUsernameProtocol };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./USyncBotProfileProtocol"), exports);
|
|
33
|
+
__exportStar(require("./USyncContactProtocol"), exports);
|
|
34
|
+
__exportStar(require("./USyncDeviceProtocol"), exports);
|
|
35
|
+
__exportStar(require("./USyncLIDProtocol"), exports);
|
|
36
|
+
__exportStar(require("./USyncStatusProtocol"), exports);
|
|
37
|
+
__exportStar(require("./USyncDisappearingModeProtocol"), exports);
|
|
38
|
+
__exportStar(require("./USyncUsernameProtocol"), exports);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { getBinaryNodeChild: getBinaryNodeChild } = require("../WABinary");
|
|
4
|
+
const {
|
|
5
|
+
USyncLIDProtocol: USyncLIDProtocol,
|
|
6
|
+
USyncDeviceProtocol: USyncDeviceProtocol,
|
|
7
|
+
USyncContactProtocol: USyncContactProtocol,
|
|
8
|
+
USyncStatusProtocol: USyncStatusProtocol,
|
|
9
|
+
USyncBotProfileProtocol: USyncBotProfileProtocol,
|
|
10
|
+
USyncDisappearingModeProtocol: USyncDisappearingModeProtocol,
|
|
11
|
+
USyncUsernameProtocol: USyncUsernameProtocol,
|
|
12
|
+
} = require("./Protocols");
|
|
13
|
+
class USyncQuery {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.protocols = [];
|
|
16
|
+
this.users = [];
|
|
17
|
+
this.context = "interactive";
|
|
18
|
+
this.mode = "query";
|
|
19
|
+
}
|
|
20
|
+
withMode(mode) {
|
|
21
|
+
this.mode = mode;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
withContext(context) {
|
|
25
|
+
this.context = context;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
withUser(user) {
|
|
29
|
+
this.users.push(user);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
parseUSyncQueryResult(result) {
|
|
33
|
+
if (!result || result.attrs.type !== "result") {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const protocolMap = Object.fromEntries(
|
|
37
|
+
this.protocols.map((protocol) => [protocol.name, protocol.parser])
|
|
38
|
+
);
|
|
39
|
+
const queryResult = { list: [], sideList: [] };
|
|
40
|
+
const usyncNode = getBinaryNodeChild(result, "usync");
|
|
41
|
+
const listNode = usyncNode ? getBinaryNodeChild(usyncNode, "list") : undefined;
|
|
42
|
+
if (listNode?.content && Array.isArray(listNode.content)) {
|
|
43
|
+
queryResult.list = listNode.content.reduce((acc, node) => {
|
|
44
|
+
const id = node?.attrs.jid;
|
|
45
|
+
if (id) {
|
|
46
|
+
const data = Array.isArray(node?.content)
|
|
47
|
+
? Object.fromEntries(
|
|
48
|
+
node.content
|
|
49
|
+
.map((content) => {
|
|
50
|
+
const protocol = content.tag;
|
|
51
|
+
const parser = protocolMap[protocol];
|
|
52
|
+
if (parser) {
|
|
53
|
+
return [protocol, parser(content)];
|
|
54
|
+
} else {
|
|
55
|
+
return [protocol, null];
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
.filter(([, b]) => b !== null)
|
|
59
|
+
)
|
|
60
|
+
: {};
|
|
61
|
+
acc.push({ ...data, id: id });
|
|
62
|
+
}
|
|
63
|
+
return acc;
|
|
64
|
+
}, []);
|
|
65
|
+
}
|
|
66
|
+
return queryResult;
|
|
67
|
+
}
|
|
68
|
+
withLIDProtocol() {
|
|
69
|
+
this.protocols.push(new USyncLIDProtocol());
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
withDeviceProtocol() {
|
|
73
|
+
this.protocols.push(new USyncDeviceProtocol());
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
withContactProtocol() {
|
|
77
|
+
this.protocols.push(new USyncContactProtocol());
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
withStatusProtocol() {
|
|
81
|
+
this.protocols.push(new USyncStatusProtocol());
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
withBotProfileProtocol() {
|
|
85
|
+
this.protocols.push(new USyncBotProfileProtocol());
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
withDisappearingModeProtocol() {
|
|
89
|
+
this.protocols.push(new USyncDisappearingModeProtocol());
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
withUsernameProtocol() {
|
|
93
|
+
this.protocols.push(new USyncUsernameProtocol());
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
module.exports = { USyncQuery: USyncQuery };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class USyncUser {
|
|
4
|
+
withId(id) {
|
|
5
|
+
this.id = id;
|
|
6
|
+
return this;
|
|
7
|
+
}
|
|
8
|
+
withLid(lid) {
|
|
9
|
+
this.lid = lid;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
withPhone(phone) {
|
|
13
|
+
this.phone = phone;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
withUsername(username) {
|
|
17
|
+
this.username = username;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
withUsernameKey(usernameKey) {
|
|
21
|
+
this.usernameKey = usernameKey;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
withType(type) {
|
|
25
|
+
this.type = type;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
withPersonaId(personaId) {
|
|
29
|
+
this.personaId = personaId;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
module.exports = { USyncUser: USyncUser };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./Protocols"), exports);
|
|
33
|
+
__exportStar(require("./USyncQuery"), exports);
|
|
34
|
+
__exportStar(require("./USyncUser"), exports);
|