@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.
Files changed (220) hide show
  1. package/LICENSE +4 -2
  2. package/README.md +107 -245
  3. package/WAProto/index.d.ts +15795 -0
  4. package/WAProto/index.js +25587 -4867
  5. package/lib/Defaults/index.d.ts +147 -0
  6. package/lib/Defaults/index.js +134 -104
  7. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  8. package/lib/Signal/Group/ciphertext-message.js +9 -11
  9. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  10. package/lib/Signal/Group/group-session-builder.js +5 -8
  11. package/lib/Signal/Group/group_cipher.d.ts +11 -0
  12. package/lib/Signal/Group/group_cipher.js +72 -75
  13. package/lib/Signal/Group/index.d.ts +12 -0
  14. package/lib/Signal/Group/index.js +11 -13
  15. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  16. package/lib/Signal/Group/keyhelper.js +11 -14
  17. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  18. package/lib/Signal/Group/sender-chain-key.js +23 -26
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
  21. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  22. package/lib/Signal/Group/sender-key-message.js +61 -64
  23. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  24. package/lib/Signal/Group/sender-key-name.js +39 -44
  25. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  26. package/lib/Signal/Group/sender-key-record.js +35 -38
  27. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  28. package/lib/Signal/Group/sender-key-state.js +76 -79
  29. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  30. package/lib/Signal/Group/sender-message-key.js +23 -26
  31. package/lib/Signal/libsignal.d.ts +55 -0
  32. package/lib/Signal/libsignal.js +414 -308
  33. package/lib/Signal/lid-mapping.d.ts +21 -0
  34. package/lib/Signal/lid-mapping.js +270 -149
  35. package/lib/Socket/Client/index.d.ts +3 -0
  36. package/lib/Socket/Client/index.js +2 -4
  37. package/lib/Socket/Client/types.d.ts +6 -0
  38. package/lib/Socket/Client/types.js +8 -11
  39. package/lib/Socket/Client/websocket.d.ts +13 -0
  40. package/lib/Socket/Client/websocket.js +51 -50
  41. package/lib/Socket/business.d.ts +395 -0
  42. package/lib/Socket/business.js +357 -355
  43. package/lib/Socket/chats.d.ts +137 -0
  44. package/lib/Socket/chats.js +1195 -867
  45. package/lib/Socket/communities.d.ts +562 -0
  46. package/lib/Socket/communities.js +416 -398
  47. package/lib/Socket/dugong.js +8 -1
  48. package/lib/Socket/groups.d.ts +286 -0
  49. package/lib/Socket/groups.js +336 -301
  50. package/lib/Socket/index.d.ts +530 -0
  51. package/lib/Socket/index.js +8 -13
  52. package/lib/Socket/messages-recv.d.ts +334 -0
  53. package/lib/Socket/messages-recv.js +1729 -1121
  54. package/lib/Socket/messages-send.d.ts +330 -0
  55. package/lib/Socket/messages-send.js +684 -462
  56. package/lib/Socket/mex.d.ts +2 -0
  57. package/lib/Socket/mex.js +36 -40
  58. package/lib/Socket/newsletter.d.ts +284 -0
  59. package/lib/Socket/newsletter.js +247 -237
  60. package/lib/Socket/socket.d.ts +61 -0
  61. package/lib/Socket/socket.js +968 -790
  62. package/lib/Store/index.d.ts +4 -0
  63. package/lib/Store/index.js +4 -6
  64. package/lib/Store/make-cache-manager-store.js +2 -2
  65. package/lib/Store/make-in-memory-store.d.ts +63 -0
  66. package/lib/Store/make-in-memory-store.js +414 -284
  67. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  68. package/lib/Store/make-ordered-dictionary.js +75 -76
  69. package/lib/Store/object-repository.d.ts +11 -0
  70. package/lib/Store/object-repository.js +21 -23
  71. package/lib/Types/Auth.d.ts +2 -0
  72. package/lib/Types/Auth.js +0 -2
  73. package/lib/Types/Bussines.d.ts +2 -0
  74. package/lib/Types/Bussines.js +0 -2
  75. package/lib/Types/Call.d.ts +2 -0
  76. package/lib/Types/Call.js +0 -2
  77. package/lib/Types/Chat.d.ts +2 -0
  78. package/lib/Types/Chat.js +5 -7
  79. package/lib/Types/Contact.d.ts +2 -0
  80. package/lib/Types/Contact.js +0 -2
  81. package/lib/Types/Events.d.ts +2 -0
  82. package/lib/Types/Events.js +1 -3
  83. package/lib/Types/GroupMetadata.d.ts +2 -0
  84. package/lib/Types/GroupMetadata.js +0 -2
  85. package/lib/Types/Label.d.ts +3 -0
  86. package/lib/Types/Label.js +21 -22
  87. package/lib/Types/LabelAssociation.d.ts +3 -0
  88. package/lib/Types/LabelAssociation.js +3 -4
  89. package/lib/Types/Message.d.ts +12 -0
  90. package/lib/Types/Message.js +11 -6
  91. package/lib/Types/Mex.d.ts +3 -0
  92. package/lib/Types/Mex.js +38 -0
  93. package/lib/Types/Product.d.ts +2 -0
  94. package/lib/Types/Product.js +0 -2
  95. package/lib/Types/RichType.d.ts +3 -0
  96. package/lib/Types/RichType.js +22 -0
  97. package/lib/Types/Signal.d.ts +2 -0
  98. package/lib/Types/Signal.js +1 -3
  99. package/lib/Types/Socket.d.ts +2 -0
  100. package/lib/Types/Socket.js +1 -4
  101. package/lib/Types/State.d.ts +6 -0
  102. package/lib/Types/State.js +52 -8
  103. package/lib/Types/USync.d.ts +2 -0
  104. package/lib/Types/USync.js +1 -3
  105. package/lib/Types/index.d.ts +14 -0
  106. package/lib/Types/index.js +22 -25
  107. package/lib/Utils/auth-utils.d.ts +58 -0
  108. package/lib/Utils/auth-utils.js +285 -203
  109. package/lib/Utils/browser-utils.d.ts +9 -0
  110. package/lib/Utils/browser-utils.js +21 -19
  111. package/lib/Utils/business.d.ts +50 -0
  112. package/lib/Utils/business.js +206 -209
  113. package/lib/Utils/chat-utils.d.ts +409 -0
  114. package/lib/Utils/chat-utils.js +825 -706
  115. package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
  116. package/lib/Utils/companion-reg-client-utils.js +39 -0
  117. package/lib/Utils/crypto.d.ts +40 -0
  118. package/lib/Utils/crypto.js +88 -101
  119. package/lib/Utils/decode-wa-message.d.ts +84 -0
  120. package/lib/Utils/decode-wa-message.js +287 -238
  121. package/lib/Utils/event-buffer.d.ts +13 -0
  122. package/lib/Utils/event-buffer.js +602 -509
  123. package/lib/Utils/generics.d.ts +64 -0
  124. package/lib/Utils/generics.js +334 -295
  125. package/lib/Utils/history.d.ts +76 -0
  126. package/lib/Utils/history.js +125 -79
  127. package/lib/Utils/identity-change-handler.d.ts +14 -0
  128. package/lib/Utils/identity-change-handler.js +49 -0
  129. package/lib/Utils/index.d.ts +25 -0
  130. package/lib/Utils/index.js +25 -21
  131. package/lib/Utils/link-preview.d.ts +13 -0
  132. package/lib/Utils/link-preview.js +73 -70
  133. package/lib/Utils/logger.d.ts +3 -0
  134. package/lib/Utils/logger.js +1 -4
  135. package/lib/Utils/lt-hash.d.ts +7 -0
  136. package/lib/Utils/lt-hash.js +7 -45
  137. package/lib/Utils/make-mutex.d.ts +7 -0
  138. package/lib/Utils/make-mutex.js +27 -31
  139. package/lib/Utils/message-retry-manager.d.ts +80 -0
  140. package/lib/Utils/message-retry-manager.js +165 -14
  141. package/lib/Utils/messages-media.d.ts +137 -0
  142. package/lib/Utils/messages-media.js +768 -572
  143. package/lib/Utils/messages.d.ts +46 -0
  144. package/lib/Utils/messages.js +1082 -130
  145. package/lib/Utils/noise-handler.d.ts +21 -0
  146. package/lib/Utils/noise-handler.js +191 -135
  147. package/lib/Utils/offline-node-processor.d.ts +10 -0
  148. package/lib/Utils/offline-node-processor.js +39 -0
  149. package/lib/Utils/pre-key-manager.d.ts +26 -0
  150. package/lib/Utils/pre-key-manager.js +96 -76
  151. package/lib/Utils/process-message.d.ts +84 -0
  152. package/lib/Utils/process-message.js +718 -311
  153. package/lib/Utils/reporting-utils.d.ts +13 -0
  154. package/lib/Utils/reporting-utils.js +257 -0
  155. package/lib/Utils/rich-message-utils.d.ts +49 -0
  156. package/lib/Utils/rich-message-utils.js +257 -0
  157. package/lib/Utils/signal.d.ts +83 -0
  158. package/lib/Utils/signal.js +174 -135
  159. package/lib/Utils/stanza-ack.d.ts +17 -0
  160. package/lib/Utils/stanza-ack.js +37 -0
  161. package/lib/Utils/sync-action-utils.d.ts +3 -0
  162. package/lib/Utils/sync-action-utils.js +48 -0
  163. package/lib/Utils/tc-token-utils.d.ts +30 -0
  164. package/lib/Utils/tc-token-utils.js +162 -0
  165. package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
  166. package/lib/Utils/use-multi-file-auth-state.js +104 -95
  167. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  168. package/lib/Utils/use-single-file-auth-state.js +108 -0
  169. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  170. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  171. package/lib/Utils/validate-connection.d.ts +44 -0
  172. package/lib/Utils/validate-connection.js +182 -180
  173. package/lib/WABinary/constants.d.ts +62 -0
  174. package/lib/WABinary/constants.js +1455 -1292
  175. package/lib/WABinary/decode.d.ts +10 -0
  176. package/lib/WABinary/decode.js +249 -228
  177. package/lib/WABinary/encode.d.ts +3 -0
  178. package/lib/WABinary/encode.js +207 -206
  179. package/lib/WABinary/generic-utils.d.ts +77 -0
  180. package/lib/WABinary/generic-utils.js +135 -99
  181. package/lib/WABinary/index.d.ts +6 -0
  182. package/lib/WABinary/index.js +5 -7
  183. package/lib/WABinary/jid-utils.d.ts +29 -0
  184. package/lib/WABinary/jid-utils.js +80 -78
  185. package/lib/WABinary/types.d.ts +2 -0
  186. package/lib/WABinary/types.js +1 -3
  187. package/lib/WAM/BinaryInfo.d.ts +8 -0
  188. package/lib/WAM/BinaryInfo.js +7 -9
  189. package/lib/WAM/constants.d.ts +34927 -0
  190. package/lib/WAM/constants.js +22847 -22848
  191. package/lib/WAM/encode.d.ts +2 -0
  192. package/lib/WAM/encode.js +129 -134
  193. package/lib/WAM/index.d.ts +4 -0
  194. package/lib/WAM/index.js +3 -5
  195. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  196. package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
  197. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  198. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
  199. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  200. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
  201. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  202. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
  203. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  204. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  205. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
  209. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  210. package/lib/WAUSync/Protocols/index.js +5 -6
  211. package/lib/WAUSync/USyncQuery.d.ts +21 -0
  212. package/lib/WAUSync/USyncQuery.js +92 -85
  213. package/lib/WAUSync/USyncUser.d.ts +17 -0
  214. package/lib/WAUSync/USyncUser.js +28 -22
  215. package/lib/WAUSync/index.d.ts +4 -0
  216. package/lib/WAUSync/index.js +3 -5
  217. package/lib/index.d.ts +12 -0
  218. package/lib/index.js +31 -19
  219. package/package.json +12 -6
  220. 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
