@nerxa/socketon 0.0.0-stage → 1.21.1

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 (289) hide show
  1. package/EXPERIMENTAL.md +350 -0
  2. package/LICENSE +24 -0
  3. package/README.md +6317 -2
  4. package/WAProto/index.d.ts +17301 -0
  5. package/WAProto/index.js +125088 -0
  6. package/engine-requirements.js +14 -0
  7. package/package.json +125 -4
  8. package/src/Defaults/index.d.ts +152 -0
  9. package/src/Defaults/index.js +164 -0
  10. package/src/MessageBuilder/bot-signature.d.ts +22 -0
  11. package/src/MessageBuilder/bot-signature.js +122 -0
  12. package/src/MessageBuilder/extras.d.ts +449 -0
  13. package/src/MessageBuilder/extras.js +1356 -0
  14. package/src/MessageBuilder/index.d.ts +210 -0
  15. package/src/MessageBuilder/index.js +3594 -0
  16. package/src/MessageBuilder/metaai.d.ts +438 -0
  17. package/src/MessageBuilder/metaai.js +890 -0
  18. package/src/Signal/Group/ciphertext-message.d.ts +9 -0
  19. package/src/Signal/Group/ciphertext-message.js +11 -0
  20. package/src/Signal/Group/group-session-builder.d.ts +7 -0
  21. package/src/Signal/Group/group-session-builder.js +27 -0
  22. package/src/Signal/Group/group_cipher.d.ts +11 -0
  23. package/src/Signal/Group/group_cipher.js +78 -0
  24. package/src/Signal/Group/index.d.ts +11 -0
  25. package/src/Signal/Group/index.js +11 -0
  26. package/src/Signal/Group/keyhelper.d.ts +6 -0
  27. package/src/Signal/Group/keyhelper.js +17 -0
  28. package/src/Signal/Group/sender-chain-key.d.ts +13 -0
  29. package/src/Signal/Group/sender-chain-key.js +25 -0
  30. package/src/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  31. package/src/Signal/Group/sender-key-distribution-message.js +62 -0
  32. package/src/Signal/Group/sender-key-message.d.ts +18 -0
  33. package/src/Signal/Group/sender-key-message.js +65 -0
  34. package/src/Signal/Group/sender-key-name.d.ts +11 -0
  35. package/src/Signal/Group/sender-key-name.js +47 -0
  36. package/src/Signal/Group/sender-key-record.d.ts +12 -0
  37. package/src/Signal/Group/sender-key-record.js +40 -0
  38. package/src/Signal/Group/sender-key-state.d.ts +16 -0
  39. package/src/Signal/Group/sender-key-state.js +83 -0
  40. package/src/Signal/Group/sender-message-key.d.ts +11 -0
  41. package/src/Signal/Group/sender-message-key.js +25 -0
  42. package/src/Signal/libsignal.d.ts +54 -0
  43. package/src/Signal/libsignal.js +427 -0
  44. package/src/Signal/lid-mapping.d.ts +20 -0
  45. package/src/Signal/lid-mapping.js +274 -0
  46. package/src/Socket/Client/index.d.ts +2 -0
  47. package/src/Socket/Client/index.js +3 -0
  48. package/src/Socket/Client/tcp.js +177 -0
  49. package/src/Socket/Client/types.d.ts +5 -0
  50. package/src/Socket/Client/types.js +9 -0
  51. package/src/Socket/Client/websocket.d.ts +12 -0
  52. package/src/Socket/Client/websocket.js +53 -0
  53. package/src/Socket/business.d.ts +431 -0
  54. package/src/Socket/business.js +379 -0
  55. package/src/Socket/chats.d.ts +247 -0
  56. package/src/Socket/chats.js +1484 -0
  57. package/src/Socket/communities.d.ts +598 -0
  58. package/src/Socket/communities.js +421 -0
  59. package/src/Socket/email.js +145 -0
  60. package/src/Socket/groups.d.ts +298 -0
  61. package/src/Socket/groups.js +339 -0
  62. package/src/Socket/index.d.ts +581 -0
  63. package/src/Socket/index.js +77 -0
  64. package/src/Socket/messages-recv.d.ts +370 -0
  65. package/src/Socket/messages-recv.js +1864 -0
  66. package/src/Socket/messages-send.d.ts +390 -0
  67. package/src/Socket/messages-send.js +1574 -0
  68. package/src/Socket/mex.d.ts +1 -0
  69. package/src/Socket/mex.js +44 -0
  70. package/src/Socket/mobile-builders.js +72 -0
  71. package/src/Socket/mobile.js +424 -0
  72. package/src/Socket/newsletter.d.ts +468 -0
  73. package/src/Socket/newsletter.js +671 -0
  74. package/src/Socket/socket.d.ts +77 -0
  75. package/src/Socket/socket.js +1106 -0
  76. package/src/Store/index.d.ts +3 -0
  77. package/src/Store/index.js +3 -0
  78. package/src/Store/make-in-memory-store.d.ts +62 -0
  79. package/src/Store/make-in-memory-store.js +396 -0
  80. package/src/Store/make-ordered-dictionary.d.ts +12 -0
  81. package/src/Store/make-ordered-dictionary.js +78 -0
  82. package/src/Store/object-repository.d.ts +10 -0
  83. package/src/Store/object-repository.js +23 -0
  84. package/src/Types/Auth.d.ts +1 -0
  85. package/src/Types/Auth.js +1 -0
  86. package/src/Types/Bussines.d.ts +1 -0
  87. package/src/Types/Bussines.js +1 -0
  88. package/src/Types/Call.d.ts +1 -0
  89. package/src/Types/Call.js +1 -0
  90. package/src/Types/Chat.d.ts +2 -0
  91. package/src/Types/Chat.js +24 -0
  92. package/src/Types/Contact.d.ts +1 -0
  93. package/src/Types/Contact.js +1 -0
  94. package/src/Types/Events.d.ts +1 -0
  95. package/src/Types/Events.js +0 -0
  96. package/src/Types/GroupMetadata.d.ts +5 -0
  97. package/src/Types/GroupMetadata.js +6 -0
  98. package/src/Types/Label.d.ts +2 -0
  99. package/src/Types/Label.js +24 -0
  100. package/src/Types/LabelAssociation.d.ts +2 -0
  101. package/src/Types/LabelAssociation.js +6 -0
  102. package/src/Types/Message.d.ts +13 -0
  103. package/src/Types/Message.js +23 -0
  104. package/src/Types/Mex.d.ts +2 -0
  105. package/src/Types/Mex.js +95 -0
  106. package/src/Types/Product.d.ts +1 -0
  107. package/src/Types/Product.js +1 -0
  108. package/src/Types/Signal.d.ts +1 -0
  109. package/src/Types/Signal.js +0 -0
  110. package/src/Types/Socket.d.ts +1 -0
  111. package/src/Types/Socket.js +0 -0
  112. package/src/Types/State.d.ts +5 -0
  113. package/src/Types/State.js +54 -0
  114. package/src/Types/USync.d.ts +1 -0
  115. package/src/Types/USync.js +0 -0
  116. package/src/Types/index.d.ts +13 -0
  117. package/src/Types/index.js +25 -0
  118. package/src/Utils/auth-store.d.ts +29 -0
  119. package/src/Utils/auth-store.js +76 -0
  120. package/src/Utils/auth-utils.d.ts +58 -0
  121. package/src/Utils/auth-utils.js +273 -0
  122. package/src/Utils/browser-utils.d.ts +9 -0
  123. package/src/Utils/browser-utils.js +28 -0
  124. package/src/Utils/business.d.ts +49 -0
  125. package/src/Utils/business.js +226 -0
  126. package/src/Utils/chat-utils.d.ts +408 -0
  127. package/src/Utils/chat-utils.js +846 -0
  128. package/src/Utils/companion-reg-client-utils.d.ts +4 -0
  129. package/src/Utils/companion-reg-client-utils.js +39 -0
  130. package/src/Utils/crypto.d.ts +39 -0
  131. package/src/Utils/crypto.js +110 -0
  132. package/src/Utils/decode-wa-message.d.ts +99 -0
  133. package/src/Utils/decode-wa-message.js +373 -0
  134. package/src/Utils/event-buffer.d.ts +22 -0
  135. package/src/Utils/event-buffer.js +624 -0
  136. package/src/Utils/generics.d.ts +63 -0
  137. package/src/Utils/generics.js +375 -0
  138. package/src/Utils/group-metadata-cache.d.ts +4 -0
  139. package/src/Utils/group-metadata-cache.js +25 -0
  140. package/src/Utils/history.d.ts +75 -0
  141. package/src/Utils/history.js +131 -0
  142. package/src/Utils/html-app.d.ts +19 -0
  143. package/src/Utils/html-app.js +96 -0
  144. package/src/Utils/html-multiplayer.d.ts +10 -0
  145. package/src/Utils/html-multiplayer.js +94 -0
  146. package/src/Utils/identity-change-handler.d.ts +13 -0
  147. package/src/Utils/identity-change-handler.js +48 -0
  148. package/src/Utils/index.d.ts +44 -0
  149. package/src/Utils/index.js +44 -0
  150. package/src/Utils/link-preview-metadata.d.ts +47 -0
  151. package/src/Utils/link-preview-metadata.js +88 -0
  152. package/src/Utils/link-preview.d.ts +12 -0
  153. package/src/Utils/link-preview.js +79 -0
  154. package/src/Utils/logger.d.ts +2 -0
  155. package/src/Utils/logger.js +2 -0
  156. package/src/Utils/lt-hash.d.ts +6 -0
  157. package/src/Utils/lt-hash.js +3 -0
  158. package/src/Utils/make-mutex.d.ts +6 -0
  159. package/src/Utils/make-mutex.js +32 -0
  160. package/src/Utils/message-retry-manager.d.ts +79 -0
  161. package/src/Utils/message-retry-manager.js +255 -0
  162. package/src/Utils/messages-media.d.ts +136 -0
  163. package/src/Utils/messages-media.js +814 -0
  164. package/src/Utils/messages.d.ts +62 -0
  165. package/src/Utils/messages.js +2223 -0
  166. package/src/Utils/mobile-companion-crypto.js +191 -0
  167. package/src/Utils/modern-messages.d.ts +150 -0
  168. package/src/Utils/modern-messages.js +496 -0
  169. package/src/Utils/native-flow.d.ts +11 -0
  170. package/src/Utils/native-flow.js +115 -0
  171. package/src/Utils/newsletter-status.d.ts +158 -0
  172. package/src/Utils/newsletter-status.js +651 -0
  173. package/src/Utils/noise-handler.d.ts +20 -0
  174. package/src/Utils/noise-handler.js +200 -0
  175. package/src/Utils/offline-node-processor.d.ts +9 -0
  176. package/src/Utils/offline-node-processor.js +33 -0
  177. package/src/Utils/optional-media.d.ts +3 -0
  178. package/src/Utils/optional-media.js +45 -0
  179. package/src/Utils/payment-messages.d.ts +66 -0
  180. package/src/Utils/payment-messages.js +160 -0
  181. package/src/Utils/pre-key-manager.d.ts +25 -0
  182. package/src/Utils/pre-key-manager.js +95 -0
  183. package/src/Utils/process-message.d.ts +60 -0
  184. package/src/Utils/process-message.js +688 -0
  185. package/src/Utils/reporting-utils.d.ts +12 -0
  186. package/src/Utils/reporting-utils.js +256 -0
  187. package/src/Utils/scheduled-message.d.ts +51 -0
  188. package/src/Utils/scheduled-message.js +112 -0
  189. package/src/Utils/sender-key-memory.d.ts +19 -0
  190. package/src/Utils/sender-key-memory.js +51 -0
  191. package/src/Utils/signal.d.ts +82 -0
  192. package/src/Utils/signal.js +193 -0
  193. package/src/Utils/stanza-ack.d.ts +16 -0
  194. package/src/Utils/stanza-ack.js +30 -0
  195. package/src/Utils/status-stickers.d.ts +127 -0
  196. package/src/Utils/status-stickers.js +260 -0
  197. package/src/Utils/sync-action-utils.d.ts +2 -0
  198. package/src/Utils/sync-action-utils.js +44 -0
  199. package/src/Utils/tc-token-utils.d.ts +29 -0
  200. package/src/Utils/tc-token-utils.js +155 -0
  201. package/src/Utils/ttl-cache.d.ts +28 -0
  202. package/src/Utils/ttl-cache.js +120 -0
  203. package/src/Utils/use-mongo-auth-state.d.ts +21 -0
  204. package/src/Utils/use-mongo-auth-state.js +67 -0
  205. package/src/Utils/use-multi-file-auth-state.d.ts +11 -0
  206. package/src/Utils/use-multi-file-auth-state.js +106 -0
  207. package/src/Utils/use-mysql-auth-state.d.ts +19 -0
  208. package/src/Utils/use-mysql-auth-state.js +79 -0
  209. package/src/Utils/use-postgres-auth-state.d.ts +19 -0
  210. package/src/Utils/use-postgres-auth-state.js +79 -0
  211. package/src/Utils/use-redis-auth-state.d.ts +19 -0
  212. package/src/Utils/use-redis-auth-state.js +89 -0
  213. package/src/Utils/use-single-file-auth-state.d.ts +10 -0
  214. package/src/Utils/use-single-file-auth-state.js +108 -0
  215. package/src/Utils/use-sqlite-auth-state.d.ts +12 -0
  216. package/src/Utils/use-sqlite-auth-state.js +120 -0
  217. package/src/Utils/useNekoDBAuth.d.ts +19 -0
  218. package/src/Utils/useNekoDBAuth.js +111 -0
  219. package/src/Utils/username.d.ts +12 -0
  220. package/src/Utils/username.js +58 -0
  221. package/src/Utils/validate-connection.d.ts +43 -0
  222. package/src/Utils/validate-connection.js +277 -0
  223. package/src/Utils/voice-recognition.d.ts +53 -0
  224. package/src/Utils/voice-recognition.js +219 -0
  225. package/src/Voip/audio-feeder.d.ts +24 -0
  226. package/src/Voip/audio-feeder.js +268 -0
  227. package/src/Voip/index.d.ts +88 -0
  228. package/src/Voip/index.js +936 -0
  229. package/src/Voip/relay-transport.d.ts +5 -0
  230. package/src/Voip/relay-transport.js +824 -0
  231. package/src/Voip/signaling.d.ts +11 -0
  232. package/src/Voip/signaling.js +1099 -0
  233. package/src/Voip/types.d.ts +2 -0
  234. package/src/Voip/types.js +12 -0
  235. package/src/Voip/video-feeder.d.ts +24 -0
  236. package/src/Voip/video-feeder.js +268 -0
  237. package/src/Voip/wasm-engine.d.ts +26 -0
  238. package/src/Voip/wasm-engine.js +1307 -0
  239. package/src/Voip/worker-bootstrap.js +1023 -0
  240. package/src/WABinary/constants.d.ts +22 -0
  241. package/src/WABinary/constants.js +1300 -0
  242. package/src/WABinary/decode.d.ts +9 -0
  243. package/src/WABinary/decode.js +261 -0
  244. package/src/WABinary/encode.d.ts +2 -0
  245. package/src/WABinary/encode.js +219 -0
  246. package/src/WABinary/generic-utils.d.ts +76 -0
  247. package/src/WABinary/generic-utils.js +214 -0
  248. package/src/WABinary/index.d.ts +5 -0
  249. package/src/WABinary/index.js +5 -0
  250. package/src/WABinary/jid-utils.d.ts +30 -0
  251. package/src/WABinary/jid-utils.js +97 -0
  252. package/src/WABinary/types.d.ts +1 -0
  253. package/src/WABinary/types.js +0 -0
  254. package/src/WAM/BinaryInfo.d.ts +7 -0
  255. package/src/WAM/BinaryInfo.js +9 -0
  256. package/src/WAM/constants.d.ts +34926 -0
  257. package/src/WAM/constants.js +22852 -0
  258. package/src/WAM/encode.d.ts +1 -0
  259. package/src/WAM/encode.js +148 -0
  260. package/src/WAM/index.d.ts +3 -0
  261. package/src/WAM/index.js +3 -0
  262. package/src/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  263. package/src/WAUSync/Protocols/USyncContactProtocol.js +50 -0
  264. package/src/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  265. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +51 -0
  266. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  267. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  268. package/src/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  269. package/src/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  270. package/src/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  271. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
  272. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  273. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
  274. package/src/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  275. package/src/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  276. package/src/WAUSync/Protocols/index.d.ts +5 -0
  277. package/src/WAUSync/Protocols/index.js +5 -0
  278. package/src/WAUSync/USyncQuery.d.ts +20 -0
  279. package/src/WAUSync/USyncQuery.js +93 -0
  280. package/src/WAUSync/USyncUser.d.ts +16 -0
  281. package/src/WAUSync/USyncUser.js +30 -0
  282. package/src/WAUSync/index.d.ts +3 -0
  283. package/src/WAUSync/index.js +3 -0
  284. package/src/assets/wasm/README.md +76 -0
  285. package/src/assets/wasm/loader.js +5 -0
  286. package/src/assets/wasm/whatsapp.wasm +0 -0
  287. package/src/assets/wasm/worker-modules.js +273 -0
  288. package/src/index.d.ts +43 -0
  289. package/src/index.js +48 -0
