ruby-baileys 0.0.0-stage → 1.5.17

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