@rizzxdc/baileys 8.0.10 → 8.1.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 +4 -2
- package/README.md +107 -245
- package/WAProto/index.d.ts +15795 -0
- package/WAProto/index.js +25587 -4867
- package/lib/Defaults/index.d.ts +147 -0
- package/lib/Defaults/index.js +134 -104
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -11
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +5 -8
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.js +72 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +11 -13
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +11 -14
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +23 -26
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +61 -64
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +39 -44
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +35 -38
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +76 -79
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -26
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.js +414 -308
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.js +270 -149
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -4
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.js +8 -11
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +51 -50
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +357 -355
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1195 -867
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +416 -398
- package/lib/Socket/dugong.js +8 -1
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +336 -301
- package/lib/Socket/index.d.ts +530 -0
- package/lib/Socket/index.js +8 -13
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.js +1729 -1121
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.js +684 -462
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +36 -40
- package/lib/Socket/newsletter.d.ts +284 -0
- package/lib/Socket/newsletter.js +247 -237
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +968 -790
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -6
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +414 -284
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +75 -76
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +21 -23
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +5 -7
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.js +1 -3
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.js +21 -22
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.js +3 -4
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.js +11 -6
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.js +0 -2
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.js +1 -3
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.js +1 -4
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.js +52 -8
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.js +1 -3
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.js +22 -25
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +285 -203
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +21 -19
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.js +206 -209
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.js +825 -706
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +88 -101
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.js +287 -238
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.js +602 -509
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.js +334 -295
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.js +125 -79
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.js +25 -21
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -70
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +1 -4
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.js +7 -45
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +27 -31
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.js +165 -14
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +768 -572
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.js +1082 -130
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +191 -135
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.js +96 -76
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.js +718 -311
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.js +257 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.js +174 -135
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -95
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +182 -180
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.js +1455 -1292
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +249 -228
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +207 -206
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.js +135 -99
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.js +80 -78
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.js +1 -3
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +7 -9
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.js +22847 -22848
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +129 -134
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +5 -6
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.js +92 -85
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +28 -22
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -19
- package/package.json +12 -6
- package/lib/Types/Newsletter.js +0 -33
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
2
3
|
import { proto } from '../../WAProto/index.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// some extra useful utilities
|
|
5
|
+
const indexCache = new WeakMap();
|
|
6
6
|
export const getBinaryNodeChildren = (node, childTag) => {
|
|
7
|
-
if (Array.isArray(node
|
|
8
|
-
return
|
|
7
|
+
if (!node || !Array.isArray(node.content))
|
|
8
|
+
return [];
|
|
9
|
+
let index = indexCache.get(node);
|
|
10
|
+
// Build the index once per node
|
|
11
|
+
if (!index) {
|
|
12
|
+
index = new Map();
|
|
13
|
+
for (const child of node.content) {
|
|
14
|
+
let arr = index.get(child.tag);
|
|
15
|
+
if (!arr)
|
|
16
|
+
index.set(child.tag, (arr = []));
|
|
17
|
+
arr.push(child);
|
|
18
|
+
}
|
|
19
|
+
indexCache.set(node, index);
|
|
9
20
|
}
|
|
10
|
-
|
|
21
|
+
// Return first matching child
|
|
22
|
+
return index.get(childTag) || [];
|
|
23
|
+
};
|
|
24
|
+
export const getBinaryNodeChild = (node, childTag) => {
|
|
25
|
+
return getBinaryNodeChildren(node, childTag)[0];
|
|
11
26
|
};
|
|
12
27
|
export const getAllBinaryNodeChildren = ({ content }) => {
|
|
13
28
|
if (Array.isArray(content)) {
|
|
@@ -15,11 +30,6 @@ export const getAllBinaryNodeChildren = ({ content }) => {
|
|
|
15
30
|
}
|
|
16
31
|
return [];
|
|
17
32
|
};
|
|
18
|
-
export const getBinaryNodeChild = (node, childTag) => {
|
|
19
|
-
if (Array.isArray(node?.content)) {
|
|
20
|
-
return node?.content.find(item => item.tag === childTag);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
33
|
export const getBinaryNodeChildBuffer = (node, childTag) => {
|
|
24
34
|
const child = getBinaryNodeChild(node, childTag)?.content;
|
|
25
35
|
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
@@ -65,7 +75,7 @@ export const getBinaryNodeMessages = ({ content }) => {
|
|
|
65
75
|
if (Array.isArray(content)) {
|
|
66
76
|
for (const item of content) {
|
|
67
77
|
if (item.tag === 'message') {
|
|
68
|
-
msgs.push(proto.WebMessageInfo.decode(item.content));
|
|
78
|
+
msgs.push(proto.WebMessageInfo.decode(item.content).toJSON());
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
81
|
}
|
|
@@ -100,90 +110,116 @@ export function binaryNodeToString(node, i = 0) {
|
|
|
100
110
|
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
|
101
111
|
return tag + content;
|
|
102
112
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
113
|
+
/**
|
|
114
|
+
* Lia@Changes 30-01-26
|
|
115
|
+
* ---
|
|
116
|
+
* Produce the binary node (WABinary-like JSON shape) required for the specific
|
|
117
|
+
* interactive button / list type.
|
|
118
|
+
* compatible with observed official client traffic.
|
|
119
|
+
*
|
|
120
|
+
* NOTE: Returning different "v" (version) and "name" values influences how
|
|
121
|
+
* WhatsApp renders & validates flows. The constants here are empirically derived.
|
|
122
|
+
*
|
|
123
|
+
* @param {object} message Normalized message content (after Baileys normalization).
|
|
124
|
+
* @returns {object} A node with shape { tag, attrs, [content] } to inject into additionalNodes.
|
|
125
|
+
*/
|
|
126
|
+
const FLOWS_MAP = {
|
|
127
|
+
mpm: true,
|
|
128
|
+
cta_catalog: true,
|
|
129
|
+
send_location: true,
|
|
130
|
+
call_permission_request: true,
|
|
131
|
+
wa_payment_transaction_details: true,
|
|
132
|
+
automated_greeting_message_view_catalog: true
|
|
133
|
+
};
|
|
134
|
+
const DECISION_SOURCE_CONTENT = [
|
|
135
|
+
{
|
|
136
|
+
tag: 'decision_source',
|
|
137
|
+
attrs: { value: 'df' }
|
|
138
|
+
}
|
|
139
|
+
];
|
|
140
|
+
const LIST_TYPE_CONTENT = {
|
|
141
|
+
tag: 'list',
|
|
142
|
+
attrs: { v: '2', type: 'product_list' }
|
|
143
|
+
};
|
|
144
|
+
const NATIVE_FLOW_ATTRIBUTE = { type: 'native_flow', v: '1' };
|
|
145
|
+
const MIXED_NATIVE_FLOW = {
|
|
146
|
+
tag: 'interactive',
|
|
147
|
+
attrs: NATIVE_FLOW_ATTRIBUTE,
|
|
148
|
+
content: [
|
|
149
|
+
{
|
|
150
|
+
tag: 'native_flow',
|
|
151
|
+
attrs: { v: '9', name: 'mixed' }
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
};
|
|
155
|
+
export const getBizBinaryNode = (message) => {
|
|
156
|
+
const flowMsg = message.interactiveMessage?.nativeFlowMessage;
|
|
157
|
+
const firstButtonName = flowMsg?.buttons?.[0]?.name;
|
|
158
|
+
const qualityContent = {
|
|
159
|
+
tag: 'quality_control',
|
|
160
|
+
attrs: {
|
|
161
|
+
decision_id: randomBytes(20).toString('hex'),
|
|
162
|
+
source_type: 'third_party'
|
|
163
|
+
},
|
|
164
|
+
content: DECISION_SOURCE_CONTENT
|
|
165
|
+
};
|
|
166
|
+
const bizAttributes = {
|
|
167
|
+
actual_actors: '2',
|
|
168
|
+
host_storage: '2',
|
|
169
|
+
privacy_mode_ts: `${Date.now() / 1_000 | 0}`
|
|
170
|
+
};
|
|
171
|
+
if (firstButtonName === 'review_and_pay' || firstButtonName === 'payment_info') {
|
|
172
|
+
bizAttributes.native_flow_name = firstButtonName === 'review_and_pay' ?
|
|
173
|
+
'order_details' :
|
|
174
|
+
firstButtonName;
|
|
175
|
+
return {
|
|
176
|
+
tag: 'biz',
|
|
177
|
+
attrs: bizAttributes,
|
|
178
|
+
content: [qualityContent]
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (firstButtonName && FLOWS_MAP[firstButtonName]) {
|
|
182
|
+
return {
|
|
183
|
+
tag: 'biz',
|
|
184
|
+
attrs: bizAttributes,
|
|
185
|
+
content: [
|
|
186
|
+
{
|
|
187
|
+
tag: 'interactive',
|
|
188
|
+
attrs: NATIVE_FLOW_ATTRIBUTE,
|
|
189
|
+
content: [
|
|
190
|
+
{
|
|
191
|
+
tag: 'native_flow',
|
|
192
|
+
attrs: { v: '2', name: firstButtonName }
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
qualityContent
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (flowMsg || message.buttonsMessage || message.templateMessage) {
|
|
201
|
+
return {
|
|
202
|
+
tag: 'biz',
|
|
203
|
+
attrs: bizAttributes,
|
|
204
|
+
content: [
|
|
205
|
+
MIXED_NATIVE_FLOW,
|
|
206
|
+
qualityContent
|
|
207
|
+
]
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
if (message.listMessage) {
|
|
211
|
+
return {
|
|
212
|
+
tag: 'biz',
|
|
213
|
+
attrs: bizAttributes,
|
|
214
|
+
content: [
|
|
215
|
+
LIST_TYPE_CONTENT,
|
|
216
|
+
qualityContent
|
|
217
|
+
]
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
tag: 'biz',
|
|
222
|
+
attrs: bizAttributes,
|
|
223
|
+
content: [qualityContent]
|
|
224
|
+
};
|
|
225
|
+
};
|
package/lib/WABinary/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from "./types.js";
|
|
7
|
-
//=======================================================//
|
|
1
|
+
export * from './encode.js';
|
|
2
|
+
export * from './decode.js';
|
|
3
|
+
export * from './generic-utils.js';
|
|
4
|
+
export * from './jid-utils.js';
|
|
5
|
+
export * from './types.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const S_WHATSAPP_NET: "@s.whatsapp.net";
|
|
2
|
+
export const OFFICIAL_BIZ_JID: "16505361212@c.us";
|
|
3
|
+
export const SERVER_JID: "server@c.us";
|
|
4
|
+
export const PSA_WID: "0@c.us";
|
|
5
|
+
export const STORIES_JID: "status@broadcast";
|
|
6
|
+
export const META_AI_JID: "13135550002@c.us";
|
|
7
|
+
export const WAJIDDomains: any;
|
|
8
|
+
export function getServerFromDomainType(initialServer: any, domainType: any): any;
|
|
9
|
+
export function jidEncode(user: any, server: any, device: any, agent: any): string;
|
|
10
|
+
export function jidDecode(jid: any): {
|
|
11
|
+
server: any;
|
|
12
|
+
user: any;
|
|
13
|
+
domainType: any;
|
|
14
|
+
device: number | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
export function areJidsSameUser(jid1: any, jid2: any): boolean;
|
|
17
|
+
export function isJidMetaAI(jid: any): any;
|
|
18
|
+
export function isPnUser(jid: any): any;
|
|
19
|
+
export function isLidUser(jid: any): any;
|
|
20
|
+
export function isJidBroadcast(jid: any): any;
|
|
21
|
+
export function isJidGroup(jid: any): any;
|
|
22
|
+
export function isJidStatusBroadcast(jid: any): boolean;
|
|
23
|
+
export function isJidNewsletter(jid: any): any;
|
|
24
|
+
export function isHostedPnUser(jid: any): any;
|
|
25
|
+
export function isHostedLidUser(jid: any): any;
|
|
26
|
+
export function isJidBot(jid: any): any;
|
|
27
|
+
export function jidNormalizedUser(jid: any): string;
|
|
28
|
+
export function transferDevice(fromJid: any, toJid: any): string;
|
|
29
|
+
//# sourceMappingURL=jid-utils.d.ts.map
|
|
@@ -1,93 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
export const OFFICIAL_BIZ_JID =
|
|
3
|
-
export const
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export const PSA_WID = "0@c.us";
|
|
8
|
-
//=======================================================//
|
|
1
|
+
export const S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
2
|
+
export const OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
3
|
+
export const SERVER_JID = 'server@c.us';
|
|
4
|
+
export const PSA_WID = '0@c.us';
|
|
5
|
+
export const STORIES_JID = 'status@broadcast';
|
|
6
|
+
export const META_AI_JID = '13135550002@c.us';
|
|
9
7
|
export var WAJIDDomains;
|
|
10
8
|
(function (WAJIDDomains) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
|
|
10
|
+
WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
|
|
11
|
+
WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
|
|
12
|
+
WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
|
|
15
13
|
})(WAJIDDomains || (WAJIDDomains = {}));
|
|
16
14
|
export const getServerFromDomainType = (initialServer, domainType) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
switch (domainType) {
|
|
16
|
+
case WAJIDDomains.LID:
|
|
17
|
+
return 'lid';
|
|
18
|
+
case WAJIDDomains.HOSTED:
|
|
19
|
+
return 'hosted';
|
|
20
|
+
case WAJIDDomains.HOSTED_LID:
|
|
21
|
+
return 'hosted.lid';
|
|
22
|
+
case WAJIDDomains.WHATSAPP:
|
|
23
|
+
default:
|
|
24
|
+
return initialServer;
|
|
25
|
+
}
|
|
28
26
|
};
|
|
29
|
-
//=======================================================//
|
|
30
27
|
export const jidEncode = (user, server, device, agent) => {
|
|
31
|
-
|
|
28
|
+
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server || 'lid'}`;
|
|
32
29
|
};
|
|
33
|
-
//=======================================================//
|
|
34
30
|
export const jidDecode = (jid) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
31
|
+
// todo: investigate how to implement hosted ids in this case
|
|
32
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
|
33
|
+
if (sepIdx < 0) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const server = jid.slice(sepIdx + 1);
|
|
37
|
+
const userCombined = jid.slice(0, sepIdx);
|
|
38
|
+
const [userAgent, device] = userCombined.split(':');
|
|
39
|
+
const [user, agent] = userAgent.split('_');
|
|
40
|
+
let domainType = WAJIDDomains.WHATSAPP;
|
|
41
|
+
if (server === 'lid') {
|
|
42
|
+
domainType = WAJIDDomains.LID;
|
|
43
|
+
}
|
|
44
|
+
else if (server === 'hosted') {
|
|
45
|
+
domainType = WAJIDDomains.HOSTED;
|
|
46
|
+
}
|
|
47
|
+
else if (server === 'hosted.lid') {
|
|
48
|
+
domainType = WAJIDDomains.HOSTED_LID;
|
|
49
|
+
}
|
|
50
|
+
else if (agent) {
|
|
51
|
+
domainType = parseInt(agent);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
server: server,
|
|
55
|
+
user: user,
|
|
56
|
+
domainType,
|
|
57
|
+
device: device ? +device : undefined
|
|
58
|
+
};
|
|
62
59
|
};
|
|
63
|
-
|
|
60
|
+
/** is the jid a user */
|
|
64
61
|
export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
|
|
65
|
-
|
|
66
|
-
export const
|
|
67
|
-
|
|
68
|
-
export const
|
|
69
|
-
|
|
70
|
-
export const
|
|
71
|
-
|
|
72
|
-
export const
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
/** is the jid Meta AI */
|
|
63
|
+
export const isJidMetaAI = (jid) => jid?.endsWith('@bot');
|
|
64
|
+
/** is the jid a PN user */
|
|
65
|
+
export const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
|
|
66
|
+
/** is the jid a LID */
|
|
67
|
+
export const isLidUser = (jid) => jid?.endsWith('@lid');
|
|
68
|
+
/** is the jid a broadcast */
|
|
69
|
+
export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
|
|
70
|
+
/** is the jid a group */
|
|
71
|
+
export const isJidGroup = (jid) => jid?.endsWith('@g.us');
|
|
72
|
+
/** is the jid the status broadcast */
|
|
73
|
+
export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
74
|
+
/** is the jid a newsletter */
|
|
75
|
+
export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
|
|
76
|
+
/** is the jid a hosted PN */
|
|
77
|
+
export const isHostedPnUser = (jid) => jid?.endsWith('@hosted');
|
|
78
|
+
/** is the jid a hosted LID */
|
|
79
|
+
export const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid');
|
|
75
80
|
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
76
|
-
|
|
77
|
-
export const isJidBot = (jid) => jid && botRegexp.test(jid.split("@")[0]) && jid.endsWith("@c.us");
|
|
81
|
+
export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
|
|
78
82
|
export const jidNormalizedUser = (jid) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const result = jidDecode(jid);
|
|
84
|
+
if (!result) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
const { user, server } = result;
|
|
88
|
+
return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
85
89
|
};
|
|
86
|
-
//=======================================================//
|
|
87
90
|
export const transferDevice = (fromJid, toJid) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
const fromDecoded = jidDecode(fromJid);
|
|
92
|
+
const deviceId = fromDecoded?.device || 0;
|
|
93
|
+
const { server, user } = jidDecode(toJid);
|
|
94
|
+
return jidEncode(user, server, deviceId);
|
|
92
95
|
};
|
|
93
|
-
//=======================================================//
|
package/lib/WABinary/types.js
CHANGED
package/lib/WAM/BinaryInfo.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
//=======================================================//
|
|
2
1
|
export class BinaryInfo {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
this.protocolVersion = 5;
|
|
4
|
+
this.sequence = 0;
|
|
5
|
+
this.events = [];
|
|
6
|
+
this.buffer = [];
|
|
7
|
+
Object.assign(this, options);
|
|
8
|
+
}
|
|
10
9
|
}
|
|
11
|
-
//=======================================================//
|