- import {} from './types.js';
4
- import { unixTimestampSeconds } from '../Utils/index.js';
5
-
4
+ // some extra useful utilities
5
+ const indexCache = new WeakMap();
6
6
  export const getBinaryNodeChildren = (node, childTag) => {
7
- if (Array.isArray(node?.content)) {
8
- return node.content.filter(item => item.tag === childTag);
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
- return [];
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
- export const getBinaryNodeFilter = (node) => {
104
- if (!Array.isArray(node)) return false
105
-
106
- return node.some(item =>
107
- ['native_flow'].includes(item?.content?.[0]?.content?.[0]?.tag) ||
108
- ['interactive', 'buttons', 'list'].includes(item?.content?.[0]?.tag) ||
109
- ['hsm', 'biz'].includes(item?.tag) ||
110
- ['bot'].includes(item?.tag) && item?.attrs?.biz_bot === '1'
111
- )
112
- }
113
- export const getAdditionalNode = (name) => {
114
- if (name) name = name.toLowerCase()
115
- const ts = unixTimestampSeconds(new Date()) - 77980457
116
-
117
- const order_response_name = {
118
- review_and_pay: 'order_details',
119
- review_order: 'order_status',
120
- payment_info: 'payment_info',
121
- payment_status: 'payment_status',
122
- payment_method: 'payment_method'
123
- }
124
-
125
- const flow_name = {
126
- cta_catalog: 'cta_catalog',
127
- mpm: 'mpm',
128
- call_request: 'call_permission_request',
129
- view_catalog: 'automated_greeting_message_view_catalog',
130
- wa_pay_detail: 'wa_payment_transaction_details',
131
- send_location: 'send_location',
132
- }
133
-
134
- if(order_response_name[name]) {
135
- return [{
136
- tag: 'biz',
137
- attrs: {
138
- native_flow_name: order_response_name[name]
139
- },
140
- content: []
141
- }]
142
- } else if (flow_name[name] || name === 'interactive' || name === 'buttons') {
143
- return [{
144
- tag: 'biz',
145
- attrs: {
146
- actual_actors: '2',
147
- host_storage: '2',
148
- privacy_mode_ts: `${ts}`
149
- },
150
- content: [{
151
- tag: 'engagement',
152
- attrs: {
153
- customer_service_state: 'open',
154
- conversation_state: 'open'
155
- }
156
- }, {
157
- tag: 'interactive',
158
- attrs: {
159
- type: 'native_flow',
160
- v: '1'
161
- },
162
- content: [{
163
- tag: 'native_flow',
164
- attrs: {
165
- v: '9',
166
- name: flow_name[name] ?? 'mixed',
167
- },
168
- content: []
169
- }]
170
- }]
171
- }]
172
- } else {
173
- return [{
174
- tag: 'biz',
175
- attrs: {
176
- actual_actors: '2',
177
- host_storage: '2',
178
- privacy_mode_ts: `${ts}`
179
- },
180
- content: [{
181
- tag: 'engagement',
182
- attrs: {
183
- customer_service_state: 'open',
184
- conversation_state: 'open'
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
+ };
@@ -0,0 +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";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,5 @@
1
- //=======================================================//
2
- export * from "./generic-utils.js";
3
- export * from "./jid-utils.js";
4
- export * from "./encode.js";
5
- export * from "./decode.js";
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 = "16505361212@c.us";
3
- export const S_WHATSAPP_NET = "@s.whatsapp.net";
4
- export const STORIES_JID = "status@broadcast";
5
- export const META_AI_JID = "13135550002@c.us";
6
- export const SERVER_JID = "server@c.us";
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
- WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
12
- WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
13
- WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
14
- WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
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
- switch (domainType) {
18
- case WAJIDDomains.LID:
19
- return "lid";
20
- case WAJIDDomains.HOSTED:
21
- return "hosted";
22
- case WAJIDDomains.HOSTED_LID:
23
- return "hosted.lid";
24
- case WAJIDDomains.WHATSAPP:
25
- default:
26
- return initialServer;
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
- return `${user || ""}${!!agent ? `_${agent}` : ""}${!!device ? `:${device}` : ""}@${server}`;
28
+ return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server || 'lid'}`;
32
29
  };
33
- //=======================================================//
34
30
  export const jidDecode = (jid) => {
35
- const sepIdx = typeof jid === "string" ? jid.indexOf("@") : -1;
36
- if (sepIdx < 0) {
37
- return undefined;
38
- }
39
- const server = jid.slice(sepIdx + 1);
40
- const userCombined = jid.slice(0, sepIdx);
41
- const [userAgent, device] = userCombined.split(":");
42
- const [user, agent] = userAgent.split("_");
43
- let domainType = WAJIDDomains.WHATSAPP;
44
- if (server === "lid") {
45
- domainType = WAJIDDomains.LID;
46
- }
47
- else if (server === "hosted") {
48
- domainType = WAJIDDomains.HOSTED;
49
- }
50
- else if (server === "hosted.lid") {
51
- domainType = WAJIDDomains.HOSTED_LID;
52
- }
53
- else if (agent) {
54
- domainType = parseInt(agent);
55
- }
56
- return {
57
- server: server,
58
- user: user,
59
- domainType,
60
- device: device ? +device : undefined
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
- export const isJidMetaAI = (jid) => jid?.endsWith("@bot");
66
- export const isPnUser = (jid) => jid?.endsWith("@s.whatsapp.net");
67
- export const isLidUser = (jid) => jid?.endsWith("@lid");
68
- export const isJidBroadcast = (jid) => jid?.endsWith("@broadcast");
69
- export const isJidGroup = (jid) => jid?.endsWith("@g.us");
70
- export const isJidStatusBroadcast = (jid) => jid === "status@broadcast";
71
- export const isJidNewsletter = (jid) => jid?.endsWith("@newsletter");
72
- export const isHostedPnUser = (jid) => jid?.endsWith("@hosted");
73
- export const isHostedLidUser = (jid) => jid?.endsWith("@hosted.lid");
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
- const result = jidDecode(jid);
80
- if (!result) {
81
- return "";
82
- }
83
- const { user, server } = result;
84
- return jidEncode(user, server === "c.us" ? "s.whatsapp.net" : server);
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
- const fromDecoded = jidDecode(fromJid);
89
- const deviceId = fromDecoded?.device || 0;
90
- const { server, user } = jidDecode(toJid);
91
- return jidEncode(user, server, deviceId);
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
- //=======================================================//
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.d.ts.map
@@ -1,3 +1 @@
1
- //=======================================================//
2
- import * as constants from "./constants.js";
3
- //=======================================================//
1
+ import * as constants from './constants.js';
@@ -0,0 +1,8 @@
1
+ export class BinaryInfo {
2
+ constructor(options?: {});
3
+ protocolVersion: number;
4
+ sequence: number;
5
+ events: any[];
6
+ buffer: any[];
7
+ }
8
+ //# sourceMappingURL=BinaryInfo.d.ts.map
@@ -1,11 +1,9 @@
1
- //=======================================================//
2
1
  export class BinaryInfo {
3
- constructor(options = {}) {
4
- this.protocolVersion = 5;
5
- this.sequence = 0;
6
- this.events = [];
7
- this.buffer = [];
8
- Object.assign(this, options);
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
- //=======================================================//