@hbmodsofc/baileys 1.5.2 → 1.7.6
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/WAProto/index.js +19671 -152026
- package/engine-requirements.js +4 -4
- package/lib/Defaults/index.d.ts +12 -8
- package/lib/Defaults/index.js +90 -124
- package/lib/Signal/Group/group_cipher.d.ts +0 -1
- package/lib/Signal/Group/group_cipher.js +28 -39
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +9 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-state.d.ts +4 -4
- package/lib/Signal/Group/sender-key-state.js +47 -16
- package/lib/Signal/libsignal.d.ts +7 -3
- package/lib/Signal/libsignal.js +224 -39
- package/lib/Signal/lid-mapping.d.ts +26 -0
- package/lib/Signal/lid-mapping.js +146 -0
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -3
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +10 -16
- package/lib/Socket/business.d.ts +94 -78
- package/lib/Socket/business.js +130 -11
- package/lib/Socket/chats.d.ts +63 -233
- package/lib/Socket/chats.js +234 -184
- package/lib/Socket/communities.d.ts +232 -0
- package/lib/Socket/communities.js +402 -0
- package/lib/Socket/groups.d.ts +62 -41
- package/lib/Socket/groups.js +76 -64
- package/lib/Socket/index.d.ts +129 -83
- package/lib/Socket/index.js +13 -6
- package/lib/Socket/messages-recv.d.ts +59 -48
- package/lib/Socket/messages-recv.js +516 -371
- package/lib/Socket/messages-send.d.ts +86 -67
- package/lib/Socket/messages-send.js +1091 -1
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +76 -64
- package/lib/Socket/newsletter.js +184 -1
- package/lib/Socket/socket.d.ts +19 -13
- package/lib/Socket/socket.js +805 -1
- package/lib/Types/Auth.d.ts +4 -10
- package/lib/Types/Bussines.d.ts +24 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +29 -9
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +55 -14
- package/lib/Types/GroupMetadata.d.ts +15 -5
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +75 -49
- package/lib/Types/Message.js +10 -7
- package/lib/Types/Newsletter.d.ts +129 -98
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +29 -1
- package/lib/Types/Socket.d.ts +48 -22
- package/lib/Types/State.d.ts +13 -2
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +1 -1
- package/lib/Types/index.d.ts +10 -3
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +378 -102
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +19 -13
- package/lib/Utils/chat-utils.d.ts +21 -22
- package/lib/Utils/chat-utils.js +201 -154
- package/lib/Utils/crypto.d.ts +18 -19
- package/lib/Utils/crypto.js +78 -37
- package/lib/Utils/decode-wa-message.d.ts +34 -7
- package/lib/Utils/decode-wa-message.js +138 -66
- package/lib/Utils/event-buffer.d.ts +6 -8
- package/lib/Utils/event-buffer.js +81 -43
- package/lib/Utils/generics.d.ts +27 -27
- package/lib/Utils/generics.js +128 -133
- package/lib/Utils/history.d.ts +9 -5
- package/lib/Utils/history.js +17 -23
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.js +2 -0
- package/lib/Utils/lidToJid-test.d.ts +11 -0
- package/lib/Utils/lidToJid-test.js +27 -0
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.js +40 -12
- package/lib/Utils/logger.d.ts +11 -3
- package/lib/Utils/lt-hash.d.ts +8 -8
- package/lib/Utils/lt-hash.js +23 -24
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +3 -2
- package/lib/Utils/message-retry-manager.d.ts +81 -0
- package/lib/Utils/message-retry-manager.js +152 -0
- package/lib/Utils/messages-media.d.ts +37 -41
- package/lib/Utils/messages-media.js +252 -368
- package/lib/Utils/messages.d.ts +13 -15
- package/lib/Utils/messages.js +274 -261
- package/lib/Utils/noise-handler.d.ts +13 -15
- package/lib/Utils/noise-handler.js +20 -26
- package/lib/Utils/process-message.d.ts +9 -8
- package/lib/Utils/process-message.js +157 -93
- package/lib/Utils/signal.d.ts +6 -5
- package/lib/Utils/signal.js +37 -29
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +12 -7
- package/lib/Utils/validate-connection.d.ts +5 -6
- package/lib/Utils/validate-connection.js +39 -97
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +3 -4
- package/lib/WABinary/decode.js +28 -14
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +134 -147
- package/lib/WABinary/generic-utils.d.ts +4 -7
- package/lib/WABinary/generic-utils.js +40 -125
- package/lib/WABinary/jid-utils.d.ts +13 -8
- package/lib/WABinary/jid-utils.js +27 -16
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/constants.d.ts +3 -2
- package/lib/WAM/constants.js +2252 -2359
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +8 -11
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -6
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/USyncQuery.d.ts +2 -2
- package/lib/WAUSync/USyncQuery.js +19 -15
- package/lib/WAUSync/USyncUser.d.ts +5 -5
- package/lib/WAUSync/index.d.ts +1 -1
- package/lib/WAUSync/index.js +1 -1
- package/package.json +102 -102
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/hbmods.d.ts +0 -253
- package/lib/Socket/hbmods.js +0 -1
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -1,81 +1,86 @@
|
|
|
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
|
-
const
|
|
6
|
-
const Utils_1 = require("../Utils")
|
|
6
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
7
7
|
// some extra useful utilities
|
|
8
8
|
const getBinaryNodeChildren = (node, childTag) => {
|
|
9
9
|
if (Array.isArray(node?.content)) {
|
|
10
|
-
return node.content.filter(item => item.tag === childTag)
|
|
10
|
+
return node.content.filter(item => item.tag === childTag);
|
|
11
11
|
}
|
|
12
|
-
return []
|
|
13
|
-
}
|
|
12
|
+
return [];
|
|
13
|
+
};
|
|
14
14
|
exports.getBinaryNodeChildren = getBinaryNodeChildren;
|
|
15
15
|
const getAllBinaryNodeChildren = ({ content }) => {
|
|
16
16
|
if (Array.isArray(content)) {
|
|
17
|
-
return content
|
|
17
|
+
return content;
|
|
18
18
|
}
|
|
19
|
-
return []
|
|
20
|
-
}
|
|
19
|
+
return [];
|
|
20
|
+
};
|
|
21
21
|
exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
|
|
22
22
|
const getBinaryNodeChild = (node, childTag) => {
|
|
23
23
|
if (Array.isArray(node?.content)) {
|
|
24
|
-
return node?.content.find(item => item.tag === childTag)
|
|
24
|
+
return node?.content.find(item => item.tag === childTag);
|
|
25
25
|
}
|
|
26
|
-
}
|
|
26
|
+
};
|
|
27
27
|
exports.getBinaryNodeChild = getBinaryNodeChild;
|
|
28
28
|
const getBinaryNodeChildBuffer = (node, childTag) => {
|
|
29
|
-
const child = getBinaryNodeChild(node, childTag)?.content
|
|
29
|
+
const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
|
|
30
30
|
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
31
|
-
return child
|
|
31
|
+
return child;
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
};
|
|
34
34
|
exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
|
|
35
35
|
const getBinaryNodeChildString = (node, childTag) => {
|
|
36
|
-
const child = getBinaryNodeChild(node, childTag)?.content
|
|
36
|
+
const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
|
|
37
37
|
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
38
|
-
return Buffer.from(child).toString('utf-8')
|
|
38
|
+
return Buffer.from(child).toString('utf-8');
|
|
39
39
|
}
|
|
40
40
|
else if (typeof child === 'string') {
|
|
41
|
-
return child
|
|
41
|
+
return child;
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
};
|
|
44
44
|
exports.getBinaryNodeChildString = getBinaryNodeChildString;
|
|
45
45
|
const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
46
|
-
const buff = getBinaryNodeChildBuffer(node, childTag)
|
|
46
|
+
const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag);
|
|
47
47
|
if (buff) {
|
|
48
|
-
return bufferToUInt(buff, length)
|
|
48
|
+
return bufferToUInt(buff, length);
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
51
|
exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
|
|
52
52
|
const assertNodeErrorFree = (node) => {
|
|
53
|
-
const errNode = getBinaryNodeChild(node, 'error')
|
|
53
|
+
const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
|
|
54
54
|
if (errNode) {
|
|
55
|
-
throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
|
|
55
|
+
throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
};
|
|
58
58
|
exports.assertNodeErrorFree = assertNodeErrorFree;
|
|
59
59
|
const reduceBinaryNodeToDictionary = (node, tag) => {
|
|
60
|
-
const nodes = getBinaryNodeChildren(node, tag)
|
|
60
|
+
const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
|
|
61
61
|
const dict = nodes.reduce((dict, { attrs }) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
if (typeof attrs.name === 'string') {
|
|
63
|
+
dict[attrs.name] = attrs.value || attrs.config_value;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
dict[attrs.config_code] = attrs.value || attrs.config_value;
|
|
67
|
+
}
|
|
68
|
+
return dict;
|
|
69
|
+
}, {});
|
|
70
|
+
return dict;
|
|
71
|
+
};
|
|
67
72
|
exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
|
|
68
73
|
const getBinaryNodeMessages = ({ content }) => {
|
|
69
|
-
const msgs = []
|
|
74
|
+
const msgs = [];
|
|
70
75
|
if (Array.isArray(content)) {
|
|
71
76
|
for (const item of content) {
|
|
72
77
|
if (item.tag === 'message') {
|
|
73
|
-
msgs.push(
|
|
78
|
+
msgs.push(index_js_1.proto.WebMessageInfo.decode(item.content));
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
|
-
return msgs
|
|
78
|
-
}
|
|
82
|
+
return msgs;
|
|
83
|
+
};
|
|
79
84
|
exports.getBinaryNodeMessages = getBinaryNodeMessages;
|
|
80
85
|
function bufferToUInt(e, t) {
|
|
81
86
|
let a = 0;
|
|
@@ -96,7 +101,7 @@ function binaryNodeToString(node, i = 0) {
|
|
|
96
101
|
return tabs(i) + Buffer.from(node).toString('hex');
|
|
97
102
|
}
|
|
98
103
|
if (Array.isArray(node)) {
|
|
99
|
-
return node.map(
|
|
104
|
+
return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
|
|
100
105
|
}
|
|
101
106
|
const children = binaryNodeToString(node.content, i + 1);
|
|
102
107
|
const tag = `<${node.tag} ${Object.entries(node.attrs || {})
|
|
@@ -106,93 +111,3 @@ function binaryNodeToString(node, i = 0) {
|
|
|
106
111
|
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
|
107
112
|
return tag + content;
|
|
108
113
|
}
|
|
109
|
-
exports.binaryNodeToString = binaryNodeToString;
|
|
110
|
-
const getBinaryNodeFilter = (node) => {
|
|
111
|
-
if (!Array.isArray(node)) return false
|
|
112
|
-
|
|
113
|
-
return node.some(item =>
|
|
114
|
-
['native_flow'].includes(item?.content?.[0]?.content?.[0]?.tag) ||
|
|
115
|
-
['interactive', 'buttons', 'list'].includes(item?.content?.[0]?.tag) ||
|
|
116
|
-
['hsm', 'biz'].includes(item?.tag) ||
|
|
117
|
-
['bot'].includes(item?.tag) && item?.attrs?.biz_bot === '1'
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
exports.getBinaryNodeFilter = getBinaryNodeFilter;
|
|
121
|
-
const getAdditionalNode = (name) => {
|
|
122
|
-
if (name) name = name.toLowerCase()
|
|
123
|
-
const ts = Utils_1.unixTimestampSeconds(new Date()) - 77980457
|
|
124
|
-
|
|
125
|
-
const order_response_name = {
|
|
126
|
-
review_and_pay: 'order_details',
|
|
127
|
-
review_order: 'order_status',
|
|
128
|
-
payment_info: 'payment_info',
|
|
129
|
-
payment_status: 'payment_status',
|
|
130
|
-
payment_method: 'payment_method'
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const flow_name = {
|
|
134
|
-
cta_catalog: 'cta_catalog',
|
|
135
|
-
mpm: 'mpm',
|
|
136
|
-
call_request: 'call_permission_request',
|
|
137
|
-
view_catalog: 'automated_greeting_message_view_catalog',
|
|
138
|
-
wa_pay_detail: 'wa_payment_transaction_details',
|
|
139
|
-
send_location: 'send_location',
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if(order_response_name[name]) {
|
|
143
|
-
return [{
|
|
144
|
-
tag: 'biz',
|
|
145
|
-
attrs: {
|
|
146
|
-
native_flow_name: order_response_name[name]
|
|
147
|
-
},
|
|
148
|
-
content: []
|
|
149
|
-
}]
|
|
150
|
-
} else if (flow_name[name] || name === 'interactive' || name === 'buttons') {
|
|
151
|
-
return [{
|
|
152
|
-
tag: 'biz',
|
|
153
|
-
attrs: {
|
|
154
|
-
actual_actors: '2',
|
|
155
|
-
host_storage: '2',
|
|
156
|
-
privacy_mode_ts: `${ts}`
|
|
157
|
-
},
|
|
158
|
-
content: [{
|
|
159
|
-
tag: 'engagement',
|
|
160
|
-
attrs: {
|
|
161
|
-
customer_service_state: 'open',
|
|
162
|
-
conversation_state: 'open'
|
|
163
|
-
}
|
|
164
|
-
}, {
|
|
165
|
-
tag: 'interactive',
|
|
166
|
-
attrs: {
|
|
167
|
-
type: 'native_flow',
|
|
168
|
-
v: '1'
|
|
169
|
-
},
|
|
170
|
-
content: [{
|
|
171
|
-
tag: 'native_flow',
|
|
172
|
-
attrs: {
|
|
173
|
-
v: '9',
|
|
174
|
-
name: flow_name[name] ?? 'mixed',
|
|
175
|
-
},
|
|
176
|
-
content: []
|
|
177
|
-
}]
|
|
178
|
-
}]
|
|
179
|
-
}]
|
|
180
|
-
} else {
|
|
181
|
-
return [{
|
|
182
|
-
tag: 'biz',
|
|
183
|
-
attrs: {
|
|
184
|
-
actual_actors: '2',
|
|
185
|
-
host_storage: '2',
|
|
186
|
-
privacy_mode_ts: `${ts}`
|
|
187
|
-
},
|
|
188
|
-
content: [{
|
|
189
|
-
tag: 'engagement',
|
|
190
|
-
attrs: {
|
|
191
|
-
customer_service_state: 'open',
|
|
192
|
-
conversation_state: 'open'
|
|
193
|
-
}
|
|
194
|
-
}]
|
|
195
|
-
}]
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
exports.getAdditionalNode = getAdditionalNode;
|
|
@@ -3,29 +3,34 @@ 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;
|
|
10
11
|
};
|
|
11
12
|
export type FullJid = JidWithDevice & {
|
|
12
|
-
server: JidServer
|
|
13
|
+
server: JidServer;
|
|
13
14
|
domainType?: number;
|
|
14
15
|
};
|
|
15
16
|
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
|
|
16
17
|
export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
|
|
17
18
|
/** is the jid a user */
|
|
18
19
|
export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
|
|
19
|
-
/** is the jid
|
|
20
|
-
export declare const
|
|
21
|
-
/** is the jid a
|
|
20
|
+
/** is the jid Meta AI */
|
|
21
|
+
export declare const isJidMetaAI: (jid: string | undefined) => boolean | undefined;
|
|
22
|
+
/** is the jid a PN user */
|
|
23
|
+
export declare const isPnUser: (jid: string | undefined) => boolean | undefined;
|
|
24
|
+
/** is the jid a LID */
|
|
22
25
|
export declare const isLidUser: (jid: string | undefined) => boolean | undefined;
|
|
23
26
|
/** is the jid a broadcast */
|
|
24
27
|
export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
|
|
25
28
|
/** is the jid a group */
|
|
26
29
|
export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
|
|
27
30
|
/** is the jid the status broadcast */
|
|
28
|
-
export declare const isJidStatusBroadcast: (jid: string) =>
|
|
29
|
-
/** is the jid
|
|
30
|
-
export declare const
|
|
31
|
+
export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
|
|
32
|
+
/** is the jid a newsletter */
|
|
33
|
+
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
|
34
|
+
export declare const isJidBot: (jid: string | undefined) => boolean | "" | undefined;
|
|
31
35
|
export declare const jidNormalizedUser: (jid: string | undefined) => string;
|
|
36
|
+
export declare const transferDevice: (fromJid: string, toJid: string) => string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jidNormalizedUser = exports.
|
|
3
|
+
exports.transferDevice = exports.jidNormalizedUser = exports.isJidBot = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isPnUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = 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';
|
|
9
10
|
const jidEncode = (user, server, device, agent) => {
|
|
10
11
|
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
|
|
11
12
|
};
|
|
@@ -20,7 +21,7 @@ const jidDecode = (jid) => {
|
|
|
20
21
|
const [userAgent, device] = userCombined.split(':');
|
|
21
22
|
const user = userAgent.split('_')[0];
|
|
22
23
|
return {
|
|
23
|
-
server,
|
|
24
|
+
server: server,
|
|
24
25
|
user,
|
|
25
26
|
domainType: server === 'lid' ? 1 : 0,
|
|
26
27
|
device: device ? +device : undefined
|
|
@@ -28,29 +29,32 @@ const jidDecode = (jid) => {
|
|
|
28
29
|
};
|
|
29
30
|
exports.jidDecode = jidDecode;
|
|
30
31
|
/** is the jid a user */
|
|
31
|
-
const areJidsSameUser = (jid1, jid2) =>
|
|
32
|
-
var _a, _b;
|
|
33
|
-
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
|
-
};
|
|
32
|
+
const areJidsSameUser = (jid1, jid2) => (0, exports.jidDecode)(jid1)?.user === (0, exports.jidDecode)(jid2)?.user;
|
|
35
33
|
exports.areJidsSameUser = areJidsSameUser;
|
|
36
|
-
/** is the jid
|
|
37
|
-
const
|
|
38
|
-
exports.
|
|
39
|
-
/** is the jid a
|
|
40
|
-
const
|
|
34
|
+
/** is the jid Meta AI */
|
|
35
|
+
const isJidMetaAI = (jid) => jid?.endsWith('@bot');
|
|
36
|
+
exports.isJidMetaAI = isJidMetaAI;
|
|
37
|
+
/** is the jid a PN user */
|
|
38
|
+
const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
|
|
39
|
+
exports.isPnUser = isPnUser;
|
|
40
|
+
/** is the jid a LID */
|
|
41
|
+
const isLidUser = (jid) => jid?.endsWith('@lid');
|
|
41
42
|
exports.isLidUser = isLidUser;
|
|
42
43
|
/** is the jid a broadcast */
|
|
43
|
-
const isJidBroadcast = (jid) =>
|
|
44
|
+
const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
|
|
44
45
|
exports.isJidBroadcast = isJidBroadcast;
|
|
45
46
|
/** is the jid a group */
|
|
46
|
-
const isJidGroup = (jid) =>
|
|
47
|
+
const isJidGroup = (jid) => jid?.endsWith('@g.us');
|
|
47
48
|
exports.isJidGroup = isJidGroup;
|
|
48
49
|
/** is the jid the status broadcast */
|
|
49
50
|
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
50
51
|
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
51
|
-
/** is the jid
|
|
52
|
-
const
|
|
53
|
-
exports.
|
|
52
|
+
/** is the jid a newsletter */
|
|
53
|
+
const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
|
|
54
|
+
exports.isJidNewsletter = isJidNewsletter;
|
|
55
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
56
|
+
const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
|
|
57
|
+
exports.isJidBot = isJidBot;
|
|
54
58
|
const jidNormalizedUser = (jid) => {
|
|
55
59
|
const result = (0, exports.jidDecode)(jid);
|
|
56
60
|
if (!result) {
|
|
@@ -60,3 +64,10 @@ const jidNormalizedUser = (jid) => {
|
|
|
60
64
|
return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
61
65
|
};
|
|
62
66
|
exports.jidNormalizedUser = jidNormalizedUser;
|
|
67
|
+
const transferDevice = (fromJid, toJid) => {
|
|
68
|
+
const fromDecoded = (0, exports.jidDecode)(fromJid);
|
|
69
|
+
const deviceId = fromDecoded?.device || 0;
|
|
70
|
+
const { server, user } = (0, exports.jidDecode)(toJid);
|
|
71
|
+
return (0, exports.jidEncode)(user, server, deviceId);
|
|
72
|
+
};
|
|
73
|
+
exports.transferDevice = transferDevice;
|
package/lib/WAM/BinaryInfo.d.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type { EventInputType } from './constants';
|
|
2
2
|
export declare class BinaryInfo {
|
|
3
3
|
protocolVersion: number;
|
|
4
4
|
sequence: number;
|
|
5
|
-
events:
|
|
6
|
-
[x: string]: {
|
|
7
|
-
props: {
|
|
8
|
-
[x: string]: any;
|
|
9
|
-
};
|
|
10
|
-
globals: {
|
|
11
|
-
[x: string]: any;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
}[];
|
|
5
|
+
events: EventInputType[];
|
|
15
6
|
buffer: Buffer[];
|
|
16
7
|
constructor(options?: Partial<BinaryInfo>);
|
|
17
8
|
}
|
package/lib/WAM/constants.d.ts
CHANGED
|
@@ -28,11 +28,12 @@ type EventByName<T extends Event['name']> = Extract<Event, {
|
|
|
28
28
|
export type EventInputType = {
|
|
29
29
|
[key in Event['name']]: {
|
|
30
30
|
props: {
|
|
31
|
-
[k in keyof EventByName<key>['props']]:
|
|
31
|
+
[k in keyof EventByName<key>['props']]: Value;
|
|
32
32
|
};
|
|
33
33
|
globals: {
|
|
34
|
-
[x: string]:
|
|
34
|
+
[x: string]: Value;
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
} & {};
|
|
38
|
+
export type Value = number | null | string;
|
|
38
39
|
export {};
|