@genuxofficial/baileys 1.0.0 → 3.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/README.md +5 -1
- package/WAProto/WAProto.proto +1385 -96
- package/WAProto/index.d.ts +19244 -2787
- package/WAProto/index.js +138202 -74217
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -0
- package/lib/Socket/business.d.ts +47 -17
- package/lib/Socket/chats.d.ts +10 -9
- package/lib/Socket/chats.js +36 -16
- package/lib/Socket/groups.d.ts +12 -11
- package/lib/Socket/groups.js +16 -3
- package/lib/Socket/index.d.ts +52 -22
- package/lib/Socket/messages-recv.d.ts +46 -15
- package/lib/Socket/messages-recv.js +158 -23
- package/lib/Socket/messages-send.d.ts +39 -11
- package/lib/Socket/messages-send.js +188 -22
- package/lib/Socket/newsletter.d.ts +137 -0
- package/lib/Socket/newsletter.js +256 -0
- package/lib/Socket/socket.d.ts +4 -4
- package/lib/Socket/socket.js +25 -12
- package/lib/Socket/usync.d.ts +5 -5
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +14 -5
- package/lib/Types/Chat.d.ts +6 -5
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +6 -0
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +150 -12
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +8 -3
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +3 -4
- package/lib/Utils/business.js +15 -3
- package/lib/Utils/chat-utils.js +0 -16
- package/lib/Utils/crypto.js +6 -4
- package/lib/Utils/decode-wa-message.d.ts +5 -3
- package/lib/Utils/decode-wa-message.js +158 -31
- package/lib/Utils/event-buffer.js +1 -3
- package/lib/Utils/generics.d.ts +3 -2
- package/lib/Utils/generics.js +16 -36
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +14 -5
- package/lib/Utils/messages-media.js +130 -69
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +309 -57
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.js +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +44 -13
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/decode.js +3 -2
- package/lib/WABinary/encode.js +13 -5
- package/lib/WABinary/generic-utils.d.ts +3 -5
- package/lib/WABinary/generic-utils.js +34 -19
- package/lib/WABinary/jid-utils.d.ts +12 -3
- package/lib/WABinary/jid-utils.js +29 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +21 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +10 -0
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +20 -12
- package/WAProto/GenerateStatics.sh +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
package/lib/WABinary/decode.js
CHANGED
@@ -146,10 +146,11 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
146
146
|
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
147
147
|
};
|
148
148
|
const readAdJid = () => {
|
149
|
-
const
|
149
|
+
const rawDomainType = readByte();
|
150
|
+
const domainType = Number(rawDomainType);
|
150
151
|
const device = readByte();
|
151
152
|
const user = readString(readByte());
|
152
|
-
return (0, jid_utils_1.jidEncode)(user,
|
153
|
+
return (0, jid_utils_1.jidEncode)(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
|
153
154
|
};
|
154
155
|
const readString = (tag) => {
|
155
156
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
package/lib/WABinary/encode.js
CHANGED
@@ -143,7 +143,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
143
143
|
}
|
144
144
|
};
|
145
145
|
const isNibble = (str) => {
|
146
|
-
if (str.length > TAGS.PACKED_MAX) {
|
146
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
147
147
|
return false;
|
148
148
|
}
|
149
149
|
for (const char of str) {
|
@@ -155,7 +155,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
155
155
|
return true;
|
156
156
|
};
|
157
157
|
const isHex = (str) => {
|
158
|
-
if (str.length > TAGS.PACKED_MAX) {
|
158
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
159
159
|
return false;
|
160
160
|
}
|
161
161
|
for (const char of str) {
|
@@ -167,6 +167,10 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
167
167
|
return true;
|
168
168
|
};
|
169
169
|
const writeString = (str) => {
|
170
|
+
if (str === undefined || str === null) {
|
171
|
+
pushByte(TAGS.LIST_EMPTY);
|
172
|
+
return;
|
173
|
+
}
|
170
174
|
const tokenIndex = TOKEN_MAP[str];
|
171
175
|
if (tokenIndex) {
|
172
176
|
if (typeof tokenIndex.dict === 'number') {
|
@@ -202,7 +206,10 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
202
206
|
pushInt16(listSize);
|
203
207
|
}
|
204
208
|
};
|
205
|
-
|
209
|
+
if (!tag) {
|
210
|
+
throw new Error('Invalid node: tag cannot be undefined');
|
211
|
+
}
|
212
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
|
206
213
|
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
207
214
|
writeString(tag);
|
208
215
|
for (const key of validAttributes) {
|
@@ -219,8 +226,9 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
219
226
|
pushBytes(content);
|
220
227
|
}
|
221
228
|
else if (Array.isArray(content)) {
|
222
|
-
|
223
|
-
|
229
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
230
|
+
writeListStart(validContent.length);
|
231
|
+
for (const item of validContent) {
|
224
232
|
encodeBinaryNodeInner(item, opts, buffer);
|
225
233
|
}
|
226
234
|
}
|
@@ -7,10 +7,8 @@ export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => Bina
|
|
7
7
|
export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
|
8
8
|
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
|
9
9
|
export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
|
10
|
-
export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
|
10
|
+
export declare const getBinaryNodeChildUInt: (node: BinaryNode | undefined, childTag: string, length: number) => number | undefined;
|
11
11
|
export declare const assertNodeErrorFree: (node: BinaryNode) => void;
|
12
|
-
export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) =>
|
13
|
-
[_: string]: string;
|
14
|
-
};
|
12
|
+
export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => Record<string, string>;
|
15
13
|
export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
|
16
|
-
export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number):
|
14
|
+
export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'] | undefined, i?: number): string | undefined;
|
@@ -5,23 +5,21 @@ const boom_1 = require("@hapi/boom");
|
|
5
5
|
const WAProto_1 = require("../../WAProto");
|
6
6
|
// some extra useful utilities
|
7
7
|
const getBinaryNodeChildren = (node, childTag) => {
|
8
|
-
if (Array.isArray(node
|
9
|
-
return
|
8
|
+
if (!node || !Array.isArray(node.content)) {
|
9
|
+
return [];
|
10
10
|
}
|
11
|
-
return
|
11
|
+
return node.content.filter((item) => item.tag === childTag);
|
12
12
|
};
|
13
13
|
exports.getBinaryNodeChildren = getBinaryNodeChildren;
|
14
14
|
const getAllBinaryNodeChildren = ({ content }) => {
|
15
|
-
|
16
|
-
return content;
|
17
|
-
}
|
18
|
-
return [];
|
15
|
+
return Array.isArray(content) ? content : [];
|
19
16
|
};
|
20
17
|
exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
|
21
18
|
const getBinaryNodeChild = (node, childTag) => {
|
22
|
-
if (Array.isArray(node
|
23
|
-
return
|
19
|
+
if (!node || !Array.isArray(node.content)) {
|
20
|
+
return undefined;
|
24
21
|
}
|
22
|
+
return node.content.find(item => item.tag === childTag);
|
25
23
|
};
|
26
24
|
exports.getBinaryNodeChild = getBinaryNodeChild;
|
27
25
|
const getBinaryNodeChildBuffer = (node, childTag) => {
|
@@ -30,6 +28,7 @@ const getBinaryNodeChildBuffer = (node, childTag) => {
|
|
30
28
|
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
31
29
|
return child;
|
32
30
|
}
|
31
|
+
return undefined;
|
33
32
|
};
|
34
33
|
exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
|
35
34
|
const getBinaryNodeChildString = (node, childTag) => {
|
@@ -41,6 +40,7 @@ const getBinaryNodeChildString = (node, childTag) => {
|
|
41
40
|
else if (typeof child === 'string') {
|
42
41
|
return child;
|
43
42
|
}
|
43
|
+
return undefined;
|
44
44
|
};
|
45
45
|
exports.getBinaryNodeChildString = getBinaryNodeChildString;
|
46
46
|
const getBinaryNodeChildUInt = (node, childTag, length) => {
|
@@ -48,31 +48,45 @@ const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
48
48
|
if (buff) {
|
49
49
|
return bufferToUInt(buff, length);
|
50
50
|
}
|
51
|
+
return undefined;
|
51
52
|
};
|
52
53
|
exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
|
53
54
|
const assertNodeErrorFree = (node) => {
|
55
|
+
var _a, _b;
|
54
56
|
const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
|
55
57
|
if (errNode) {
|
56
|
-
throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', {
|
58
|
+
throw new boom_1.Boom(((_a = errNode.attrs) === null || _a === void 0 ? void 0 : _a.text) || 'Unknown error', {
|
59
|
+
data: Number((_b = errNode.attrs) === null || _b === void 0 ? void 0 : _b.code) || 0
|
60
|
+
});
|
57
61
|
}
|
58
62
|
};
|
59
63
|
exports.assertNodeErrorFree = assertNodeErrorFree;
|
60
64
|
const reduceBinaryNodeToDictionary = (node, tag) => {
|
61
65
|
const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
|
62
|
-
|
63
|
-
|
66
|
+
return nodes.reduce((dict, { attrs }) => {
|
67
|
+
const name = (attrs === null || attrs === void 0 ? void 0 : attrs.name) || (attrs === null || attrs === void 0 ? void 0 : attrs.config_code);
|
68
|
+
const value = (attrs === null || attrs === void 0 ? void 0 : attrs.value) || (attrs === null || attrs === void 0 ? void 0 : attrs.config_value);
|
69
|
+
if (name && value) {
|
70
|
+
dict[name] = value;
|
71
|
+
}
|
64
72
|
return dict;
|
65
73
|
}, {});
|
66
|
-
return dict;
|
67
74
|
};
|
68
75
|
exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
|
69
76
|
const getBinaryNodeMessages = ({ content }) => {
|
77
|
+
if (!Array.isArray(content)) {
|
78
|
+
return [];
|
79
|
+
}
|
70
80
|
const msgs = [];
|
71
|
-
|
72
|
-
|
73
|
-
|
81
|
+
for (const item of content) {
|
82
|
+
if (item.tag === 'message' && item.content) {
|
83
|
+
try {
|
74
84
|
msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content));
|
75
85
|
}
|
86
|
+
catch (error) {
|
87
|
+
// Handle decode error if needed
|
88
|
+
console.error('Failed to decode message:', error);
|
89
|
+
}
|
76
90
|
}
|
77
91
|
}
|
78
92
|
return msgs;
|
@@ -88,7 +102,7 @@ function bufferToUInt(e, t) {
|
|
88
102
|
const tabs = (n) => '\t'.repeat(n);
|
89
103
|
function binaryNodeToString(node, i = 0) {
|
90
104
|
if (!node) {
|
91
|
-
return
|
105
|
+
return undefined;
|
92
106
|
}
|
93
107
|
if (typeof node === 'string') {
|
94
108
|
return tabs(i) + node;
|
@@ -100,10 +114,11 @@ function binaryNodeToString(node, i = 0) {
|
|
100
114
|
return node.map((x) => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
|
101
115
|
}
|
102
116
|
const children = binaryNodeToString(node.content, i + 1);
|
103
|
-
const
|
117
|
+
const attrs = Object.entries(node.attrs || {})
|
104
118
|
.filter(([, v]) => v !== undefined)
|
105
119
|
.map(([k, v]) => `${k}='${v}'`)
|
106
|
-
.join(' ')
|
120
|
+
.join(' ');
|
121
|
+
const tag = `<${node.tag}${attrs ? ' ' + attrs : ''}`;
|
107
122
|
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
108
123
|
return tag + content;
|
109
124
|
}
|
@@ -3,7 +3,8 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
|
|
3
3
|
export declare const SERVER_JID = "server@c.us";
|
4
4
|
export declare const PSA_WID = "0@c.us";
|
5
5
|
export declare const STORIES_JID = "status@broadcast";
|
6
|
-
export
|
6
|
+
export declare const META_AI_JID = "13135550002@c.us";
|
7
|
+
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter' | 'bot';
|
7
8
|
export type JidWithDevice = {
|
8
9
|
user: string;
|
9
10
|
device?: number;
|
@@ -12,20 +13,28 @@ export type FullJid = JidWithDevice & {
|
|
12
13
|
server: JidServer;
|
13
14
|
domainType?: number;
|
14
15
|
};
|
16
|
+
/**
|
17
|
+
Get Meta Ai's Jid
|
18
|
+
@shizothetechie
|
19
|
+
*/
|
20
|
+
export declare const getBotJid: (jid: string) => string;
|
15
21
|
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
|
16
22
|
export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
|
17
23
|
/** is the jid a user */
|
18
24
|
export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
|
25
|
+
/** is the jid a bot (Meta Ai) */
|
26
|
+
export declare const isJidMetaAI: (jid: string | undefined) => boolean | undefined;
|
19
27
|
/** is the jid a user */
|
20
28
|
export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
|
21
29
|
/** is the jid a group */
|
22
30
|
export declare const isLidUser: (jid: string | undefined) => boolean | undefined;
|
23
31
|
/** is the jid a broadcast */
|
24
32
|
export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
|
33
|
+
/** is the jid a newsletter */
|
34
|
+
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
25
35
|
/** is the jid a group */
|
26
36
|
export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
|
27
37
|
/** is the jid the status broadcast */
|
28
38
|
export declare const isJidStatusBroadcast: (jid: string) => boolean;
|
29
|
-
|
30
|
-
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
39
|
+
export declare const isJidBot: (jid: string | undefined) => boolean | "" | undefined;
|
31
40
|
export declare const jidNormalizedUser: (jid: string | undefined) => string;
|
@@ -1,11 +1,30 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.jidNormalizedUser = exports.
|
3
|
+
exports.jidNormalizedUser = exports.isJidBot = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.getBotJid = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
4
4
|
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
5
5
|
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
6
6
|
exports.SERVER_JID = 'server@c.us';
|
7
7
|
exports.PSA_WID = '0@c.us';
|
8
8
|
exports.STORIES_JID = 'status@broadcast';
|
9
|
+
exports.META_AI_JID = '13135550002@c.us';
|
10
|
+
/**
|
11
|
+
Get Meta Ai's Jid
|
12
|
+
@shizothetechie
|
13
|
+
*/
|
14
|
+
const getBotJid = (jid) => {
|
15
|
+
const BOT_MAP = new Map([["867051314767696", "13135550002"], ["1061492271844689", "13135550005"], ["245886058483988", "13135550009"], ["3509905702656130", "13135550012"], ["1059680132034576", "13135550013"], ["715681030623646", "13135550014"], ["1644971366323052", "13135550015"], ["582497970646566", "13135550019"], ["645459357769306", "13135550022"], ["294997126699143", "13135550023"], ["1522631578502677", "13135550027"], ["719421926276396", "13135550030"], ["1788488635002167", "13135550031"], ["24232338603080193", "13135550033"], ["689289903143209", "13135550035"], ["871626054177096", "13135550039"], ["362351902849370", "13135550042"], ["1744617646041527", "13135550043"], ["893887762270570", "13135550046"], ["1155032702135830", "13135550047"], ["333931965993883", "13135550048"], ["853748013058752", "13135550049"], ["1559068611564819", "13135550053"], ["890487432705716", "13135550054"], ["240254602395494", "13135550055"], ["1578420349663261", "13135550062"], ["322908887140421", "13135550065"], ["3713961535514771", "13135550067"], ["997884654811738", "13135550070"], ["403157239387035", "13135550081"], ["535242369074963", "13135550082"], ["946293427247659", "13135550083"], ["3664707673802291", "13135550084"], ["1821827464894892", "13135550085"], ["1760312477828757", "13135550086"], ["439480398712216", "13135550087"], ["1876735582800984", "13135550088"], ["984025089825661", "13135550089"], ["1001336351558186", "13135550090"], ["3739346336347061", "13135550091"], ["3632749426974980", "13135550092"], ["427864203481615", "13135550093"], ["1434734570493055", "13135550094"], ["992873449225921", "13135550095"], ["813087747426445", "13135550096"], ["806369104931434", "13135550098"], ["1220982902403148", "13135550099"], ["1365893374104393", "13135550100"], ["686482033622048", "13135550200"], ["1454999838411253", "13135550201"], ["718584497008509", "13135550202"], ["743520384213443", "13135550301"], ["1147715789823789", "13135550302"], ["1173034540372201", "13135550303"], ["974785541030953", "13135550304"], ["1122200255531507", "13135550305"], ["899669714813162", "13135550306"], ["631880108970650", "13135550307"], ["435816149330026", "13135550308"], ["1368717161184556", "13135550309"], ["7849963461784891", "13135550310"], ["3609617065968984", "13135550312"], ["356273980574602", "13135550313"], ["1043447920539760", "13135550314"], ["1052764336525346", "13135550315"], ["2631118843732685", "13135550316"], ["510505411332176", "13135550317"], ["1945664239227513", "13135550318"], ["1518594378764656", "13135550319"], ["1378821579456138", "13135550320"], ["490214716896013", "13135550321"], ["1028577858870699", "13135550322"], ["308915665545959", "13135550323"], ["845884253678900", "13135550324"], ["995031308616442", "13135550325"], ["2787365464763437", "13135550326"], ["1532790990671645", "13135550327"], ["302617036180485", "13135550328"], ["723376723197227", "13135550329"], ["8393570407377966", "13135550330"], ["1931159970680725", "13135550331"], ["401073885688605", "13135550332"], ["2234478453565422", "13135550334"], ["814748673882312", "13135550335"], ["26133635056281592", "13135550336"], ["1439804456676119", "13135550337"], ["889851503172161", "13135550338"], ["1018283232836879", "13135550339"], ["1012781386779537", "13135559000"], ["823280953239532", "13135559001"], ["1597090934573334", "13135559002"], ["485965054020343", "13135559003"], ["1033381648363446", "13135559004"], ["491802010206446", "13135559005"], ["1017139033184870", "13135559006"], ["499638325922174", "13135559008"], ["468946335863664", "13135559009"], ["1570389776875816", "13135559010"], ["1004342694328995", "13135559011"], ["1012240323971229", "13135559012"], ["392171787222419", "13135559013"], ["952081212945019", "13135559016"], ["444507875070178", "13135559017"], ["1274819440594668", "13135559018"], ["1397041101147050", "13135559019"], ["425657699872640", "13135559020"], ["532292852562549", "13135559021"], ["705863241720292", "13135559022"], ["476449815183959", "13135559023"], ["488071553854222", "13135559024"], ["468693832665397", "13135559025"], ["517422564037340", "13135559026"], ["819805466613825", "13135559027"], ["1847708235641382", "13135559028"], ["716282970644228", "13135559029"], ["521655380527741", "13135559030"], ["476193631941905", "13135559031"], ["485600497445562", "13135559032"], ["440217235683910", "13135559033"], ["523342446758478", "13135559034"], ["514784864360240", "13135559035"], ["505790121814530", "13135559036"], ["420008964419580", "13135559037"], ["492141680204555", "13135559038"], ["388462787271952", "13135559039"], ["423473920752072", "13135559040"], ["489574180468229", "13135559041"], ["432360635854105", "13135559042"], ["477878201669248", "13135559043"], ["351656951234045", "13135559044"], ["430178036732582", "13135559045"], ["434537312944552", "13135559046"], ["1240614300631808", "13135559047"], ["473135945605128", "13135559048"], ["423669800729310", "13135559049"], ["3685666705015792", "13135559050"], ["504196509016638", "13135559051"], ["346844785189449", "13135559052"], ["504823088911074", "13135559053"], ["402669415797083", "13135559054"], ["490939640234431", "13135559055"], ["875124128063715", "13135559056"], ["468788962654605", "13135559057"], ["562386196354570", "13135559058"], ["372159285928791", "13135559059"], ["531017479591050", "13135559060"], ["1328873881401826", "13135559061"], ["1608363646390484", "13135559062"], ["1229628561554232", "13135559063"], ["348802211530364", "13135559064"], ["3708535859420184", "13135559065"], ["415517767742187", "13135559066"], ["479330341612638", "13135559067"], ["480785414723083", "13135559068"], ["387299107507991", "13135559069"], ["333389813188944", "13135559070"], ["391794130316996", "13135559071"], ["457893470576314", "13135559072"], ["435550496166469", "13135559073"], ["1620162702100689", "13135559074"], ["867491058616043", "13135559075"], ["816224117357759", "13135559076"], ["334065176362830", "13135559077"], ["489973170554709", "13135559078"], ["473060669049665", "13135559079"], ["1221505815643060", "13135559080"], ["889000703096359", "13135559081"], ["475235961979883", "13135559082"], ["3434445653519934", "13135559084"], ["524503026827421", "13135559085"], ["1179639046403856", "13135559086"], ["471563305859144", "13135559087"], ["533896609192881", "13135559088"], ["365443583168041", "13135559089"], ["836082305329393", "13135559090"], ["1056787705969916", "13135559091"], ["503312598958357", "13135559092"], ["3718606738453460", "13135559093"], ["826066052850902", "13135559094"], ["1033611345091888", "13135559095"], ["3868390816783240", "13135559096"], ["7462677740498860", "13135559097"], ["436288576108573", "13135559098"], ["1047559746718900", "13135559099"], ["1099299455255491", "13135559100"], ["1202037301040633", "13135559101"], ["1720619402074074", "13135559102"], ["1030422235101467", "13135559103"], ["827238979523502", "13135559104"], ["1516443722284921", "13135559105"], ["1174442747196709", "13135559106"], ["1653165225503842", "13135559107"], ["1037648777635013", "13135559108"], ["551617757299900", "13135559109"], ["1158813558718726", "13135559110"], ["2463236450542262", "13135559111"], ["1550393252501466", "13135559112"], ["2057065188042796", "13135559113"], ["506163028760735", "13135559114"], ["2065249100538481", "13135559115"], ["1041382867195858", "13135559116"], ["886500209499603", "13135559117"], ["1491615624892655", "13135559118"], ["486563697299617", "13135559119"], ["1175736513679463", "13135559120"], ["491811473512352", "13165550064"]]);
|
16
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
17
|
+
if (sepIdx < 0) {
|
18
|
+
return jid;
|
19
|
+
}
|
20
|
+
const server = jid.slice(sepIdx + 1);
|
21
|
+
if (server !== 'bot')
|
22
|
+
return jid;
|
23
|
+
const user = jid.slice(0, sepIdx);
|
24
|
+
const mappedNumber = BOT_MAP.get(user);
|
25
|
+
return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
|
26
|
+
};
|
27
|
+
exports.getBotJid = getBotJid;
|
9
28
|
const jidEncode = (user, server, device, agent) => {
|
10
29
|
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
|
11
30
|
};
|
@@ -33,6 +52,9 @@ const areJidsSameUser = (jid1, jid2) => {
|
|
33
52
|
return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
|
34
53
|
};
|
35
54
|
exports.areJidsSameUser = areJidsSameUser;
|
55
|
+
/** is the jid a bot (Meta Ai) */
|
56
|
+
const isJidMetaAI = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
|
57
|
+
exports.isJidMetaAI = isJidMetaAI;
|
36
58
|
/** is the jid a user */
|
37
59
|
const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
|
38
60
|
exports.isJidUser = isJidUser;
|
@@ -42,15 +64,18 @@ exports.isLidUser = isLidUser;
|
|
42
64
|
/** is the jid a broadcast */
|
43
65
|
const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
|
44
66
|
exports.isJidBroadcast = isJidBroadcast;
|
67
|
+
/** is the jid a newsletter */
|
68
|
+
const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
|
69
|
+
exports.isJidNewsletter = isJidNewsletter;
|
45
70
|
/** is the jid a group */
|
46
71
|
const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
|
47
72
|
exports.isJidGroup = isJidGroup;
|
48
73
|
/** is the jid the status broadcast */
|
49
74
|
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
50
75
|
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
51
|
-
|
52
|
-
const
|
53
|
-
exports.
|
76
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
77
|
+
const isJidBot = (jid) => (jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us'));
|
78
|
+
exports.isJidBot = isJidBot;
|
54
79
|
const jidNormalizedUser = (jid) => {
|
55
80
|
const result = (0, exports.jidDecode)(jid);
|
56
81
|
if (!result) {
|
@@ -27,29 +27,38 @@ class USyncDeviceProtocol {
|
|
27
27
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
28
28
|
const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list');
|
29
29
|
const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list');
|
30
|
-
if (Array.isArray(deviceListNode
|
31
|
-
for (const
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
if (deviceListNode && Array.isArray(deviceListNode.content)) {
|
31
|
+
for (const item of deviceListNode.content) {
|
32
|
+
if (item.tag === 'device' && item.attrs) {
|
33
|
+
const id = Number(item.attrs.id) || 0;
|
34
|
+
const keyIndexValue = item.attrs['key-index']
|
35
|
+
? Number(item.attrs['key-index'])
|
36
|
+
: undefined;
|
37
|
+
const isHosted = item.attrs['is_hosted'] === 'true';
|
35
38
|
deviceList.push({
|
36
39
|
id,
|
37
|
-
keyIndex,
|
38
|
-
isHosted
|
40
|
+
keyIndex: keyIndexValue,
|
41
|
+
isHosted
|
39
42
|
});
|
40
43
|
}
|
41
44
|
}
|
42
45
|
}
|
43
|
-
if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
|
46
|
+
if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list' && keyIndexNode.attrs) {
|
47
|
+
const timestamp = Number(keyIndexNode.attrs['ts']) || 0;
|
48
|
+
const expectedTimestamp = keyIndexNode.attrs['expected_ts']
|
49
|
+
? Number(keyIndexNode.attrs['expected_ts'])
|
50
|
+
: undefined;
|
44
51
|
keyIndex = {
|
45
|
-
timestamp
|
46
|
-
signedKeyIndex: keyIndexNode
|
47
|
-
|
52
|
+
timestamp,
|
53
|
+
signedKeyIndex: keyIndexNode.content instanceof Uint8Array
|
54
|
+
? keyIndexNode.content
|
55
|
+
: undefined,
|
56
|
+
expectedTimestamp
|
48
57
|
};
|
49
58
|
}
|
50
59
|
}
|
51
60
|
return {
|
52
|
-
deviceList,
|
61
|
+
deviceList: deviceList.length > 0 ? deviceList : undefined,
|
53
62
|
keyIndex
|
54
63
|
};
|
55
64
|
}
|
@@ -16,13 +16,13 @@ class USyncStatusProtocol {
|
|
16
16
|
return null;
|
17
17
|
}
|
18
18
|
parser(node) {
|
19
|
-
var _a;
|
19
|
+
var _a, _b, _c;
|
20
20
|
if (node.tag === 'status') {
|
21
21
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
22
|
-
let status = node === null || node === void 0 ? void 0 : node.content.toString();
|
22
|
+
let status = (_b = (_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : null;
|
23
23
|
const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
|
24
24
|
if (!status) {
|
25
|
-
if (+((
|
25
|
+
if (+((_c = node.attrs) === null || _c === void 0 ? void 0 : _c.code) === 401) {
|
26
26
|
status = '';
|
27
27
|
}
|
28
28
|
else {
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
3
|
+
import { USyncUser } from '../USyncUser';
|
4
|
+
export type BotProfileCommand = {
|
5
|
+
name: string;
|
6
|
+
description: string;
|
7
|
+
};
|
8
|
+
export type BotProfileInfo = {
|
9
|
+
jid: string;
|
10
|
+
name: string;
|
11
|
+
attributes: string;
|
12
|
+
description: string;
|
13
|
+
category: string;
|
14
|
+
isDefault: boolean;
|
15
|
+
prompts: string[];
|
16
|
+
personaId: string;
|
17
|
+
commands: BotProfileCommand[];
|
18
|
+
commandsDescription: string;
|
19
|
+
};
|
20
|
+
export declare class USyncBotProfileProtocol implements USyncQueryProtocol {
|
21
|
+
name: string;
|
22
|
+
getQueryElement(): BinaryNode;
|
23
|
+
getUserElement(user: USyncUser): BinaryNode;
|
24
|
+
parser(node: BinaryNode): BotProfileInfo;
|
25
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.USyncBotProfileProtocol = void 0;
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
5
|
+
class USyncBotProfileProtocol {
|
6
|
+
constructor() {
|
7
|
+
this.name = 'bot';
|
8
|
+
}
|
9
|
+
getQueryElement() {
|
10
|
+
return {
|
11
|
+
tag: 'bot',
|
12
|
+
attrs: {},
|
13
|
+
content: [{ tag: 'profile', attrs: { v: '1' } }]
|
14
|
+
};
|
15
|
+
}
|
16
|
+
getUserElement(user) {
|
17
|
+
return {
|
18
|
+
tag: 'bot',
|
19
|
+
attrs: {},
|
20
|
+
content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
|
21
|
+
};
|
22
|
+
}
|
23
|
+
parser(node) {
|
24
|
+
const botNode = (0, WABinary_1.getBinaryNodeChild)(node, 'bot');
|
25
|
+
const profile = (0, WABinary_1.getBinaryNodeChild)(botNode, 'profile');
|
26
|
+
const commandsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'commands');
|
27
|
+
const promptsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'prompts');
|
28
|
+
const commands = [];
|
29
|
+
const prompts = [];
|
30
|
+
for (const command of (0, WABinary_1.getBinaryNodeChildren)(commandsNode, 'command')) {
|
31
|
+
commands.push({
|
32
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(command, 'name'),
|
33
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(command, 'description')
|
34
|
+
});
|
35
|
+
}
|
36
|
+
for (const prompt of (0, WABinary_1.getBinaryNodeChildren)(promptsNode, 'prompt')) {
|
37
|
+
prompts.push(`${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'emoji')} ${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'text')}`);
|
38
|
+
}
|
39
|
+
return {
|
40
|
+
isDefault: !!(0, WABinary_1.getBinaryNodeChild)(profile, 'default'),
|
41
|
+
jid: node.attrs.jid,
|
42
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(profile, 'name'),
|
43
|
+
attributes: (0, WABinary_1.getBinaryNodeChildString)(profile, 'attributes'),
|
44
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(profile, 'description'),
|
45
|
+
category: (0, WABinary_1.getBinaryNodeChildString)(profile, 'category'),
|
46
|
+
personaId: profile.attrs['persona_id'],
|
47
|
+
commandsDescription: (0, WABinary_1.getBinaryNodeChildString)(commandsNode, 'description'),
|
48
|
+
commands,
|
49
|
+
prompts
|
50
|
+
};
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.USyncBotProfileProtocol = USyncBotProfileProtocol;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
3
|
+
export declare class USyncLIDProtocol implements USyncQueryProtocol {
|
4
|
+
name: string;
|
5
|
+
getQueryElement(): BinaryNode;
|
6
|
+
getUserElement(): null;
|
7
|
+
parser(node: BinaryNode): string | null;
|
8
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.USyncLIDProtocol = void 0;
|
4
|
+
class USyncLIDProtocol {
|
5
|
+
constructor() {
|
6
|
+
this.name = 'lid';
|
7
|
+
}
|
8
|
+
getQueryElement() {
|
9
|
+
return {
|
10
|
+
tag: 'lid',
|
11
|
+
attrs: {},
|
12
|
+
};
|
13
|
+
}
|
14
|
+
getUserElement() {
|
15
|
+
return null;
|
16
|
+
}
|
17
|
+
parser(node) {
|
18
|
+
if (node.tag === 'lid') {
|
19
|
+
return node.attrs.val;
|
20
|
+
}
|
21
|
+
return null;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
exports.USyncLIDProtocol = USyncLIDProtocol;
|
@@ -2,6 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.USyncQuery = void 0;
|
4
4
|
const WABinary_1 = require("../WABinary");
|
5
|
+
const UsyncBotProfileProtocol_1 = require("./Protocols/UsyncBotProfileProtocol");
|
6
|
+
const UsyncLIDProtocol_1 = require("./Protocols/UsyncLIDProtocol");
|
5
7
|
const Protocols_1 = require("./Protocols");
|
6
8
|
class USyncQuery {
|
7
9
|
constructor() {
|
@@ -75,5 +77,13 @@ class USyncQuery {
|
|
75
77
|
this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol());
|
76
78
|
return this;
|
77
79
|
}
|
80
|
+
withBotProfileProtocol() {
|
81
|
+
this.protocols.push(new UsyncBotProfileProtocol_1.USyncBotProfileProtocol());
|
82
|
+
return this;
|
83
|
+
}
|
84
|
+
withLIDProtocol() {
|
85
|
+
this.protocols.push(new UsyncLIDProtocol_1.USyncLIDProtocol());
|
86
|
+
return this;
|
87
|
+
}
|
78
88
|
}
|
79
89
|
exports.USyncQuery = USyncQuery;
|
@@ -3,8 +3,10 @@ export declare class USyncUser {
|
|
3
3
|
lid: string;
|
4
4
|
phone: string;
|
5
5
|
type: string;
|
6
|
+
personaId: string;
|
6
7
|
withId(id: string): this;
|
7
8
|
withLid(lid: string): this;
|
8
9
|
withPhone(phone: string): this;
|
9
10
|
withType(type: string): this;
|
11
|
+
withPersonaId(personaId: string): this;
|
10
12
|
}
|
package/lib/WAUSync/USyncUser.js
CHANGED
package/lib/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { proto } from '../WAProto';
|
1
2
|
import makeWASocket from './Socket';
|
2
3
|
export * from '../WAProto';
|
3
4
|
export * from './Utils';
|
@@ -8,5 +9,5 @@ export * from './WABinary';
|
|
8
9
|
export * from './WAM';
|
9
10
|
export * from './WAUSync';
|
10
11
|
export type WASocket = ReturnType<typeof makeWASocket>;
|
11
|
-
export { makeWASocket };
|
12
|
+
export { makeWASocket, proto };
|
12
13
|
export default makeWASocket;
|
package/lib/index.js
CHANGED
@@ -17,7 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
18
18
|
};
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
-
exports.makeWASocket = void 0;
|
20
|
+
exports.proto = exports.makeWASocket = void 0;
|
21
|
+
const WAProto_1 = require("../WAProto");
|
22
|
+
Object.defineProperty(exports, "proto", { enumerable: true, get: function () { return WAProto_1.proto; } });
|
21
23
|
const Socket_1 = __importDefault(require("./Socket"));
|
22
24
|
exports.makeWASocket = Socket_1.default;
|
23
25
|
__exportStar(require("../WAProto"), exports);
|