@nexustechpro/baileys 2.0.1 → 2.0.5

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.
Files changed (102) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/lib/Defaults/baileys-version.json +6 -2
  4. package/lib/Defaults/index.js +172 -172
  5. package/lib/Signal/libsignal.js +380 -292
  6. package/lib/Signal/lid-mapping.js +264 -171
  7. package/lib/Socket/Client/index.js +2 -2
  8. package/lib/Socket/Client/types.js +10 -10
  9. package/lib/Socket/Client/websocket.js +45 -310
  10. package/lib/Socket/business.js +375 -375
  11. package/lib/Socket/chats.js +909 -963
  12. package/lib/Socket/communities.js +430 -430
  13. package/lib/Socket/groups.js +342 -342
  14. package/lib/Socket/index.js +22 -22
  15. package/lib/Socket/messages-recv.js +777 -743
  16. package/lib/Socket/messages-send.js +667 -393
  17. package/lib/Socket/mex.js +50 -50
  18. package/lib/Socket/newsletter.js +148 -148
  19. package/lib/Socket/nexus-handler.js +75 -261
  20. package/lib/Socket/socket.js +709 -1201
  21. package/lib/Store/index.js +5 -5
  22. package/lib/Store/make-cache-manager-store.js +81 -81
  23. package/lib/Store/make-in-memory-store.js +416 -416
  24. package/lib/Store/make-ordered-dictionary.js +81 -81
  25. package/lib/Store/object-repository.js +30 -30
  26. package/lib/Types/Auth.js +1 -1
  27. package/lib/Types/Bussines.js +1 -1
  28. package/lib/Types/Call.js +1 -1
  29. package/lib/Types/Chat.js +7 -7
  30. package/lib/Types/Contact.js +1 -1
  31. package/lib/Types/Events.js +1 -1
  32. package/lib/Types/GroupMetadata.js +1 -1
  33. package/lib/Types/Label.js +24 -24
  34. package/lib/Types/LabelAssociation.js +6 -6
  35. package/lib/Types/Message.js +10 -10
  36. package/lib/Types/Newsletter.js +28 -28
  37. package/lib/Types/Product.js +1 -1
  38. package/lib/Types/Signal.js +1 -1
  39. package/lib/Types/Socket.js +2 -2
  40. package/lib/Types/State.js +12 -12
  41. package/lib/Types/USync.js +1 -1
  42. package/lib/Types/index.js +25 -25
  43. package/lib/Utils/auth-utils.js +264 -256
  44. package/lib/Utils/baileys-event-stream.js +55 -55
  45. package/lib/Utils/browser-utils.js +27 -27
  46. package/lib/Utils/business.js +228 -230
  47. package/lib/Utils/chat-utils.js +694 -764
  48. package/lib/Utils/crypto.js +109 -135
  49. package/lib/Utils/decode-wa-message.js +310 -314
  50. package/lib/Utils/event-buffer.js +547 -547
  51. package/lib/Utils/generics.js +297 -297
  52. package/lib/Utils/history.js +91 -83
  53. package/lib/Utils/index.js +21 -20
  54. package/lib/Utils/key-store.js +17 -0
  55. package/lib/Utils/link-preview.js +97 -88
  56. package/lib/Utils/logger.js +2 -2
  57. package/lib/Utils/lt-hash.js +47 -47
  58. package/lib/Utils/make-mutex.js +39 -39
  59. package/lib/Utils/message-retry-manager.js +148 -148
  60. package/lib/Utils/messages-media.js +534 -532
  61. package/lib/Utils/messages.js +705 -705
  62. package/lib/Utils/noise-handler.js +255 -255
  63. package/lib/Utils/pre-key-manager.js +105 -105
  64. package/lib/Utils/process-message.js +412 -412
  65. package/lib/Utils/signal.js +160 -158
  66. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  67. package/lib/Utils/validate-connection.js +194 -194
  68. package/lib/WABinary/constants.js +1300 -1300
  69. package/lib/WABinary/decode.js +237 -237
  70. package/lib/WABinary/encode.js +232 -232
  71. package/lib/WABinary/generic-utils.js +252 -211
  72. package/lib/WABinary/index.js +5 -5
  73. package/lib/WABinary/jid-utils.js +279 -95
  74. package/lib/WABinary/types.js +1 -1
  75. package/lib/WAM/BinaryInfo.js +9 -9
  76. package/lib/WAM/constants.js +22852 -22852
  77. package/lib/WAM/encode.js +149 -149
  78. package/lib/WAM/index.js +3 -3
  79. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  80. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  81. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  82. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  83. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  84. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  85. package/lib/WAUSync/Protocols/index.js +4 -4
  86. package/lib/WAUSync/USyncQuery.js +93 -93
  87. package/lib/WAUSync/USyncUser.js +22 -22
  88. package/lib/WAUSync/index.js +3 -3
  89. package/lib/index.js +66 -66
  90. package/package.json +171 -144
  91. package/lib/Signal/Group/ciphertext-message.js +0 -12
  92. package/lib/Signal/Group/group-session-builder.js +0 -30
  93. package/lib/Signal/Group/group_cipher.js +0 -100
  94. package/lib/Signal/Group/index.js +0 -12
  95. package/lib/Signal/Group/keyhelper.js +0 -18
  96. package/lib/Signal/Group/sender-chain-key.js +0 -26
  97. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  98. package/lib/Signal/Group/sender-key-message.js +0 -66
  99. package/lib/Signal/Group/sender-key-name.js +0 -48
  100. package/lib/Signal/Group/sender-key-record.js +0 -41
  101. package/lib/Signal/Group/sender-key-state.js +0 -84
  102. package/lib/Signal/Group/sender-message-key.js +0 -26