@@ -0,0 +1,298 @@
1
+ export function makeGroupsSocket(config: any): {
2
+ groupQuery: (jid: any, type: any, content: any) => Promise<any>;
3
+ groupMetadata: (jid: any) => Promise<{
4
+ id: any;
5
+ notify: any;
6
+ addressingMode: any;
7
+ subject: any;
8
+ subjectOwner: any;
9
+ subjectOwnerPn: any;
10
+ subjectOwnerUsername: any;
11
+ subjectTime: number;
12
+ size: any;
13
+ creation: number;
14
+ owner: string | undefined;
15
+ ownerPn: string | undefined;
16
+ ownerUsername: any;
17
+ owner_country_code: any;
18
+ desc: any;
19
+ descId: any;
20
+ descOwner: string | undefined;
21
+ descOwnerPn: string | undefined;
22
+ descOwnerUsername: any;
23
+ descTime: number | undefined;
24
+ linkedParent: any;
25
+ restrict: boolean;
26
+ announce: boolean;
27
+ isCommunity: boolean;
28
+ isCommunityAnnounce: boolean;
29
+ joinApprovalMode: boolean;
30
+ memberAddMode: boolean;
31
+ participants: any;
32
+ ephemeralDuration: number | undefined;
33
+ }>;
34
+ groupCreate: (subject: any, participants: any) => Promise<{
35
+ id: any;
36
+ notify: any;
37
+ addressingMode: any;
38
+ subject: any;
39
+ subjectOwner: any;
40
+ subjectOwnerPn: any;
41
+ subjectOwnerUsername: any;
42
+ subjectTime: number;
43
+ size: any;
44
+ creation: number;
45
+ owner: string | undefined;
46
+ ownerPn: string | undefined;
47
+ ownerUsername: any;
48
+ owner_country_code: any;
49
+ desc: any;
50
+ descId: any;
51
+ descOwner: string | undefined;
52
+ descOwnerPn: string | undefined;
53
+ descOwnerUsername: any;
54
+ descTime: number | undefined;
55
+ linkedParent: any;
56
+ restrict: boolean;
57
+ announce: boolean;
58
+ isCommunity: boolean;
59
+ isCommunityAnnounce: boolean;
60
+ joinApprovalMode: boolean;
61
+ memberAddMode: boolean;
62
+ participants: any;
63
+ ephemeralDuration: number | undefined;
64
+ }>;
65
+ groupLeave: (id: any) => Promise<void>;
66
+ groupUpdateSubject: (jid: any, subject: any) => Promise<void>;
67
+ groupRequestParticipantsList: (jid: any) => Promise<any>;
68
+ groupRequestParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any>;
69
+ groupParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any>;
70
+ groupUpdateDescription: (jid: any, description: any) => Promise<void>;
71
+ groupInviteCode: (jid: any) => Promise<any>;
72
+ groupRevokeInvite: (jid: any) => Promise<any>;
73
+ groupAcceptInvite: (code: any) => Promise<any>;
74
+ /**
75
+ * revoke a v4 invite for someone
76
+ * @param groupJid group jid
77
+ * @param invitedJid jid of person you invited
78
+ * @returns true if successful
79
+ */
80
+ groupRevokeInviteV4: (groupJid: any, invitedJid: any) => Promise<boolean>;
81
+ /**
82
+ * accept a GroupInviteMessage
83
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
84
+ * @param inviteMessage the message to accept
85
+ */
86
+ groupAcceptInviteV4: (...args: any[]) => Promise<any>;
87
+ groupGetInviteInfo: (code: any) => Promise<{
88
+ id: any;
89
+ notify: any;
90
+ addressingMode: any;
91
+ subject: any;
92
+ subjectOwner: any;
93
+ subjectOwnerPn: any;
94
+ subjectOwnerUsername: any;
95
+ subjectTime: number;
96
+ size: any;
97
+ creation: number;
98
+ owner: string | undefined;
99
+ ownerPn: string | undefined;
100
+ ownerUsername: any;
101
+ owner_country_code: any;
102
+ desc: any;
103
+ descId: any;
104
+ descOwner: string | undefined;
105
+ descOwnerPn: string | undefined;
106
+ descOwnerUsername: any;
107
+ descTime: number | undefined;
108
+ linkedParent: any;
109
+ restrict: boolean;
110
+ announce: boolean;
111
+ isCommunity: boolean;
112
+ isCommunityAnnounce: boolean;
113
+ joinApprovalMode: boolean;
114
+ memberAddMode: boolean;
115
+ participants: any;
116
+ ephemeralDuration: number | undefined;
117
+ }>;
118
+ groupToggleEphemeral: (jid: any, ephemeralExpiration: any) => Promise<void>;
119
+ groupSettingUpdate: (jid: any, setting: any) => Promise<void>;
120
+ groupMemberAddMode: (jid: any, mode: any) => Promise<void>;
121
+ groupJoinApprovalMode: (jid: any, mode: any) => Promise<void>;
122
+ groupFetchAllParticipating: () => Promise<{}>;
123
+ findUserId: (pnLid: any) => Promise<{
124
+ lid: undefined;
125
+ phoneNumber: undefined;
126
+ }>;
127
+ serverProps: {
128
+ privacyTokenOn1to1: boolean;
129
+ profilePicPrivacyToken: boolean;
130
+ lidTrustedTokenIssueToLid: boolean;
131
+ };
132
+ createCallLink: (type: any, event: any, timeoutMs: any) => Promise<any>;
133
+ getBotListV2: () => Promise<{
134
+ jid: any;
135
+ personaId: any;
136
+ }[]>;
137
+ messageMutex: {
138
+ mutex(code: any): any;
139
+ };
140
+ receiptMutex: {
141
+ mutex(code: any): any;
142
+ };
143
+ appStatePatchMutex: {
144
+ mutex(code: any): any;
145
+ };
146
+ notificationMutex: {
147
+ mutex(code: any): any;
148
+ };
149
+ fetchPrivacySettings: (force?: boolean) => Promise<any>;
150
+ upsertMessage: (...args: any[]) => Promise<any>;
151
+ appPatch: (patchCreate: any) => Promise<void>;
152
+ sendPresenceUpdate: (type: any, toJid: any) => Promise<void>;
153
+ presenceSubscribe: (toJid: any) => Promise<void>;
154
+ profilePictureUrl: (jid: any, type?: string, timeoutMs?: number, shouldIncludeTcToken?: boolean) => Promise<any>;
155
+ fetchBlocklist: () => Promise<any>;
156
+ fetchStatus: (...jids: any[]) => Promise<any>;
157
+ fetchDisappearingDuration: (...jids: any[]) => Promise<any>;
158
+ updateProfilePicture: (jid: any, content: any, dimensions: any) => Promise<void>;
159
+ removeProfilePicture: (jid: any) => Promise<void>;
160
+ updateProfileStatus: (status: any) => Promise<void>;
161
+ updateProfileName: (name: any) => Promise<void>;
162
+ updateBlockStatus: (jid: any, action: any) => Promise<void>;
163
+ reportSpam: (jid: string, options?: {
164
+ flow?: string;
165
+ source?: string;
166
+ subject?: string;
167
+ isKnownChat?: boolean;
168
+ }) => Promise<{
169
+ jid: string;
170
+ flow: string;
171
+ reported: true;
172
+ node: any;
173
+ }>;
174
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: any) => Promise<void>;
175
+ updateCallPrivacy: (value: any) => Promise<void>;
176
+ updateMessagesPrivacy: (value: any) => Promise<void>;
177
+ updateLastSeenPrivacy: (value: any) => Promise<void>;
178
+ updateOnlinePrivacy: (value: any) => Promise<void>;
179
+ updateProfilePicturePrivacy: (value: any) => Promise<void>;
180
+ updateStatusPrivacy: (value: any) => Promise<void>;
181
+ updateReadReceiptsPrivacy: (value: any) => Promise<void>;
182
+ updateGroupsAddPrivacy: (value: any) => Promise<void>;
183
+ updateDefaultDisappearingMode: (duration: any) => Promise<void>;
184
+ getBusinessProfile: (jid: any) => Promise<{
185
+ wid: any;
186
+ address: any;
187
+ description: any;
188
+ website: any[];
189
+ email: any;
190
+ category: any;
191
+ business_hours: {
192
+ timezone: any;
193
+ business_config: any;
194
+ };
195
+ } | undefined>;
196
+ resyncAppState: (...args: any[]) => Promise<any>;
197
+ chatModify: (mod: any, jid: any) => Promise<void>;
198
+ cleanDirtyBits: (type: any, fromTimestamp: any) => Promise<void>;
199
+ addOrEditContact: (jid: any, contact: any) => Promise<void>;
200
+ removeContact: (jid: any) => Promise<void>;
201
+ placeholderResendCache: any;
202
+ addLabel: (jid: any, labels: any) => Promise<void>;
203
+ addChatLabel: (jid: any, labelId: any) => Promise<void>;
204
+ removeChatLabel: (jid: any, labelId: any) => Promise<void>;
205
+ addMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
206
+ removeMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
207
+ star: (jid: any, messages: any, star: any) => Promise<void>;
208
+ addOrEditQuickReply: (quickReply: any) => Promise<void>;
209
+ removeQuickReply: (timestamp: any) => Promise<void>;
210
+ type: string;
211
+ ws: import("./Client/websocket.js").WebSocketClient;
212
+ ev: {
213
+ process(handler: any): () => void;
214
+ emit(event: any, evData: any): any;
215
+ isBuffering(): boolean;
216
+ buffer: () => void;
217
+ flush: () => boolean;
218
+ createBufferedFunction(work: any): (...args: any[]) => Promise<any>;
219
+ on: (...args: any[]) => any;
220
+ off: (...args: any[]) => any;
221
+ removeAllListeners: (...args: any[]) => any;
222
+ destroy(): void;
223
+ };
224
+ authState: {
225
+ creds: any;
226
+ keys: {
227
+ get: (type: any, ids: any) => Promise<any>;
228
+ set: (data: any) => Promise<void>;
229
+ isInTransaction: () => boolean;
230
+ transaction: (work: any, key: any) => Promise<any>;
231
+ };
232
+ };
233
+ signalRepository: any;
234
+ user: any;
235
+ generateMessageTag: () => string;
236
+ query: (node: any, timeoutMs: any) => Promise<any>;
237
+ waitForMessage: (msgId: any, timeoutMs?: any) => Promise<any>;
238
+ waitForSocketOpen: () => Promise<void>;
239
+ sendRawMessage: (data: any) => Promise<void>;
240
+ sendNode: (frame: any) => Promise<void>;
241
+ logout: (msg: any) => Promise<void>;
242
+ end: (error: any) => Promise<void>;
243
+ registerSocketEndHandler: (handler: any) => void;
244
+ onUnexpectedError: (err: any, msg: any) => void;
245
+ uploadPreKeys: (count?: number) => Promise<void>;
246
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
247
+ digestKeyBundle: () => Promise<void>;
248
+ rotateSignedPreKey: () => Promise<void>;
249
+ requestPairingCode: (phoneNumber: any, customPairingCode: any) => Promise<any>;
250
+ updateServerTimeOffset: ({ attrs }: {
251
+ attrs: any;
252
+ }) => void;
253
+ sendUnifiedSession: () => Promise<void>;
254
+ wamBuffer: import("../index.js").BinaryInfo;
255
+ waitForConnectionUpdate: (check: any, timeoutMs: any) => Promise<void>;
256
+ sendWAMBuffer: (wamBuffer: any) => Promise<any>;
257
+ executeUSyncQuery: (usyncQuery: any) => Promise<any>;
258
+ onWhatsApp: (...phoneNumber: any[]) => Promise<any>;
259
+ onWhatsAppUsername: (...usernames: any[]) => Promise<any>;
260
+ getUsernames: (...jids: any[]) => Promise<any>;
261
+ fetchAccountReachoutTimelock: () => Promise<{
262
+ isActive: boolean;
263
+ timeEnforcementEnds: Date | undefined;
264
+ enforcementType: any;
265
+ }>;
266
+ fetchNewChatMessageCap: () => Promise<any>;
267
+ };
268
+ export function extractGroupMetadata(result: any): {
269
+ id: any;
270
+ notify: any;
271
+ addressingMode: any;
272
+ subject: any;
273
+ subjectOwner: any;
274
+ subjectOwnerPn: any;
275
+ subjectOwnerUsername: any;
276
+ subjectTime: number;
277
+ size: any;
278
+ creation: number;
279
+ owner: string | undefined;
280
+ ownerPn: string | undefined;
281
+ ownerUsername: any;
282
+ owner_country_code: any;
283
+ desc: any;
284
+ descId: any;
285
+ descOwner: string | undefined;
286
+ descOwnerPn: string | undefined;
287
+ descOwnerUsername: any;
288
+ descTime: number | undefined;
289
+ linkedParent: any;
290
+ restrict: boolean;
291
+ announce: boolean;
292
+ isCommunity: boolean;
293
+ isCommunityAnnounce: boolean;
294
+ joinApprovalMode: boolean;
295
+ memberAddMode: boolean;
296
+ participants: any;
297
+ ephemeralDuration: number | undefined;
298
+ };
@@ -0,0 +1,339 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
4
+ import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
5
+ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
6
+ import { makeChatsSocket } from './chats.js';
7
+ export const makeGroupsSocket = (config) => {
8
+ const sock = makeChatsSocket(config);
9
+ const { authState, ev, query, upsertMessage } = sock;
10
+ const groupQuery = async (jid, type, content) => query({
11
+ tag: 'iq',
12
+ attrs: {
13
+ type,
14
+ xmlns: 'w:g2',
15
+ to: jid
16
+ },
17
+ content
18
+ });
19
+ const groupMetadata = async (jid) => {
20
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
21
+ return extractGroupMetadata(result);
22
+ };
23
+ const groupFetchAllParticipating = async () => {
24
+ const result = await query({
25
+ tag: 'iq',
26
+ attrs: {
27
+ to: '@g.us',
28
+ xmlns: 'w:g2',
29
+ type: 'get'
30
+ },
31
+ content: [
32
+ {
33
+ tag: 'participating',
34
+ attrs: {},
35
+ content: [
36
+ { tag: 'participants', attrs: {} },
37
+ { tag: 'description', attrs: {} }
38
+ ]
39
+ }
40
+ ]
41
+ });
42
+ const data = {};
43
+ const groupsChild = getBinaryNodeChild(result, 'groups');
44
+ if (groupsChild) {
45
+ const groups = getBinaryNodeChildren(groupsChild, 'group');
46
+ for (const groupNode of groups) {
47
+ const meta = extractGroupMetadata({
48
+ tag: 'result',
49
+ attrs: {},
50
+ content: [groupNode]
51
+ });
52
+ data[meta.id] = meta;
53
+ }
54
+ }
55
+
56
+ sock.ev.emit('groups.update', Object.values(data));
57
+ return data;
58
+ };
59
+ sock.ws.on('CB:ib,,dirty', async (node) => {
60
+ const { attrs } = getBinaryNodeChild(node, 'dirty');
61
+ if (attrs.type !== 'groups') {
62
+ return;
63
+ }
64
+ await groupFetchAllParticipating();
65
+ await sock.cleanDirtyBits('groups');
66
+ });
67
+ return {
68
+ ...sock,
69
+ groupQuery,
70
+ groupMetadata,
71
+ groupCreate: async (subject, participants) => {
72
+ const key = generateMessageIDV2();
73
+ const result = await groupQuery('@g.us', 'set', [
74
+ {
75
+ tag: 'create',
76
+ attrs: {
77
+ subject,
78
+ key
79
+ },
80
+ content: participants.map(jid => ({
81
+ tag: 'participant',
82
+ attrs: { jid }
83
+ }))
84
+ }
85
+ ]);
86
+ return extractGroupMetadata(result);
87
+ },
88
+ groupLeave: async (id) => {
89
+ await groupQuery('@g.us', 'set', [
90
+ {
91
+ tag: 'leave',
92
+ attrs: {},
93
+ content: [{ tag: 'group', attrs: { id } }]
94
+ }
95
+ ]);
96
+ },
97
+ groupUpdateSubject: async (jid, subject) => {
98
+ await groupQuery(jid, 'set', [
99
+ {
100
+ tag: 'subject',
101
+ attrs: {},
102
+ content: Buffer.from(subject, 'utf-8')
103
+ }
104
+ ]);
105
+ },
106
+ groupRequestParticipantsList: async (jid) => {
107
+ const result = await groupQuery(jid, 'get', [
108
+ {
109
+ tag: 'membership_approval_requests',
110
+ attrs: {}
111
+ }
112
+ ]);
113
+ const node = getBinaryNodeChild(result, 'membership_approval_requests');
114
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request');
115
+ return participants.map(v => v.attrs);
116
+ },
117
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
118
+ const result = await groupQuery(jid, 'set', [
119
+ {
120
+ tag: 'membership_requests_action',
121
+ attrs: {},
122
+ content: [
123
+ {
124
+ tag: action,
125
+ attrs: {},
126
+ content: participants.map(jid => ({
127
+ tag: 'participant',
128
+ attrs: { jid }
129
+ }))
130
+ }
131
+ ]
132
+ }
133
+ ]);
134
+ const node = getBinaryNodeChild(result, 'membership_requests_action');
135
+ const nodeAction = getBinaryNodeChild(node, action);
136
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
137
+ return participantsAffected.map(p => {
138
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
139
+ });
140
+ },
141
+ groupParticipantsUpdate: async (jid, participants, action) => {
142
+ const result = await groupQuery(jid, 'set', [
143
+ {
144
+ tag: action,
145
+ attrs: {},
146
+ content: participants.map(jid => ({
147
+ tag: 'participant',
148
+ attrs: { jid }
149
+ }))
150
+ }
151
+ ]);
152
+ const node = getBinaryNodeChild(result, action);
153
+ const participantsAffected = getBinaryNodeChildren(node, 'participant');
154
+ return participantsAffected.map(p => {
155
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
156
+ });
157
+ },
158
+ groupUpdateDescription: async (jid, description) => {
159
+ const metadata = await groupMetadata(jid);
160
+ const prev = metadata.descId ?? null;
161
+ await groupQuery(jid, 'set', [
162
+ {
163
+ tag: 'description',
164
+ attrs: {
165
+ ...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
166
+ ...(prev ? { prev } : {})
167
+ },
168
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
169
+ }
170
+ ]);
171
+ },
172
+ groupInviteCode: async (jid) => {
173
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
174
+ const inviteNode = getBinaryNodeChild(result, 'invite');
175
+ return inviteNode?.attrs.code;
176
+ },
177
+ groupRevokeInvite: async (jid) => {
178
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
179
+ const inviteNode = getBinaryNodeChild(result, 'invite');
180
+ return inviteNode?.attrs.code;
181
+ },
182
+ groupAcceptInvite: async (code) => {
183
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
184
+ const result = getBinaryNodeChild(results, 'group');
185
+ return result?.attrs.jid;
186
+ },
187
+
188
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
189
+ const result = await groupQuery(groupJid, 'set', [
190
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
191
+ ]);
192
+ return !!result;
193
+ },
194
+
195
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
196
+ key = typeof key === 'string' ? { remoteJid: key } : key;
197
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
198
+ {
199
+ tag: 'accept',
200
+ attrs: {
201
+ code: inviteMessage.inviteCode,
202
+ expiration: inviteMessage.inviteExpiration.toString(),
203
+ admin: key.remoteJid
204
+ }
205
+ }
206
+ ]);
207
+
208
+ if (key.id) {
209
+
210
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
211
+ inviteMessage.inviteExpiration = 0;
212
+ inviteMessage.inviteCode = '';
213
+ ev.emit('messages.update', [
214
+ {
215
+ key,
216
+ update: {
217
+ message: {
218
+ groupInviteMessage: inviteMessage
219
+ }
220
+ }
221
+ }
222
+ ]);
223
+ }
224
+
225
+ await upsertMessage({
226
+ key: {
227
+ remoteJid: inviteMessage.groupJid,
228
+ id: generateMessageIDV2(sock.user?.id),
229
+ fromMe: false,
230
+ participant: key.remoteJid
231
+ },
232
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
233
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
234
+ participant: key.remoteJid,
235
+ messageTimestamp: unixTimestampSeconds()
236
+ }, 'notify');
237
+ return results.attrs.from;
238
+ }),
239
+ groupGetInviteInfo: async (code) => {
240
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
241
+ return extractGroupMetadata(results);
242
+ },
243
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
244
+ const content = ephemeralExpiration
245
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
246
+ : { tag: 'not_ephemeral', attrs: {} };
247
+ await groupQuery(jid, 'set', [content]);
248
+ },
249
+ groupSettingUpdate: async (jid, setting) => {
250
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
251
+ },
252
+ groupMemberAddMode: async (jid, mode) => {
253
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
254
+ },
255
+ groupJoinApprovalMode: async (jid, mode) => {
256
+ await groupQuery(jid, 'set', [
257
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
258
+ ]);
259
+ },
260
+ groupFetchAllParticipating
261
+ };
262
+ };
263
+ export const extractGroupMetadata = (result) => {
264
+ const group = getBinaryNodeChild(result, 'group');
265
+ if (!group) {
266
+
267
+ const errorNode = getBinaryNodeChild(result, 'error');
268
+ if (errorNode) {
269
+ const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
270
+ const text = errorNode.attrs.text || 'group metadata query failed';
271
+ throw new Boom(text, { statusCode: code, data: errorNode });
272
+ }
273
+ throw new Boom('Invalid group metadata response: missing <group> node', { data: result });
274
+ }
275
+ if (!group.attrs.id) {
276
+ throw new Boom('Invalid group metadata response: missing group id', { data: group });
277
+ }
278
+ const descChild = getBinaryNodeChild(group, 'description');
279
+ let desc;
280
+ let descId;
281
+ let descOwner;
282
+ let descOwnerPn;
283
+ let descOwnerUsername;
284
+ let descTime;
285
+ if (descChild) {
286
+ desc = getBinaryNodeChildString(descChild, 'body');
287
+ descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
288
+ descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
289
+ descOwnerUsername = descChild.attrs.participant_username || undefined;
290
+ descTime = +descChild.attrs.t;
291
+ descId = descChild.attrs.id;
292
+ }
293
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
294
+ const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
295
+ const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
296
+ const metadata = {
297
+ id: groupId,
298
+ notify: group.attrs.notify,
299
+ addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
300
+ subject: group.attrs.subject,
301
+ subjectOwner: group.attrs.s_o ? jidNormalizedUser(group.attrs.s_o) : undefined,
302
+ subjectOwnerPn: group.attrs.s_o_pn ? jidNormalizedUser(group.attrs.s_o_pn) : undefined,
303
+ subjectOwnerUsername: group.attrs.s_o_username,
304
+ subjectTime: +group.attrs.s_t,
305
+ size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
306
+ creation: +group.attrs.creation,
307
+ owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
308
+ ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
309
+ ownerUsername: group.attrs.creator_username || undefined,
310
+ owner_country_code: group.attrs.creator_country_code,
311
+ desc,
312
+ descId,
313
+ descOwner,
314
+ descOwnerPn,
315
+ descOwnerUsername,
316
+ descTime,
317
+ linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
318
+ restrict: !!getBinaryNodeChild(group, 'locked'),
319
+ announce: !!getBinaryNodeChild(group, 'announcement'),
320
+ isCommunity: !!getBinaryNodeChild(group, 'parent'),
321
+ isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
322
+ joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
323
+ memberAddMode,
324
+ participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
325
+ const jid = attrs.jid;
326
+ const lid = isLidUser(jid) ? jid : isLidUser(attrs.lid) ? attrs.lid : undefined;
327
+ const phoneNumber = isPnUser(jid) ? jid : isPnUser(attrs.phone_number) ? attrs.phone_number : undefined;
328
+ return {
329
+ id: jid,
330
+ phoneNumber,
331
+ lid,
332
+ username: attrs.participant_username || attrs.username || undefined,
333
+ admin: (attrs.type || null)
334
+ };
335
+ }),
336
+ ephemeralDuration: eph ? +eph : undefined
337
+ };
338
+ return metadata;
339
+ };