@zelynskybail/baileys 0.0.0-stage → 2.6.28

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 (226) hide show
  1. package/BUILD_STATUS.md +21 -0
  2. package/CHANGELOG.md +17 -0
  3. package/LICENSE +21 -0
  4. package/NOTICE.md +9 -0
  5. package/README.md +165 -2
  6. package/THANKS.md +7 -0
  7. package/THIRD_PARTY_NOTICES.md +8 -0
  8. package/WAProto/GenerateStatics.sh +3 -0
  9. package/WAProto/WAProto.proto +6035 -0
  10. package/WAProto/fix-imports.js +81 -0
  11. package/WAProto/index.d.ts +2 -0
  12. package/WAProto/index.js +132326 -0
  13. package/lib/Builders/advanced.d.ts +14 -0
  14. package/lib/Builders/advanced.js +142 -0
  15. package/lib/Builders/group-status.d.ts +9 -0
  16. package/lib/Builders/group-status.js +19 -0
  17. package/lib/Builders/index.d.ts +62 -0
  18. package/lib/Builders/index.js +242 -0
  19. package/lib/Defaults/index.d.ts +74 -0
  20. package/lib/Defaults/index.js +136 -0
  21. package/lib/Modded/MessageBuilder.js +3222 -0
  22. package/lib/Modded/message_builder.d.ts +43 -0
  23. package/lib/Modded/message_builder.js +2 -0
  24. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  25. package/lib/Signal/Group/ciphertext-message.js +11 -0
  26. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  27. package/lib/Signal/Group/group-session-builder.js +29 -0
  28. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  29. package/lib/Signal/Group/group_cipher.js +81 -0
  30. package/lib/Signal/Group/index.d.ts +12 -0
  31. package/lib/Signal/Group/index.js +11 -0
  32. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  33. package/lib/Signal/Group/keyhelper.js +17 -0
  34. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  35. package/lib/Signal/Group/sender-chain-key.js +25 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  38. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  39. package/lib/Signal/Group/sender-key-message.js +65 -0
  40. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  41. package/lib/Signal/Group/sender-key-name.js +47 -0
  42. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  43. package/lib/Signal/Group/sender-key-record.js +40 -0
  44. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  45. package/lib/Signal/Group/sender-key-state.js +83 -0
  46. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  47. package/lib/Signal/Group/sender-message-key.js +25 -0
  48. package/lib/Signal/libsignal.d.ts +5 -0
  49. package/lib/Signal/libsignal.js +402 -0
  50. package/lib/Signal/lid-mapping.d.ts +19 -0
  51. package/lib/Signal/lid-mapping.js +270 -0
  52. package/lib/Socket/Client/index.d.ts +3 -0
  53. package/lib/Socket/Client/index.js +2 -0
  54. package/lib/Socket/Client/types.d.ts +16 -0
  55. package/lib/Socket/Client/types.js +10 -0
  56. package/lib/Socket/Client/websocket.d.ts +13 -0
  57. package/lib/Socket/Client/websocket.js +53 -0
  58. package/lib/Socket/business.d.ts +536 -0
  59. package/lib/Socket/business.js +421 -0
  60. package/lib/Socket/chats.d.ts +111 -0
  61. package/lib/Socket/chats.js +990 -0
  62. package/lib/Socket/communities.d.ts +645 -0
  63. package/lib/Socket/communities.js +430 -0
  64. package/lib/Socket/dugong.d.ts +130 -0
  65. package/lib/Socket/dugong.js +767 -0
  66. package/lib/Socket/groups.d.ts +150 -0
  67. package/lib/Socket/groups.js +326 -0
  68. package/lib/Socket/index.d.ts +657 -0
  69. package/lib/Socket/index.js +26 -0
  70. package/lib/Socket/messages-recv.d.ts +238 -0
  71. package/lib/Socket/messages-recv.js +1307 -0
  72. package/lib/Socket/messages-send.d.ts +579 -0
  73. package/lib/Socket/messages-send.js +1594 -0
  74. package/lib/Socket/mex.d.ts +3 -0
  75. package/lib/Socket/mex.js +47 -0
  76. package/lib/Socket/newsletter.d.ts +177 -0
  77. package/lib/Socket/newsletter.js +314 -0
  78. package/lib/Socket/socket.d.ts +55 -0
  79. package/lib/Socket/socket.js +935 -0
  80. package/lib/Types/Auth.d.ts +116 -0
  81. package/lib/Types/Auth.js +1 -0
  82. package/lib/Types/Bussines.d.ts +37 -0
  83. package/lib/Types/Bussines.js +1 -0
  84. package/lib/Types/Call.d.ts +15 -0
  85. package/lib/Types/Call.js +1 -0
  86. package/lib/Types/Chat.d.ts +123 -0
  87. package/lib/Types/Chat.js +7 -0
  88. package/lib/Types/Contact.d.ts +24 -0
  89. package/lib/Types/Contact.js +1 -0
  90. package/lib/Types/Events.d.ts +237 -0
  91. package/lib/Types/Events.js +1 -0
  92. package/lib/Types/GroupMetadata.d.ts +68 -0
  93. package/lib/Types/GroupMetadata.js +1 -0
  94. package/lib/Types/Label.d.ts +47 -0
  95. package/lib/Types/Label.js +24 -0
  96. package/lib/Types/LabelAssociation.d.ts +30 -0
  97. package/lib/Types/LabelAssociation.js +6 -0
  98. package/lib/Types/Message.d.ts +422 -0
  99. package/lib/Types/Message.js +10 -0
  100. package/lib/Types/Newsletter.d.ts +135 -0
  101. package/lib/Types/Newsletter.js +30 -0
  102. package/lib/Types/Product.d.ts +79 -0
  103. package/lib/Types/Product.js +1 -0
  104. package/lib/Types/Signal.d.ts +76 -0
  105. package/lib/Types/Signal.js +1 -0
  106. package/lib/Types/Socket.d.ts +154 -0
  107. package/lib/Types/Socket.js +2 -0
  108. package/lib/Types/State.d.ts +39 -0
  109. package/lib/Types/State.js +12 -0
  110. package/lib/Types/USync.d.ts +26 -0
  111. package/lib/Types/USync.js +1 -0
  112. package/lib/Types/index.d.ts +66 -0
  113. package/lib/Types/index.js +32 -0
  114. package/lib/Utils/auth-utils.d.ts +19 -0
  115. package/lib/Utils/auth-utils.js +289 -0
  116. package/lib/Utils/browser-utils.d.ts +4 -0
  117. package/lib/Utils/browser-utils.js +27 -0
  118. package/lib/Utils/business.d.ts +23 -0
  119. package/lib/Utils/business.js +230 -0
  120. package/lib/Utils/chat-utils.d.ts +70 -0
  121. package/lib/Utils/chat-utils.js +811 -0
  122. package/lib/Utils/crypto.d.ts +37 -0
  123. package/lib/Utils/crypto.js +117 -0
  124. package/lib/Utils/decode-wa-message.d.ts +48 -0
  125. package/lib/Utils/decode-wa-message.js +282 -0
  126. package/lib/Utils/event-buffer.d.ts +34 -0
  127. package/lib/Utils/event-buffer.js +573 -0
  128. package/lib/Utils/generics.d.ts +91 -0
  129. package/lib/Utils/generics.js +383 -0
  130. package/lib/Utils/history.d.ts +22 -0
  131. package/lib/Utils/history.js +130 -0
  132. package/lib/Utils/identity-change-handler.d.ts +37 -0
  133. package/lib/Utils/identity-change-handler.js +48 -0
  134. package/lib/Utils/index.d.ts +24 -0
  135. package/lib/Utils/index.js +24 -0
  136. package/lib/Utils/link-preview.d.ts +21 -0
  137. package/lib/Utils/link-preview.js +84 -0
  138. package/lib/Utils/logger.d.ts +13 -0
  139. package/lib/Utils/logger.js +2 -0
  140. package/lib/Utils/lt-hash.d.ts +8 -0
  141. package/lib/Utils/lt-hash.js +7 -0
  142. package/lib/Utils/make-mutex.d.ts +9 -0
  143. package/lib/Utils/make-mutex.js +32 -0
  144. package/lib/Utils/message-retry-manager.d.ts +110 -0
  145. package/lib/Utils/message-retry-manager.js +224 -0
  146. package/lib/Utils/message-tools.d.ts +31 -0
  147. package/lib/Utils/message-tools.js +182 -0
  148. package/lib/Utils/messages-media.d.ts +130 -0
  149. package/lib/Utils/messages-media.js +781 -0
  150. package/lib/Utils/messages.d.ts +91 -0
  151. package/lib/Utils/messages.js +1239 -0
  152. package/lib/Utils/noise-handler.d.ts +20 -0
  153. package/lib/Utils/noise-handler.js +200 -0
  154. package/lib/Utils/offline-node-processor.d.ts +17 -0
  155. package/lib/Utils/offline-node-processor.js +68 -0
  156. package/lib/Utils/performance.d.ts +3 -0
  157. package/lib/Utils/performance.js +35 -0
  158. package/lib/Utils/pre-key-manager.d.ts +28 -0
  159. package/lib/Utils/pre-key-manager.js +105 -0
  160. package/lib/Utils/process-message.d.ts +60 -0
  161. package/lib/Utils/process-message.js +527 -0
  162. package/lib/Utils/reporting-utils.d.ts +11 -0
  163. package/lib/Utils/reporting-utils.js +257 -0
  164. package/lib/Utils/rich-messages.d.ts +277 -0
  165. package/lib/Utils/rich-messages.js +1143 -0
  166. package/lib/Utils/signal.d.ts +34 -0
  167. package/lib/Utils/signal.js +158 -0
  168. package/lib/Utils/stanza-ack.d.ts +11 -0
  169. package/lib/Utils/stanza-ack.js +37 -0
  170. package/lib/Utils/sticker-pack.d.ts +10 -0
  171. package/lib/Utils/sticker-pack.js +111 -0
  172. package/lib/Utils/sync-action-utils.d.ts +19 -0
  173. package/lib/Utils/sync-action-utils.js +47 -0
  174. package/lib/Utils/tc-token-utils.d.ts +12 -0
  175. package/lib/Utils/tc-token-utils.js +17 -0
  176. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  177. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  178. package/lib/Utils/validate-connection.d.ts +11 -0
  179. package/lib/Utils/validate-connection.js +199 -0
  180. package/lib/VoIP/index.d.ts +18 -0
  181. package/lib/VoIP/index.js +81 -0
  182. package/lib/WABinary/constants.d.ts +28 -0
  183. package/lib/WABinary/constants.js +1300 -0
  184. package/lib/WABinary/decode.d.ts +7 -0
  185. package/lib/WABinary/decode.js +261 -0
  186. package/lib/WABinary/encode.d.ts +3 -0
  187. package/lib/WABinary/encode.js +219 -0
  188. package/lib/WABinary/generic-utils.d.ts +17 -0
  189. package/lib/WABinary/generic-utils.js +190 -0
  190. package/lib/WABinary/index.d.ts +6 -0
  191. package/lib/WABinary/index.js +5 -0
  192. package/lib/WABinary/jid-utils.d.ts +48 -0
  193. package/lib/WABinary/jid-utils.js +95 -0
  194. package/lib/WABinary/types.d.ts +19 -0
  195. package/lib/WABinary/types.js +1 -0
  196. package/lib/WAM/BinaryInfo.d.ts +9 -0
  197. package/lib/WAM/BinaryInfo.js +9 -0
  198. package/lib/WAM/constants.d.ts +40 -0
  199. package/lib/WAM/constants.js +22852 -0
  200. package/lib/WAM/encode.d.ts +3 -0
  201. package/lib/WAM/encode.js +149 -0
  202. package/lib/WAM/index.d.ts +4 -0
  203. package/lib/WAM/index.js +3 -0
  204. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  205. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  206. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  207. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  208. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  209. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  210. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  211. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  212. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  213. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  214. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  215. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  216. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  217. package/lib/WAUSync/Protocols/index.js +4 -0
  218. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  219. package/lib/WAUSync/USyncQuery.js +93 -0
  220. package/lib/WAUSync/USyncUser.d.ts +13 -0
  221. package/lib/WAUSync/USyncUser.js +22 -0
  222. package/lib/WAUSync/index.d.ts +4 -0
  223. package/lib/WAUSync/index.js +3 -0
  224. package/lib/index.d.ts +14 -0
  225. package/lib/index.js +14 -0
  226. package/package.json +128 -4