@@ -1,211 +1,252 @@
1
- import { Boom } from '@hapi/boom';
2
- import { proto } from '../../WAProto/index.js';
3
- import {} from './types.js';
4
- // some extra useful utilities
5
- export const getBinaryNodeChildren = (node, childTag) => {
6
- if (Array.isArray(node?.content)) {
7
- return node.content.filter(item => item.tag === childTag);
8
- }
9
- return [];
10
- };
11
- export const getAllBinaryNodeChildren = ({ content }) => {
12
- if (Array.isArray(content)) {
13
- return content;
14
- }
15
- return [];
16
- };
17
- export const getBinaryNodeChild = (node, childTag) => {
18
- if (Array.isArray(node?.content)) {
19
- return node?.content.find(item => item.tag === childTag);
20
- }
21
- };
22
- export const getBinaryNodeChildBuffer = (node, childTag) => {
23
- const child = getBinaryNodeChild(node, childTag)?.content;
24
- if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
25
- return child;
26
- }
27
- };
28
- // Add this function after getBinaryFilteredButtons
29
- export const getButtonArgs = (message) => {
30
- const msgContent = message.viewOnceMessage?.message || message;
31
- // Check both interactiveMessage and interactive keys
32
- const interactiveMsg = msgContent.interactiveMessage || msgContent.interactive;
33
- const flowMsg = interactiveMsg?.nativeFlowMessage;
34
- const btnFirst = flowMsg?.buttons?.[0]?.name;
35
- const specialBtns = [
36
- 'mpm', 'cta_catalog', 'send_location', 'call_permission_request',
37
- 'wa_payment_transaction_details', 'automated_greeting_message_view_catalog',
38
- 'open_webview', 'galaxy_message'
39
- ];
40
-
41
- const base = {
42
- tag: 'biz',
43
- attrs: {
44
- actual_actors: '2',
45
- host_storage: '2',
46
- privacy_mode_ts: Math.floor(Date.now() / 1000).toString()
47
- }
48
- };
49
-
50
- // Special buttons need full interactive structure
51
- if (flowMsg && specialBtns.includes(btnFirst)) {
52
- return {
53
- ...base,
54
- content: [
55
- {
56
- tag: 'interactive',
57
- attrs: { type: 'native_flow', v: '1' },
58
- content: [{
59
- tag: 'native_flow',
60
- attrs: { v: '2', name: btnFirst }
61
- }]
62
- },
63
- { tag: 'quality_control', attrs: { source_type: 'third_party' } }
64
- ]
65
- };
66
- }
67
-
68
- // Regular interactive/button messages
69
- if (flowMsg || msgContent.buttonsMessage) {
70
- return {
71
- ...base,
72
- content: [
73
- {
74
- tag: 'interactive',
75
- attrs: { type: 'native_flow', v: '1' },
76
- content: [{
77
- tag: 'native_flow',
78
- attrs: { v: '9', name: 'mixed' }
79
- }]
80
- },
81
- { tag: 'quality_control', attrs: { source_type: 'third_party' } }
82
- ]
83
- };
84
- }
85
-
86
- // List messages
87
- if (msgContent.listMessage) {
88
- return {
89
- ...base,
90
- content: [
91
- { tag: 'list', attrs: { v: '2', type: 'product_list' } },
92
- { tag: 'quality_control', attrs: { source_type: 'third_party' } }
93
- ]
94
- };
95
- }
96
-
97
- return base;
98
- };
99
-
100
- // Add button type detection helper
101
- export const getButtonType = (message) => {
102
- if (message.listMessage) return 'list';
103
- if (message.buttonsMessage) return 'buttons';
104
-
105
- // Check both interactiveMessage and interactive keys
106
- const interactiveMsg = message.interactiveMessage || message.interactive;
107
- if (!interactiveMsg?.nativeFlowMessage) return null;
108
-
109
- const btn = interactiveMsg?.nativeFlowMessage?.buttons?.[0]?.name;
110
- if (['review_and_pay', 'review_order', 'payment_info', 'payment_status', 'payment_method'].includes(btn)) {
111
- return btn;
112
- }
113
-
114
- // Return 'interactive' for ANY native flow message that has buttons or nativeFlowMessage
115
- if (interactiveMsg?.nativeFlowMessage?.buttons?.length || interactiveMsg?.nativeFlowMessage) {
116
- return 'interactive';
117
- }
118
-
119
- return null;
120
- };
121
-
122
- export const getBinaryNodeChildString = (node, childTag) => {
123
- const child = getBinaryNodeChild(node, childTag)?.content;
124
- if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
125
- return Buffer.from(child).toString('utf-8');
126
- }
127
- else if (typeof child === 'string') {
128
- return child;
129
- }
130
- };
131
- export const getBinaryFilteredButtons = (nodeContent) => {
132
- if (!Array.isArray(nodeContent)) return false
133
-
134
- return nodeContent.some(a =>
135
- ['native_flow'].includes(a?.content?.[0]?.content?.[0]?.tag) ||
136
- ['interactive', 'buttons', 'list'].includes(a?.content?.[0]?.tag) ||
137
- ['hsm', 'biz'].includes(a?.tag)
138
- )
139
- }
140
- export const getBinaryNodeChildUInt = (node, childTag, length) => {
141
- const buff = getBinaryNodeChildBuffer(node, childTag);
142
- if (buff) {
143
- return bufferToUInt(buff, length);
144
- }
145
- };
146
- export const assertNodeErrorFree = (node) => {
147
- const errNode = getBinaryNodeChild(node, 'error');
148
- if (errNode) {
149
- const errorCode = +errNode.attrs.code;
150
- if (errorCode === 429) {
151
- const error = new Boom('Rate limit', { data: 429 });
152
- error.isRateLimit = true;
153
- throw error;
154
- }
155
- throw new Boom(errNode.attrs.text || 'Unknown error', { data: errorCode });
156
- }
157
- };
158
- export const reduceBinaryNodeToDictionary = (node, tag) => {
159
- const nodes = getBinaryNodeChildren(node, tag);
160
- const dict = nodes.reduce((dict, { attrs }) => {
161
- if (typeof attrs.name === 'string') {
162
- dict[attrs.name] = attrs.value || attrs.config_value;
163
- }
164
- else {
165
- dict[attrs.config_code] = attrs.value || attrs.config_value;
166
- }
167
- return dict;
168
- }, {});
169
- return dict;
170
- };
171
- export const getBinaryNodeMessages = ({ content }) => {
172
- const msgs = [];
173
- if (Array.isArray(content)) {
174
- for (const item of content) {
175
- if (item.tag === 'message') {
176
- msgs.push(proto.WebMessageInfo.decode(item.content).toJSON());
177
- }
178
- }
179
- }
180
- return msgs;
181
- };
182
- function bufferToUInt(e, t) {
183
- let a = 0;
184
- for (let i = 0; i < t; i++) {
185
- a = 256 * a + e[i];
186
- }
187
- return a;
188
- }
189
- const tabs = (n) => '\t'.repeat(n);
190
- export function binaryNodeToString(node, i = 0) {
191
- if (!node) {
192
- return node;
193
- }
194
- if (typeof node === 'string') {
195
- return tabs(i) + node;
196
- }
197
- if (node instanceof Uint8Array) {
198
- return tabs(i) + Buffer.from(node).toString('hex');
199
- }
200
- if (Array.isArray(node)) {
201
- return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
202
- }
203
- const children = binaryNodeToString(node.content, i + 1);
204
- const tag = `<${node.tag} ${Object.entries(node.attrs || {})
205
- .filter(([, v]) => v !== undefined)
206
- .map(([k, v]) => `${k}='${v}'`)
207
- .join(' ')}`;
208
- const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
209
- return tag + content;
210
- }
211
- //# sourceMappingURL=generic-utils.js.map
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import {} from './types.js';
4
+ // some extra useful utilities
5
+ export const getBinaryNodeChildren = (node, childTag) => {
6
+ if (Array.isArray(node?.content)) {
7
+ return node.content.filter(item => item.tag === childTag);
8
+ }
9
+ return [];
10
+ };
11
+ export const getAllBinaryNodeChildren = ({ content }) => {
12
+ if (Array.isArray(content)) {
13
+ return content;
14
+ }
15
+ return [];
16
+ };
17
+ export const getBinaryNodeChild = (node, childTag) => {
18
+ if (Array.isArray(node?.content)) {
19
+ return node?.content.find(item => item.tag === childTag);
20
+ }
21
+ };
22
+ export const getBinaryNodeChildBuffer = (node, childTag) => {
23
+ const child = getBinaryNodeChild(node, childTag)?.content;
24
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
25
+ return child;
26
+ }
27
+ };
28
+ // Returns the biz stanza nodes required for interactive/button messages
29
+ export const getButtonArgs = (message) => {
30
+ const msgContent = message.viewOnceMessage?.message || message;
31
+ const interactiveMsg = msgContent.interactiveMessage || msgContent.interactive;
32
+ const flowMsg = interactiveMsg?.nativeFlowMessage;
33
+ const btnFirst = flowMsg?.buttons?.[0]?.name;
34
+
35
+ const ts = Math.floor(Date.now() / 1000) - 77980457;
36
+
37
+ const order_response_name = {
38
+ review_and_pay: 'order_details',
39
+ review_order: 'order_status',
40
+ payment_info: 'payment_info',
41
+ payment_status: 'payment_status',
42
+ payment_method: 'payment_method'
43
+ };
44
+
45
+ const flow_name = {
46
+ cta_catalog: 'cta_catalog',
47
+ mpm: 'mpm',
48
+ call_permission_request: 'call_permission_request',
49
+ call_request: 'call_permission_request',
50
+ view_catalog: 'automated_greeting_message_view_catalog',
51
+ automated_greeting_message_view_catalog: 'automated_greeting_message_view_catalog',
52
+ wa_pay_detail: 'wa_payment_transaction_details',
53
+ wa_payment_transaction_details: 'wa_payment_transaction_details',
54
+ send_location: 'send_location',
55
+ open_webview: 'open_webview',
56
+ galaxy_message: 'galaxy_message',
57
+ };
58
+
59
+ // Order response buttons
60
+ if (btnFirst && order_response_name[btnFirst]) {
61
+ return [{
62
+ tag: 'biz',
63
+ attrs: {
64
+ native_flow_name: order_response_name[btnFirst]
65
+ },
66
+ content: []
67
+ }];
68
+ }
69
+
70
+ // Interactive / native flow buttons
71
+ if (flowMsg || msgContent.buttonsMessage) {
72
+ const name = (btnFirst && flow_name[btnFirst]) ? flow_name[btnFirst] : 'mixed';
73
+ return [{
74
+ tag: 'biz',
75
+ attrs: {
76
+ actual_actors: '2',
77
+ host_storage: '2',
78
+ privacy_mode_ts: `${ts}`
79
+ },
80
+ content: [{
81
+ tag: 'engagement',
82
+ attrs: {
83
+ customer_service_state: 'open',
84
+ conversation_state: 'open'
85
+ }
86
+ }, {
87
+ tag: 'interactive',
88
+ attrs: {
89
+ type: 'native_flow',
90
+ v: '1'
91
+ },
92
+ content: [{
93
+ tag: 'native_flow',
94
+ attrs: {
95
+ v: '9',
96
+ name: name,
97
+ },
98
+ content: []
99
+ }]
100
+ }]
101
+ }];
102
+ }
103
+
104
+ // List messages
105
+ if (msgContent.listMessage) {
106
+ return [{
107
+ tag: 'biz',
108
+ attrs: {
109
+ actual_actors: '2',
110
+ host_storage: '2',
111
+ privacy_mode_ts: `${ts}`
112
+ },
113
+ content: [{
114
+ tag: 'engagement',
115
+ attrs: {
116
+ customer_service_state: 'open',
117
+ conversation_state: 'open'
118
+ }
119
+ }]
120
+ }];
121
+ }
122
+
123
+ // Fallback
124
+ return [{
125
+ tag: 'biz',
126
+ attrs: {
127
+ actual_actors: '2',
128
+ host_storage: '2',
129
+ privacy_mode_ts: `${ts}`
130
+ },
131
+ content: [{
132
+ tag: 'engagement',
133
+ attrs: {
134
+ customer_service_state: 'open',
135
+ conversation_state: 'open'
136
+ }
137
+ }]
138
+ }];
139
+ };
140
+
141
+ // Add button type detection helper
142
+ export const getButtonType = (message) => {
143
+ if (message.listMessage) return 'list';
144
+ if (message.buttonsMessage) return 'buttons';
145
+
146
+ // Check both interactiveMessage and interactive keys
147
+ const interactiveMsg = message.interactiveMessage || message.interactive;
148
+ if (!interactiveMsg?.nativeFlowMessage) return null;
149
+
150
+ const btn = interactiveMsg?.nativeFlowMessage?.buttons?.[0]?.name;
151
+ if (['review_and_pay', 'review_order', 'payment_info', 'payment_status', 'payment_method'].includes(btn)) {
152
+ return btn;
153
+ }
154
+
155
+ // Return 'interactive' for ANY native flow message that has buttons or nativeFlowMessage
156
+ if (interactiveMsg?.nativeFlowMessage?.buttons?.length || interactiveMsg?.nativeFlowMessage) {
157
+ return 'interactive';
158
+ }
159
+
160
+ return null;
161
+ };
162
+
163
+ export const getBinaryNodeChildString = (node, childTag) => {
164
+ const child = getBinaryNodeChild(node, childTag)?.content;
165
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
166
+ return Buffer.from(child).toString('utf-8');
167
+ }
168
+ else if (typeof child === 'string') {
169
+ return child;
170
+ }
171
+ };
172
+ export const getBinaryFilteredButtons = (nodeContent) => {
173
+ if (!Array.isArray(nodeContent)) return false
174
+
175
+ return nodeContent.some(a =>
176
+ ['native_flow'].includes(a?.content?.[0]?.content?.[0]?.tag) ||
177
+ ['interactive', 'buttons', 'list'].includes(a?.content?.[0]?.tag) ||
178
+ ['hsm', 'biz'].includes(a?.tag)
179
+ )
180
+ }
181
+ export const getBinaryNodeChildUInt = (node, childTag, length) => {
182
+ const buff = getBinaryNodeChildBuffer(node, childTag);
183
+ if (buff) {
184
+ return bufferToUInt(buff, length);
185
+ }
186
+ };
187
+ export const assertNodeErrorFree = (node) => {
188
+ const errNode = getBinaryNodeChild(node, 'error');
189
+ if (errNode) {
190
+ const errorCode = +errNode.attrs.code;
191
+ if (errorCode === 429) {
192
+ const error = new Boom('Rate limit', { data: 429 });
193
+ error.isRateLimit = true;
194
+ throw error;
195
+ }
196
+ throw new Boom(errNode.attrs.text || 'Unknown error', { data: errorCode });
197
+ }
198
+ };
199
+ export const reduceBinaryNodeToDictionary = (node, tag) => {
200
+ const nodes = getBinaryNodeChildren(node, tag);
201
+ const dict = nodes.reduce((dict, { attrs }) => {
202
+ if (typeof attrs.name === 'string') {
203
+ dict[attrs.name] = attrs.value || attrs.config_value;
204
+ }
205
+ else {
206
+ dict[attrs.config_code] = attrs.value || attrs.config_value;
207
+ }
208
+ return dict;
209
+ }, {});
210
+ return dict;
211
+ };
212
+ export const getBinaryNodeMessages = ({ content }) => {
213
+ const msgs = [];
214
+ if (Array.isArray(content)) {
215
+ for (const item of content) {
216
+ if (item.tag === 'message') {
217
+ msgs.push(proto.WebMessageInfo.decode(item.content).toJSON());
218
+ }
219
+ }
220
+ }
221
+ return msgs;
222
+ };
223
+ function bufferToUInt(e, t) {
224
+ let a = 0;
225
+ for (let i = 0; i < t; i++) {
226
+ a = 256 * a + e[i];
227
+ }
228
+ return a;
229
+ }
230
+ const tabs = (n) => '\t'.repeat(n);
231
+ export function binaryNodeToString(node, i = 0) {
232
+ if (!node) {
233
+ return node;
234
+ }
235
+ if (typeof node === 'string') {
236
+ return tabs(i) + node;
237
+ }
238
+ if (node instanceof Uint8Array) {
239
+ return tabs(i) + Buffer.from(node).toString('hex');
240
+ }
241
+ if (Array.isArray(node)) {
242
+ return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
243
+ }
244
+ const children = binaryNodeToString(node.content, i + 1);
245
+ const tag = `<${node.tag} ${Object.entries(node.attrs || {})
246
+ .filter(([, v]) => v !== undefined)
247
+ .map(([k, v]) => `${k}='${v}'`)
248
+ .join(' ')}`;
249
+ const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
250
+ return tag + content;
251
+ }
252
+ //# sourceMappingURL=generic-utils.js.map
@@ -1,6 +1,6 @@
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';
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';
6
6
  //# sourceMappingURL=index.js.map