@genuxofficial/baileys 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +5 -1
- 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.d.ts +3 -5
- package/lib/Defaults/index.js +7 -6
- package/lib/Signal/libsignal.js +18 -9
- package/lib/Socket/Client/types.d.ts +0 -2
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +65 -37
- package/lib/Socket/chats.d.ts +22 -18
- package/lib/Socket/chats.js +110 -6
- package/lib/Socket/groups.d.ts +30 -26
- package/lib/Socket/groups.js +20 -6
- package/lib/Socket/index.d.ts +66 -38
- package/lib/Socket/messages-recv.d.ts +63 -33
- package/lib/Socket/messages-recv.js +174 -27
- package/lib/Socket/messages-send.d.ts +55 -29
- package/lib/Socket/messages-send.js +190 -26
- package/lib/Socket/newsletter.d.ts +140 -0
- package/lib/Socket/newsletter.js +252 -0
- package/lib/Socket/socket.d.ts +8 -10
- package/lib/Socket/socket.js +26 -13
- package/lib/Socket/usync.d.ts +10 -12
- package/lib/Socket/usync.js +10 -15
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +1 -1
- package/lib/Store/make-in-memory-store.js +14 -5
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -2
- package/lib/Types/Chat.d.ts +7 -0
- package/lib/Types/Contact.d.ts +5 -0
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +7 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +129 -16
- 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 -5
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +2 -1
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +6 -7
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +8 -10
- package/lib/Utils/chat-utils.js +11 -0
- package/lib/Utils/crypto.d.ts +14 -16
- package/lib/Utils/crypto.js +40 -26
- package/lib/Utils/decode-wa-message.d.ts +5 -3
- package/lib/Utils/decode-wa-message.js +171 -29
- package/lib/Utils/event-buffer.js +1 -3
- package/lib/Utils/generics.d.ts +35 -9
- package/lib/Utils/generics.js +93 -27
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +17 -7
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +35 -16
- package/lib/Utils/messages-media.js +168 -43
- package/lib/Utils/messages.d.ts +6 -9
- package/lib/Utils/messages.js +297 -37
- package/lib/Utils/noise-handler.d.ts +5 -7
- package/lib/Utils/process-message.js +2 -3
- package/lib/Utils/use-multi-file-auth-state.js +44 -13
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/decode.d.ts +2 -4
- package/lib/WABinary/decode.js +20 -9
- package/lib/WABinary/encode.d.ts +1 -3
- package/lib/WABinary/encode.js +30 -12
- package/lib/WABinary/generic-utils.d.ts +1 -3
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +9 -4
- package/lib/WABinary/jid-utils.js +25 -4
- package/lib/WAM/BinaryInfo.d.ts +2 -12
- package/lib/WAM/encode.d.ts +1 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- 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 +27 -13
- 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 +59 -57
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -3344
package/lib/WABinary/decode.d.ts
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
4
|
-
export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer
|
5
|
-
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions,
|
2
|
+
export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer<ArrayBufferLike>>;
|
3
|
+
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
|
6
4
|
index: number;
|
7
5
|
}) => BinaryNode;
|
8
6
|
export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
|
package/lib/WABinary/decode.js
CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
36
|
exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
27
37
|
const util_1 = require("util");
|
@@ -146,10 +156,11 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
146
156
|
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
147
157
|
};
|
148
158
|
const readAdJid = () => {
|
149
|
-
const
|
159
|
+
const rawDomainType = readByte();
|
160
|
+
const domainType = Number(rawDomainType);
|
150
161
|
const device = readByte();
|
151
162
|
const user = readString(readByte());
|
152
|
-
return (0, jid_utils_1.jidEncode)(user,
|
163
|
+
return (0, jid_utils_1.jidEncode)(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
|
153
164
|
};
|
154
165
|
const readString = (tag) => {
|
155
166
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
package/lib/WABinary/encode.d.ts
CHANGED
@@ -1,4 +1,2 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
4
|
-
export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions,
|
2
|
+
export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
|
package/lib/WABinary/encode.js
CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
36
|
exports.encodeBinaryNode = void 0;
|
27
37
|
const constants = __importStar(require("./constants"));
|
@@ -143,7 +153,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
143
153
|
}
|
144
154
|
};
|
145
155
|
const isNibble = (str) => {
|
146
|
-
if (str.length > TAGS.PACKED_MAX) {
|
156
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
147
157
|
return false;
|
148
158
|
}
|
149
159
|
for (const char of str) {
|
@@ -155,7 +165,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
155
165
|
return true;
|
156
166
|
};
|
157
167
|
const isHex = (str) => {
|
158
|
-
if (str.length > TAGS.PACKED_MAX) {
|
168
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
159
169
|
return false;
|
160
170
|
}
|
161
171
|
for (const char of str) {
|
@@ -167,6 +177,10 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
167
177
|
return true;
|
168
178
|
};
|
169
179
|
const writeString = (str) => {
|
180
|
+
if (str === undefined || str === null) {
|
181
|
+
pushByte(TAGS.LIST_EMPTY);
|
182
|
+
return;
|
183
|
+
}
|
170
184
|
const tokenIndex = TOKEN_MAP[str];
|
171
185
|
if (tokenIndex) {
|
172
186
|
if (typeof tokenIndex.dict === 'number') {
|
@@ -202,7 +216,10 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
202
216
|
pushInt16(listSize);
|
203
217
|
}
|
204
218
|
};
|
205
|
-
|
219
|
+
if (!tag) {
|
220
|
+
throw new Error('Invalid node: tag cannot be undefined');
|
221
|
+
}
|
222
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
|
206
223
|
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
207
224
|
writeString(tag);
|
208
225
|
for (const key of validAttributes) {
|
@@ -219,8 +236,9 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
219
236
|
pushBytes(content);
|
220
237
|
}
|
221
238
|
else if (Array.isArray(content)) {
|
222
|
-
|
223
|
-
|
239
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
240
|
+
writeListStart(validContent.length);
|
241
|
+
for (const item of validContent) {
|
224
242
|
encodeBinaryNodeInner(item, opts, buffer);
|
225
243
|
}
|
226
244
|
}
|
@@ -1,11 +1,9 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
import { proto } from '../../WAProto';
|
4
2
|
import { BinaryNode } from './types';
|
5
3
|
export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
|
6
4
|
export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
|
7
5
|
export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
|
8
|
-
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
|
6
|
+
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | undefined;
|
9
7
|
export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
|
10
8
|
export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
|
11
9
|
export declare const assertNodeErrorFree: (node: BinaryNode) => void;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
|
4
|
+
exports.binaryNodeToString = binaryNodeToString;
|
4
5
|
const boom_1 = require("@hapi/boom");
|
5
6
|
const WAProto_1 = require("../../WAProto");
|
6
7
|
// some extra useful utilities
|
@@ -107,4 +108,3 @@ function binaryNodeToString(node, i = 0) {
|
|
107
108
|
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
108
109
|
return tag + content;
|
109
110
|
}
|
110
|
-
exports.binaryNodeToString = binaryNodeToString;
|
@@ -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,24 @@ export type FullJid = JidWithDevice & {
|
|
12
13
|
server: JidServer;
|
13
14
|
domainType?: number;
|
14
15
|
};
|
16
|
+
export declare const getBotJid: (jid: string) => string;
|
15
17
|
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
|
16
18
|
export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
|
17
19
|
/** is the jid a user */
|
18
20
|
export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
|
21
|
+
/** is the jid Meta AI */
|
22
|
+
export declare const isJidMetaAI: (jid: string | undefined) => boolean | undefined;
|
19
23
|
/** is the jid a user */
|
20
24
|
export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
|
21
25
|
/** is the jid a group */
|
22
26
|
export declare const isLidUser: (jid: string | undefined) => boolean | undefined;
|
23
27
|
/** is the jid a broadcast */
|
24
28
|
export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
|
29
|
+
/** is the jid a newsletter */
|
30
|
+
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
25
31
|
/** is the jid a group */
|
26
32
|
export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
|
27
33
|
/** is the jid the status broadcast */
|
28
|
-
export declare const isJidStatusBroadcast: (jid: string) =>
|
29
|
-
|
30
|
-
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
34
|
+
export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
|
35
|
+
export declare const isJidBot: (jid: string | undefined) => boolean | "" | undefined;
|
31
36
|
export declare const jidNormalizedUser: (jid: string | undefined) => string;
|
@@ -1,11 +1,26 @@
|
|
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
|
+
const getBotJid = (jid) => {
|
11
|
+
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"]]);
|
12
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
13
|
+
if (sepIdx < 0) {
|
14
|
+
return jid;
|
15
|
+
}
|
16
|
+
const server = jid.slice(sepIdx + 1);
|
17
|
+
if (server !== 'bot')
|
18
|
+
return jid;
|
19
|
+
const user = jid.slice(0, sepIdx);
|
20
|
+
const mappedNumber = BOT_MAP.get(user);
|
21
|
+
return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
|
22
|
+
};
|
23
|
+
exports.getBotJid = getBotJid;
|
9
24
|
const jidEncode = (user, server, device, agent) => {
|
10
25
|
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
|
11
26
|
};
|
@@ -33,6 +48,9 @@ const areJidsSameUser = (jid1, jid2) => {
|
|
33
48
|
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
49
|
};
|
35
50
|
exports.areJidsSameUser = areJidsSameUser;
|
51
|
+
/** is the jid Meta AI */
|
52
|
+
const isJidMetaAI = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
|
53
|
+
exports.isJidMetaAI = isJidMetaAI;
|
36
54
|
/** is the jid a user */
|
37
55
|
const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
|
38
56
|
exports.isJidUser = isJidUser;
|
@@ -42,15 +60,18 @@ exports.isLidUser = isLidUser;
|
|
42
60
|
/** is the jid a broadcast */
|
43
61
|
const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
|
44
62
|
exports.isJidBroadcast = isJidBroadcast;
|
63
|
+
/** is the jid a newsletter */
|
64
|
+
const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
|
65
|
+
exports.isJidNewsletter = isJidNewsletter;
|
45
66
|
/** is the jid a group */
|
46
67
|
const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
|
47
68
|
exports.isJidGroup = isJidGroup;
|
48
69
|
/** is the jid the status broadcast */
|
49
70
|
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
50
71
|
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
51
|
-
|
52
|
-
const
|
53
|
-
exports.
|
72
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
73
|
+
const isJidBot = (jid) => (jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us'));
|
74
|
+
exports.isJidBot = isJidBot;
|
54
75
|
const jidNormalizedUser = (jid) => {
|
55
76
|
const result = (0, exports.jidDecode)(jid);
|
56
77
|
if (!result) {
|
package/lib/WAM/BinaryInfo.d.ts
CHANGED
@@ -1,18 +1,8 @@
|
|
1
|
-
|
2
|
-
/// <reference types="node" />
|
1
|
+
import { EventInputType } from './constants';
|
3
2
|
export declare class BinaryInfo {
|
4
3
|
protocolVersion: number;
|
5
4
|
sequence: number;
|
6
|
-
events:
|
7
|
-
[x: string]: {
|
8
|
-
props: {
|
9
|
-
[x: string]: import("./constants").Value;
|
10
|
-
};
|
11
|
-
globals: {
|
12
|
-
[x: string]: import("./constants").Value;
|
13
|
-
};
|
14
|
-
};
|
15
|
-
}[];
|
5
|
+
events: EventInputType[];
|
16
6
|
buffer: Buffer[];
|
17
7
|
constructor(options?: Partial<BinaryInfo>);
|
18
8
|
}
|
package/lib/WAM/encode.d.ts
CHANGED
@@ -9,7 +9,7 @@ class USyncContactProtocol {
|
|
9
9
|
getQueryElement() {
|
10
10
|
return {
|
11
11
|
tag: 'contact',
|
12
|
-
attrs: {}
|
12
|
+
attrs: {}
|
13
13
|
};
|
14
14
|
}
|
15
15
|
getUserElement(user) {
|
@@ -17,7 +17,7 @@ class USyncContactProtocol {
|
|
17
17
|
return {
|
18
18
|
tag: 'contact',
|
19
19
|
attrs: {},
|
20
|
-
content: user.phone
|
20
|
+
content: user.phone
|
21
21
|
};
|
22
22
|
}
|
23
23
|
parser(node) {
|
@@ -9,7 +9,7 @@ class USyncDisappearingModeProtocol {
|
|
9
9
|
getQueryElement() {
|
10
10
|
return {
|
11
11
|
tag: 'disappearing_mode',
|
12
|
-
attrs: {}
|
12
|
+
attrs: {}
|
13
13
|
};
|
14
14
|
}
|
15
15
|
getUserElement() {
|
@@ -22,7 +22,7 @@ class USyncDisappearingModeProtocol {
|
|
22
22
|
const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
|
23
23
|
return {
|
24
24
|
duration,
|
25
|
-
setAt
|
25
|
+
setAt
|
26
26
|
};
|
27
27
|
}
|
28
28
|
}
|
@@ -9,20 +9,20 @@ class USyncStatusProtocol {
|
|
9
9
|
getQueryElement() {
|
10
10
|
return {
|
11
11
|
tag: 'status',
|
12
|
-
attrs: {}
|
12
|
+
attrs: {}
|
13
13
|
};
|
14
14
|
}
|
15
15
|
getUserElement() {
|
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 {
|
@@ -34,7 +34,7 @@ class USyncStatusProtocol {
|
|
34
34
|
}
|
35
35
|
return {
|
36
36
|
status,
|
37
|
-
setAt
|
37
|
+
setAt
|
38
38
|
};
|
39
39
|
}
|
40
40
|
}
|
@@ -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() {
|
@@ -26,13 +28,13 @@ class USyncQuery {
|
|
26
28
|
if (result.attrs.type !== 'result') {
|
27
29
|
return;
|
28
30
|
}
|
29
|
-
const protocolMap = Object.fromEntries(this.protocols.map(
|
31
|
+
const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
|
30
32
|
return [protocol.name, protocol.parser];
|
31
33
|
}));
|
32
34
|
const queryResult = {
|
33
35
|
// TODO: implement errors etc.
|
34
36
|
list: [],
|
35
|
-
sideList: []
|
37
|
+
sideList: []
|
36
38
|
};
|
37
39
|
const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
|
38
40
|
//TODO: implement error backoff, refresh etc.
|
@@ -40,18 +42,22 @@ class USyncQuery {
|
|
40
42
|
//const resultNode = getBinaryNodeChild(usyncNode, 'result')
|
41
43
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
42
44
|
if (Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) && typeof listNode !== 'undefined') {
|
43
|
-
queryResult.list = listNode.content.map(
|
45
|
+
queryResult.list = listNode.content.map(node => {
|
44
46
|
const id = node === null || node === void 0 ? void 0 : node.attrs.jid;
|
45
|
-
const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content)
|
48
|
+
? Object.fromEntries(node.content
|
49
|
+
.map(content => {
|
50
|
+
const protocol = content.tag;
|
51
|
+
const parser = protocolMap[protocol];
|
52
|
+
if (parser) {
|
53
|
+
return [protocol, parser(content)];
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
return [protocol, null];
|
57
|
+
}
|
58
|
+
})
|
59
|
+
.filter(([, b]) => b !== null))
|
60
|
+
: {};
|
55
61
|
return { ...data, id };
|
56
62
|
});
|
57
63
|
}
|
@@ -75,5 +81,13 @@ class USyncQuery {
|
|
75
81
|
this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol());
|
76
82
|
return this;
|
77
83
|
}
|
84
|
+
withBotProfileProtocol() {
|
85
|
+
this.protocols.push(new UsyncBotProfileProtocol_1.USyncBotProfileProtocol());
|
86
|
+
return this;
|
87
|
+
}
|
88
|
+
withLIDProtocol() {
|
89
|
+
this.protocols.push(new UsyncLIDProtocol_1.USyncLIDProtocol());
|
90
|
+
return this;
|
91
|
+
}
|
78
92
|
}
|
79
93
|
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;
|