@@ -0,0 +1,14 @@
1
+ import type { WASocket, WAMessage } from '../Types/index.js';
2
+ export declare class ButtonV3 {
3
+ constructor(sock: WASocket);
4
+ setTitle(value: string): this; setBody(value: string): this; setText(value: string): this; setFooter(value: string): this;
5
+ setContextInfo(value: object): this; addPayload(value: object): this;
6
+ setImage(input: string | Buffer, options?: object): this; setVideo(input: string | Buffer, options?: object): this; setDocument(input: string | Buffer, options?: object): this;
7
+ addReply(displayText: string, id?: string): this; addUrl(displayText: string, url: string): this; addCall(displayText: string, phoneNumber: string): this; addRawButton(button: object): this;
8
+ loadFrom(message: WAMessage | object): this; build(jid: string, options?: object): Promise<WAMessage>; send(jid: string, options?: object): Promise<WAMessage>;
9
+ }
10
+ export declare class A2UIBuilder {
11
+ static components: ReadonlySet<string>;
12
+ setRoot(node: object): this; setComponent(component: string, props?: object, children?: object[]): this;
13
+ build(): object; toButtonParams(): { bloks_widget: object }; toJSON(): object;
14
+ }
@@ -0,0 +1,142 @@
1
+ import { generateWAMessageFromContent, prepareWAMessageMedia } from '../Utils/messages.js';
2
+ import { generateMessageIDV2 } from '../Utils/generics.js';
3
+
4
+ const assertSocket = (sock) => {
5
+ if (!sock || typeof sock.relayMessage !== 'function') throw new TypeError('A Baileys socket with relayMessage() is required.');
6
+ };
7
+
8
+ const asMedia = (kind, input) => {
9
+ if (!input) throw new TypeError(`${kind} content is required.`);
10
+ return Buffer.isBuffer(input) ? { [kind]: input } : { [kind]: { url: input } };
11
+ };
12
+
13
+ /** Hydrated-template (Button V3) builder. Maximum three WhatsApp template actions. */
14
+ export class ButtonV3 {
15
+ constructor(sock) {
16
+ assertSocket(sock);
17
+ this.sock = sock;
18
+ this.title = '';
19
+ this.body = '';
20
+ this.footer = '';
21
+ this.buttons = [];
22
+ this.media = null;
23
+ this.contextInfo = {};
24
+ this.extra = {};
25
+ }
26
+ setTitle(value) { this.title = String(value ?? ''); return this; }
27
+ setBody(value) { this.body = String(value ?? ''); return this; }
28
+ setText(value) { return this.setBody(value); }
29
+ setFooter(value) { this.footer = String(value ?? ''); return this; }
30
+ setContextInfo(value) {
31
+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError('contextInfo must be an object.');
32
+ this.contextInfo = { ...value }; return this;
33
+ }
34
+ addPayload(value) {
35
+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError('Payload must be an object.');
36
+ Object.assign(this.extra, value); return this;
37
+ }
38
+ setImage(input, options = {}) { this.media = { type: 'image', input, options }; return this; }
39
+ setVideo(input, options = {}) { this.media = { type: 'video', input, options }; return this; }
40
+ setDocument(input, options = {}) { this.media = { type: 'document', input, options }; return this; }
41
+ addReply(displayText, id = displayText) {
42
+ this.#push({ quickReplyButton: { displayText: String(displayText), id: String(id) } }); return this;
43
+ }
44
+ addUrl(displayText, url) {
45
+ const parsed = new URL(String(url));
46
+ if (!['http:', 'https:'].includes(parsed.protocol)) throw new TypeError('URL buttons require HTTP(S).');
47
+ this.#push({ urlButton: { displayText: String(displayText), url: parsed.href } }); return this;
48
+ }
49
+ addCall(displayText, phoneNumber) {
50
+ const number = String(phoneNumber).replace(/[^+\d]/g, '');
51
+ if (!/^\+?\d{6,20}$/.test(number)) throw new TypeError('A valid international phone number is required.');
52
+ this.#push({ callButton: { displayText: String(displayText), phoneNumber: number } }); return this;
53
+ }
54
+ addRawButton(button) {
55
+ if (!button || typeof button !== 'object' || Array.isArray(button)) throw new TypeError('Template button must be an object.');
56
+ this.#push(structuredClone(button)); return this;
57
+ }
58
+ #push(button) {
59
+ if (this.buttons.length >= 3) throw new RangeError('WhatsApp hydrated templates support at most three buttons.');
60
+ this.buttons.push({ index: this.buttons.length, ...button });
61
+ }
62
+ loadFrom(input) {
63
+ const message = input?.message ?? input;
64
+ const template = message?.templateMessage?.hydratedTemplate;
65
+ if (!template) throw new TypeError('templateMessage.hydratedTemplate was not found.');
66
+ this.title = template.hydratedTitleText ?? '';
67
+ this.body = template.hydratedContentText ?? '';
68
+ this.footer = template.hydratedFooterText ?? '';
69
+ this.buttons = Array.isArray(template.hydratedButtons) ? structuredClone(template.hydratedButtons) : [];
70
+ this.contextInfo = message?.templateMessage?.contextInfo ?? {};
71
+ this.media = null;
72
+ if (template.imageMessage) this.media = { type: 'imageMessage', prepared: template.imageMessage };
73
+ else if (template.videoMessage) this.media = { type: 'videoMessage', prepared: template.videoMessage };
74
+ else if (template.documentMessage) this.media = { type: 'documentMessage', prepared: template.documentMessage };
75
+ return this;
76
+ }
77
+ async build(jid, options = {}) {
78
+ if (!String(this.body).trim()) throw new Error('Template body is required.');
79
+ const hydratedTemplate = {
80
+ hydratedContentText: this.body,
81
+ ...(this.title ? { hydratedTitleText: this.title } : {}),
82
+ ...(this.footer ? { hydratedFooterText: this.footer } : {}),
83
+ hydratedButtons: this.buttons.map((button, index) => ({ index, ...button })),
84
+ };
85
+ if (this.media?.prepared) {
86
+ hydratedTemplate[this.media.type] = this.media.prepared;
87
+ } else if (this.media) {
88
+ const prepared = await prepareWAMessageMedia(asMedia(this.media.type, this.media.input), {
89
+ upload: this.sock.waUploadToServer,
90
+ ...this.media.options,
91
+ });
92
+ Object.assign(hydratedTemplate, prepared);
93
+ }
94
+ return generateWAMessageFromContent(jid, {
95
+ ...this.extra,
96
+ templateMessage: { hydratedTemplate, contextInfo: this.contextInfo },
97
+ }, { messageId: options.messageId ?? generateMessageIDV2(), ...options });
98
+ }
99
+ async send(jid, options = {}) {
100
+ const { additionalNodes = [], ...messageOptions } = options;
101
+ const message = await this.build(jid, messageOptions);
102
+ await this.sock.relayMessage(message.key.remoteJid, message.message, {
103
+ messageId: message.key.id,
104
+ additionalNodes,
105
+ ...messageOptions,
106
+ });
107
+ return message;
108
+ }
109
+ }
110
+
111
+ /** Experimental A2UI/Bloks tree validator and payload builder. Rendering is WhatsApp-client dependent. */
112
+ export class A2UIBuilder {
113
+ static components = Object.freeze(new Set([
114
+ 'Column', 'Row', 'Text', 'Icon', 'Divider', 'Image', 'Video', 'List', 'TextField',
115
+ 'DateTimeInput', 'Slider', 'CheckBox', 'ChoicePicker', 'Button', 'Modal', 'Tabs', 'Card', 'AudioPlayer'
116
+ ]));
117
+ constructor() { this.root = null; }
118
+ setRoot(node) { this.#validate(node); this.root = structuredClone(node); return this; }
119
+ setComponent(component, props = {}, children = []) {
120
+ return this.setRoot({ component, ...props, ...(children.length ? { children } : {}) });
121
+ }
122
+ #validate(node, depth = 0, refs = new Set()) {
123
+ if (depth > 32) throw new RangeError('A2UI tree exceeds the maximum depth of 32.');
124
+ if (!node || typeof node !== 'object' || Array.isArray(node)) throw new TypeError('A2UI nodes must be objects.');
125
+ if (!A2UIBuilder.components.has(node.component)) throw new TypeError(`Unsupported A2UI component: ${String(node.component)}`);
126
+ if (node.ref) {
127
+ if (refs.has(node.ref)) throw new Error(`Duplicate A2UI ref: ${node.ref}`);
128
+ refs.add(node.ref);
129
+ }
130
+ if (node.children !== undefined) {
131
+ if (!Array.isArray(node.children)) throw new TypeError('A2UI children must be an array.');
132
+ for (const child of node.children) this.#validate(child, depth + 1, refs);
133
+ }
134
+ }
135
+ build() {
136
+ if (!this.root) throw new Error('A2UI root component is required.');
137
+ return structuredClone(this.root);
138
+ }
139
+ toButtonParams() { return { bloks_widget: this.build() }; }
140
+ toJSON() { return this.build(); }
141
+ }
142
+
@@ -0,0 +1,9 @@
1
+ import type { WASocket, WAMessage } from '../Types/index.js';
2
+ export declare class GroupStatusHelper {
3
+ static send(sock: WASocket, groupJid: string, content: object, options?: object): Promise<WAMessage>;
4
+ static text(sock: WASocket, groupJid: string, text: string, options?: object): Promise<WAMessage>;
5
+ static image(sock: WASocket, groupJid: string, image: any, caption?: string, options?: object): Promise<WAMessage>;
6
+ static video(sock: WASocket, groupJid: string, video: any, caption?: string, options?: object): Promise<WAMessage>;
7
+ static audio(sock: WASocket, groupJid: string, audio: any, options?: object): Promise<WAMessage>;
8
+ static sticker(sock: WASocket, groupJid: string, sticker: any, options?: object): Promise<WAMessage>;
9
+ }
@@ -0,0 +1,19 @@
1
+ const assertSocket = (sock) => {
2
+ if (!sock || typeof sock.sendMessage !== 'function') throw new TypeError('A connected Baileys socket is required.');
3
+ };
4
+
5
+ /** Group Story helper backed by the underlying socket's swgc transport. */
6
+ export class GroupStatusHelper {
7
+ static async send(sock, groupJid, content, options = {}) {
8
+ assertSocket(sock);
9
+ if (typeof groupJid !== 'string' || !groupJid.endsWith('@g.us')) throw new TypeError('A group JID is required.');
10
+ if (!content || typeof content !== 'object' || Array.isArray(content)) throw new TypeError('Group status content must be an object.');
11
+ if (typeof sock.swgc !== 'function') throw new Error('Group Status is not supported by this socket.');
12
+ return sock.swgc(groupJid, content, options);
13
+ }
14
+ static text(sock, groupJid, text, options = {}) { return this.send(sock, groupJid, { text: String(text ?? ''), ...options }); }
15
+ static image(sock, groupJid, image, caption = '', options = {}) { return this.send(sock, groupJid, { image, ...(caption ? { caption } : {}), ...options }); }
16
+ static video(sock, groupJid, video, caption = '', options = {}) { return this.send(sock, groupJid, { video, ...(caption ? { caption } : {}), ...options }); }
17
+ static audio(sock, groupJid, audio, options = {}) { return this.send(sock, groupJid, { audio, ptt: true, ...options }); }
18
+ static sticker(sock, groupJid, sticker, options = {}) { return this.send(sock, groupJid, { sticker, ...options }); }
19
+ }
@@ -0,0 +1,62 @@
1
+ import type { WAMessage } from '../Types/index.js';
2
+ import type { Button, ButtonV2, Carousel, AIRich, ORich, Toolkit } from '../Modded/message_builder.js';
3
+ export { Button, ButtonV2, Carousel, AIRich, ORich, Toolkit, makeStickerPack } from '../Modded/message_builder.js';
4
+ export declare class NativeFlow extends Button {
5
+ setText(text: string): this;
6
+ addQuickReply(label: string, id: string, options?: Record<string, unknown>): this;
7
+ addUrlButton(label: string, url: string, options?: Record<string, unknown>): this;
8
+ addCopyButton(label: string, code: string, options?: Record<string, unknown>): this;
9
+ addCallButton(label: string, phone: string, options?: Record<string, unknown>): this;
10
+ addRawButton(name: string, params: object | string): this;
11
+ addSingleSelect(title: string, sections?: Array<{ title?: string; highlight_label?: string; rows?: Array<{ header?: string; title: string; description?: string; id: string }> }>): this;
12
+ }
13
+ export declare class CardBuilder extends NativeFlow { button(label: string, id: string): this; }
14
+ export declare class PollBuilder {
15
+ constructor(sock: any);
16
+ setName(name: string): this; setQuestion(name: string): this; addOption(value: string): this;
17
+ setOptions(values: string[]): this; setSelectable(count: number): this; setMultiSelect(enabled?: boolean): this;
18
+ setAnnouncementGroup(enabled?: boolean): this; build(): { poll: { name: string; values: string[]; selectableCount: number; toAnnouncementGroup: boolean } };
19
+ send(jid: string, options?: object): Promise<WAMessage>;
20
+ }
21
+ export declare class AlbumBuilder {
22
+ constructor(sock: any); add(item: object): this; addImage(image: any, caption?: string, options?: object): this;
23
+ addVideo(video: any, caption?: string, options?: object): this; setContextInfo(info: object): this; build(): { albumMessage: object[] };
24
+ send(jid: string, options?: object): Promise<WAMessage>;
25
+ }
26
+ export declare class ContactBuilder {
27
+ constructor(sock: any); add(contact: { name?: string; displayName?: string; phone?: string; phones?: Array<string | { number: string; type?: string }>; email?: string; company?: string }): this;
28
+ setContacts(contacts: object[]): this; build(): { contacts: { displayName: string; contacts: Array<{ displayName: string; vcard: string }> } };
29
+ send(jid: string, options?: object): Promise<WAMessage>;
30
+ }
31
+ export declare class VCardBuilder extends ContactBuilder {}
32
+ export declare class LocationBuilder {
33
+ constructor(sock: any); setCoordinates(latitude: number, longitude: number): this; setName(name: string): this; setAddress(address: string): this;
34
+ setUrl(url: string): this; setComment(comment: string): this; build(): { location: Record<string, unknown> }; send(jid: string, options?: object): Promise<WAMessage>;
35
+ }
36
+ export declare class LinkPreviewBuilder {
37
+ constructor(sock: any); setText(text: string): this; setUrl(url: string): this; setTitle(title: string): this;
38
+ setDescription(description: string): this; setThumbnail(buffer: Buffer): this; build(): object; send(jid: string, options?: object): Promise<WAMessage>;
39
+ }
40
+ export declare const createTextStatus: (options: { text: string; backgroundColor?: string; font?: number; mentions?: string[] }) => object;
41
+ export declare const createImageStatus: (image: any, caption?: string, options?: object) => object;
42
+ export declare const createVideoStatus: (video: any, caption?: string, options?: object) => object;
43
+ export declare const createAudioStatus: (audio: any, options?: object) => object;
44
+ export declare class StatusHelper {
45
+ static send(sock: any, content: object, recipients?: string[], options?: object): Promise<WAMessage>;
46
+ static text(sock: any, options: object, recipients?: string[]): Promise<WAMessage>;
47
+ static image(sock: any, image: any, caption?: string, recipients?: string[], options?: object): Promise<WAMessage>;
48
+ static video(sock: any, video: any, caption?: string, recipients?: string[], options?: object): Promise<WAMessage>;
49
+ static audio(sock: any, audio: any, recipients?: string[], options?: object): Promise<WAMessage>;
50
+ }
51
+ export { GroupStatusHelper } from './group-status.js';
52
+ export declare class ZelynskyBuilders {
53
+ constructor(sock: any); button(): Button; buttonV2(): ButtonV2; nativeFlow(): NativeFlow; carousel(): Carousel; airich(): AIRich;
54
+ poll(): PollBuilder; album(): AlbumBuilder; contact(): ContactBuilder; vcard(): VCardBuilder; location(): LocationBuilder; linkPreview(): LinkPreviewBuilder;
55
+ }
56
+ export declare const attachBuilders: (sock: any) => any;
57
+
58
+ export { ButtonV3, A2UIBuilder } from './advanced.js';
59
+ export declare class MessageBuilder extends ZelynskyBuilders {
60
+ buttonV3(): import('./advanced.js').ButtonV3;
61
+ a2ui(): import('./advanced.js').A2UIBuilder;
62
+ }
@@ -0,0 +1,242 @@
1
+ import { ButtonV3, A2UIBuilder } from './advanced.js';
2
+ import {
3
+ Button,
4
+ ButtonV2,
5
+ Carousel,
6
+ AIRich,
7
+ ORich,
8
+ Toolkit,
9
+ } from '../Modded/message_builder.js';
10
+ import { makeStickerPack } from '../Utils/sticker-pack.js';
11
+ import { GroupStatusHelper } from './group-status.js';
12
+
13
+ const assertSocket = (sock) => {
14
+ if (!sock || typeof sock.sendMessage !== 'function') {
15
+ throw new TypeError('A connected Baileys socket is required.');
16
+ }
17
+ };
18
+
19
+ const escapeVCard = (value) => String(value ?? '')
20
+ .replace(/\\/g, '\\\\')
21
+ .replace(/\n/g, '\\n')
22
+ .replace(/,/g, '\\,')
23
+ .replace(/;/g, '\\;');
24
+
25
+ export class NativeFlow extends Button {
26
+ setText(text) { return this.setBody(text); }
27
+ addQuickReply(label, id, options = {}) { return this.addReply(label, id, options); }
28
+ addUrlButton(label, url, options = {}) {
29
+ return this.addUrl(label, url, Boolean(options.webviewInteraction), options);
30
+ }
31
+ addCopyButton(label, code, options = {}) { return this.addCopy(label, code, options); }
32
+ addCallButton(label, phone, options = {}) { return this.addCall(label, phone, options); }
33
+ addRawButton(name, params) { return this.addButton(name, params); }
34
+ addSingleSelect(title, sections = []) {
35
+ this.addSelection(title);
36
+ for (const section of sections) {
37
+ this.makeSection(section.title ?? '', section.highlight_label ?? '');
38
+ for (const item of section.rows ?? []) {
39
+ this.makeRow(item.header ?? '', item.title ?? '', item.description ?? '', item.id ?? '');
40
+ }
41
+ }
42
+ return this;
43
+ }
44
+ }
45
+
46
+ export class CardBuilder extends NativeFlow {
47
+ button(label, id) { return this.addQuickReply(label, id); }
48
+ }
49
+
50
+ export class PollBuilder {
51
+ constructor(sock) {
52
+ assertSocket(sock);
53
+ this.sock = sock;
54
+ this.name = '';
55
+ this.values = [];
56
+ this.selectableCount = 1;
57
+ this.toAnnouncementGroup = false;
58
+ }
59
+ setName(name) { this.name = String(name ?? '').trim(); return this; }
60
+ setQuestion(name) { return this.setName(name); }
61
+ addOption(value) { this.values.push(String(value)); return this; }
62
+ setOptions(values) {
63
+ if (!Array.isArray(values)) throw new TypeError('Poll options must be an array.');
64
+ this.values = values.map(String);
65
+ return this;
66
+ }
67
+ setSelectable(count) { this.selectableCount = Number(count); return this; }
68
+ setMultiSelect(enabled = true) { this.selectableCount = enabled ? Math.max(2, this.values.length) : 1; return this; }
69
+ setAnnouncementGroup(enabled = true) { this.toAnnouncementGroup = Boolean(enabled); return this; }
70
+ build() {
71
+ const values = [...new Set(this.values.map((value) => value.trim()).filter(Boolean))];
72
+ if (!this.name) throw new Error('Poll name is required.');
73
+ if (values.length < 2) throw new Error('A poll needs at least two unique options.');
74
+ if (!Number.isInteger(this.selectableCount) || this.selectableCount < 1 || this.selectableCount > values.length) {
75
+ throw new RangeError('selectableCount must be between 1 and the number of options.');
76
+ }
77
+ return { poll: { name: this.name, values, selectableCount: this.selectableCount, toAnnouncementGroup: this.toAnnouncementGroup } };
78
+ }
79
+ async send(jid, options = {}) { return this.sock.sendMessage(jid, this.build(), options); }
80
+ }
81
+
82
+ export class AlbumBuilder {
83
+ constructor(sock) { assertSocket(sock); this.sock = sock; this.items = []; this.contextInfo = undefined; }
84
+ add(item) {
85
+ if (!item || typeof item !== 'object' || (!('image' in item) && !('video' in item))) {
86
+ throw new TypeError('Album item must contain image or video content.');
87
+ }
88
+ this.items.push({ ...item });
89
+ return this;
90
+ }
91
+ addImage(image, caption, options = {}) { return this.add({ ...options, image, ...(caption ? { caption } : {}) }); }
92
+ addVideo(video, caption, options = {}) { return this.add({ ...options, video, ...(caption ? { caption } : {}) }); }
93
+ setContextInfo(contextInfo) { this.contextInfo = contextInfo; return this; }
94
+ build() {
95
+ if (!this.items.length) throw new Error('Album must contain at least one media item.');
96
+ return { albumMessage: this.items.map((item) => ({ ...item, ...(this.contextInfo && !item.contextInfo ? { contextInfo: this.contextInfo } : {}) })) };
97
+ }
98
+ async send(jid, options = {}) { return this.sock.sendMessage(jid, this.build(), options); }
99
+ }
100
+
101
+ export class ContactBuilder {
102
+ constructor(sock) { assertSocket(sock); this.sock = sock; this.contacts = []; }
103
+ add(contact) {
104
+ if (!contact || typeof contact !== 'object') throw new TypeError('Contact must be an object.');
105
+ const displayName = String(contact.displayName ?? contact.name ?? '').trim();
106
+ if (!displayName) throw new Error('Contact displayName is required.');
107
+ const phones = (Array.isArray(contact.phones) ? contact.phones : contact.phone ? [contact.phone] : []).filter(Boolean);
108
+ const lines = ['BEGIN:VCARD', 'VERSION:3.0', `FN:${escapeVCard(displayName)}`];
109
+ if (contact.company) lines.push(`ORG:${escapeVCard(contact.company)}`);
110
+ if (contact.email) lines.push(`EMAIL;type=INTERNET:${escapeVCard(contact.email)}`);
111
+ for (const phone of phones) {
112
+ const value = typeof phone === 'string' ? phone : phone.number;
113
+ if (!value) continue;
114
+ const type = typeof phone === 'object' && phone.type ? phone.type : 'CELL';
115
+ lines.push(`TEL;type=${escapeVCard(type)};type=VOICE:${escapeVCard(value)}`);
116
+ }
117
+ lines.push('END:VCARD');
118
+ this.contacts.push({ displayName, vcard: lines.join('\n') });
119
+ return this;
120
+ }
121
+ setContacts(contacts) { this.contacts = []; for (const contact of contacts ?? []) this.add(contact); return this; }
122
+ build() {
123
+ if (!this.contacts.length) throw new Error('At least one contact is required.');
124
+ return { contacts: { displayName: this.contacts.length === 1 ? this.contacts[0].displayName : 'Contacts', contacts: [...this.contacts] } };
125
+ }
126
+ async send(jid, options = {}) { return this.sock.sendMessage(jid, this.build(), options); }
127
+ }
128
+
129
+ export class LocationBuilder {
130
+ constructor(sock) { assertSocket(sock); this.sock = sock; this.data = {}; }
131
+ setCoordinates(latitude, longitude) {
132
+ const lat = Number(latitude); const lon = Number(longitude);
133
+ if (!Number.isFinite(lat) || lat < -90 || lat > 90) throw new RangeError('Latitude must be between -90 and 90.');
134
+ if (!Number.isFinite(lon) || lon < -180 || lon > 180) throw new RangeError('Longitude must be between -180 and 180.');
135
+ this.data.degreesLatitude = lat; this.data.degreesLongitude = lon; return this;
136
+ }
137
+ setName(name) { this.data.name = String(name ?? ''); return this; }
138
+ setAddress(address) { this.data.address = String(address ?? ''); return this; }
139
+ setUrl(url) { this.data.url = String(url ?? ''); return this; }
140
+ setComment(comment) { this.data.comment = String(comment ?? ''); return this; }
141
+ build() {
142
+ if (!Number.isFinite(this.data.degreesLatitude) || !Number.isFinite(this.data.degreesLongitude)) {
143
+ throw new Error('Location coordinates are required.');
144
+ }
145
+ return { location: { ...this.data } };
146
+ }
147
+ async send(jid, options = {}) { return this.sock.sendMessage(jid, this.build(), options); }
148
+ }
149
+
150
+ export class LinkPreviewBuilder {
151
+ constructor(sock) { assertSocket(sock); this.sock = sock; this.text = ''; this.preview = {}; }
152
+ setText(text) { this.text = String(text ?? ''); return this; }
153
+ setUrl(url) { this.preview['matched-text'] = String(url); this.preview['canonical-url'] = String(url); return this; }
154
+ setTitle(title) { this.preview.title = String(title ?? ''); return this; }
155
+ setDescription(description) { this.preview.description = String(description ?? ''); return this; }
156
+ setThumbnail(buffer) {
157
+ if (!Buffer.isBuffer(buffer)) throw new TypeError('Thumbnail must be a Buffer.');
158
+ this.preview.jpegThumbnail = buffer; return this;
159
+ }
160
+ build() {
161
+ if (!this.preview['matched-text']) throw new Error('Preview URL is required.');
162
+ if (!this.text) throw new Error('Message text is required.');
163
+ return { text: this.text, linkPreview: { ...this.preview, previewType: 0 } };
164
+ }
165
+ async send(jid, options = {}) { return this.sock.sendMessage(jid, this.build(), options); }
166
+ }
167
+
168
+ export const createTextStatus = ({ text, backgroundColor, font, mentions } = {}) => {
169
+ if (typeof text !== 'string' || !text.trim()) throw new TypeError('Status text is required.');
170
+ return { text, ...(backgroundColor ? { backgroundColor } : {}), ...(font !== undefined ? { font } : {}), ...(Array.isArray(mentions) && mentions.length ? { mentions } : {}) };
171
+ };
172
+ export const createImageStatus = (image, caption = '', options = {}) => ({ ...options, image, ...(caption ? { caption } : {}) });
173
+ export const createVideoStatus = (video, caption = '', options = {}) => ({ ...options, video, ...(caption ? { caption } : {}) });
174
+ export const createAudioStatus = (audio, options = {}) => ({ ...options, audio });
175
+
176
+ export class StatusHelper {
177
+ static async send(sock, content, recipients = [], options = {}) {
178
+ assertSocket(sock);
179
+ if (!content || typeof content !== 'object') throw new TypeError('Status content must be an object.');
180
+ if (!Array.isArray(recipients)) throw new TypeError('Status recipients must be an array of JIDs.');
181
+ const sendOptions = { ...options, ...(recipients.length ? { statusJidList: [...recipients] } : {}) };
182
+ return sock.sendMessage('status@broadcast', content, sendOptions);
183
+ }
184
+ static text(sock, options, recipients = []) { return this.send(sock, createTextStatus(options), recipients); }
185
+ static image(sock, image, caption, recipients = [], options) { return this.send(sock, createImageStatus(image, caption, options), recipients); }
186
+ static video(sock, video, caption, recipients = [], options) { return this.send(sock, createVideoStatus(video, caption, options), recipients); }
187
+ static audio(sock, audio, recipients = [], options) { return this.send(sock, createAudioStatus(audio, options), recipients); }
188
+ }
189
+
190
+
191
+ export class VCardBuilder extends ContactBuilder {}
192
+
193
+
194
+ export class ZelynskyBuilders {
195
+ constructor(sock) { assertSocket(sock); this.sock = sock; }
196
+ button() { return new Button(this.sock); }
197
+ buttonV2() { return new ButtonV2(this.sock); }
198
+ nativeFlow() { return new NativeFlow(this.sock); }
199
+ carousel() { return new Carousel(this.sock); }
200
+ airich() { return new AIRich(this.sock); }
201
+ poll() { return new PollBuilder(this.sock); }
202
+ album() { return new AlbumBuilder(this.sock); }
203
+ contact() { return new ContactBuilder(this.sock); }
204
+ vcard() { return new VCardBuilder(this.sock); }
205
+ location() { return new LocationBuilder(this.sock); }
206
+ linkPreview() { return new LinkPreviewBuilder(this.sock); }
207
+ }
208
+
209
+ export class MessageBuilder extends ZelynskyBuilders {
210
+ buttonV3() { return new ButtonV3(this.sock); }
211
+ a2ui() { return new A2UIBuilder(); }
212
+ }
213
+
214
+ export const attachBuilders = (sock) => {
215
+ assertSocket(sock);
216
+ const factories = {
217
+ createButton: () => new Button(sock),
218
+ createButtonV2: () => new ButtonV2(sock),
219
+ createNativeFlow: () => new NativeFlow(sock),
220
+ createCarousel: () => new Carousel(sock),
221
+ createAIRich: () => new AIRich(sock),
222
+ createORich: () => new ORich(sock),
223
+ createPoll: () => new PollBuilder(sock),
224
+ createAlbum: () => new AlbumBuilder(sock),
225
+ createContact: () => new ContactBuilder(sock),
226
+ createVCard: () => new VCardBuilder(sock),
227
+ createLocation: () => new LocationBuilder(sock),
228
+ createLinkPreview: () => new LinkPreviewBuilder(sock),
229
+ createBuilders: () => new MessageBuilder(sock),
230
+ createA2UI: () => new A2UIBuilder(),
231
+ createButtonV3: () => new ButtonV3(sock),
232
+ createMessageBuilder: () => new MessageBuilder(sock),
233
+ };
234
+ for (const [name, factory] of Object.entries(factories)) {
235
+ if (typeof sock[name] !== 'function') Object.defineProperty(sock, name, { value: factory, configurable: true });
236
+ }
237
+ return sock;
238
+ };
239
+
240
+ export { Button, ButtonV2, Carousel, AIRich, ORich, Toolkit, makeStickerPack };
241
+
242
+ export { ButtonV3, A2UIBuilder, GroupStatusHelper };
@@ -0,0 +1,74 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { SocketConfig } from '../Types/index.js';
3
+ export declare const UNAUTHORIZED_CODES: number[];
4
+ export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
5
+ export declare const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
6
+ export declare const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
7
+ export declare const DEF_CALLBACK_PREFIX = "CB:";
8
+ export declare const DEF_TAG_PREFIX = "TAG:";
9
+ export declare const PHONE_CONNECTION_CB = "CB:Pong";
10
+ export declare const WA_ADV_ACCOUNT_SIG_PREFIX: Buffer;
11
+ export declare const WA_ADV_DEVICE_SIG_PREFIX: Buffer;
12
+ export declare const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX: Buffer;
13
+ export declare const WA_ADV_HOSTED_DEVICE_SIG_PREFIX: Buffer;
14
+ export declare const WA_DEFAULT_EPHEMERAL: number;
15
+ /** Status messages older than 24 hours are considered expired */
16
+ export declare const STATUS_EXPIRY_SECONDS: number;
17
+ /** WA Web enforces a 14-day maximum age for placeholder resend requests */
18
+ export declare const PLACEHOLDER_MAX_AGE_SECONDS: number;
19
+ export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
20
+ export declare const DICT_VERSION = 3;
21
+ export declare const KEY_BUNDLE_TYPE: Buffer;
22
+ export declare const NOISE_WA_HEADER: Buffer;
23
+ /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
24
+ export declare const URL_REGEX: RegExp;
25
+ export declare const WA_CERT_DETAILS: {
26
+ SERIAL: number;
27
+ ISSUER: string;
28
+ PUBLIC_KEY: Buffer;
29
+ };
30
+ export declare const PROCESSABLE_HISTORY_TYPES: proto.HistorySync.HistorySyncType[];
31
+ export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig;
32
+ export declare const MEDIA_PATH_MAP: {
33
+ [T in MediaType]?: string;
34
+ };
35
+ export declare const MEDIA_HKDF_KEY_MAPPING: {
36
+ audio: string;
37
+ document: string;
38
+ gif: string;
39
+ image: string;
40
+ ppic: string;
41
+ product: string;
42
+ ptt: string;
43
+ sticker: string;
44
+ video: string;
45
+ 'thumbnail-document': string;
46
+ 'thumbnail-image': string;
47
+ 'thumbnail-video': string;
48
+ 'thumbnail-link': string;
49
+ 'md-msg-hist': string;
50
+ 'md-app-state': string;
51
+ 'product-catalog-image': string;
52
+ 'payment-bg-image': string;
53
+ ptv: string;
54
+ 'biz-cover-photo': string;
55
+ };
56
+ export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING;
57
+ export declare const MEDIA_KEYS: MediaType[];
58
+ export declare const MIN_PREKEY_COUNT = 5;
59
+ export declare const INITIAL_PREKEY_COUNT = 812;
60
+ export declare const UPLOAD_TIMEOUT = 30000;
61
+ export declare const MIN_UPLOAD_INTERVAL = 5000;
62
+ export declare const DEFAULT_CACHE_TTLS: {
63
+ SIGNAL_STORE: number;
64
+ MSG_RETRY: number;
65
+ CALL_OFFER: number;
66
+ USER_DEVICES: number;
67
+ };
68
+ export declare const TimeMs: {
69
+ Minute: number;
70
+ Hour: number;
71
+ Day: number;
72
+ Week: number;
73
+ };
74
+ //# sourceMappingURL=index.d.ts.map