@elrayyxml/baileys 1.0.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 (191) hide show
  1. package/LICENSE +21 -0
  2. package/README.MD +60 -0
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +4775 -0
  5. package/WAProto/index.js +169661 -0
  6. package/engine-requirements.js +10 -0
  7. package/lib/Defaults/baileys-version.json +3 -0
  8. package/lib/Defaults/index.d.ts +51 -0
  9. package/lib/Defaults/index.js +108 -0
  10. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  11. package/lib/Signal/Group/ciphertext-message.js +15 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  13. package/lib/Signal/Group/group-session-builder.js +64 -0
  14. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  15. package/lib/Signal/Group/group_cipher.js +96 -0
  16. package/lib/Signal/Group/index.d.ts +11 -0
  17. package/lib/Signal/Group/index.js +57 -0
  18. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  19. package/lib/Signal/Group/keyhelper.js +55 -0
  20. package/lib/Signal/Group/queue-job.d.ts +1 -0
  21. package/lib/Signal/Group/queue-job.js +57 -0
  22. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  23. package/lib/Signal/Group/sender-chain-key.js +34 -0
  24. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  26. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  27. package/lib/Signal/Group/sender-key-message.js +69 -0
  28. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  29. package/lib/Signal/Group/sender-key-name.js +51 -0
  30. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  31. package/lib/Signal/Group/sender-key-record.js +53 -0
  32. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  33. package/lib/Signal/Group/sender-key-state.js +99 -0
  34. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  35. package/lib/Signal/Group/sender-message-key.js +29 -0
  36. package/lib/Signal/libsignal.d.ts +3 -0
  37. package/lib/Signal/libsignal.js +174 -0
  38. package/lib/Socket/Client/index.d.ts +2 -0
  39. package/lib/Socket/Client/index.js +18 -0
  40. package/lib/Socket/Client/types.d.ts +16 -0
  41. package/lib/Socket/Client/types.js +13 -0
  42. package/lib/Socket/Client/websocket.d.ts +13 -0
  43. package/lib/Socket/Client/websocket.js +72 -0
  44. package/lib/Socket/business.d.ts +172 -0
  45. package/lib/Socket/business.js +260 -0
  46. package/lib/Socket/chats.d.ts +82 -0
  47. package/lib/Socket/chats.js +890 -0
  48. package/lib/Socket/groups.d.ts +124 -0
  49. package/lib/Socket/groups.js +332 -0
  50. package/lib/Socket/index.d.ts +172 -0
  51. package/lib/Socket/index.js +10 -0
  52. package/lib/Socket/messages-recv.d.ts +161 -0
  53. package/lib/Socket/messages-recv.js +1142 -0
  54. package/lib/Socket/messages-send.d.ts +151 -0
  55. package/lib/Socket/messages-send.js +863 -0
  56. package/lib/Socket/newsletter.d.ts +136 -0
  57. package/lib/Socket/newsletter.js +250 -0
  58. package/lib/Socket/socket.d.ts +43 -0
  59. package/lib/Socket/socket.js +654 -0
  60. package/lib/Socket/type.d.ts +253 -0
  61. package/lib/Socket/type.js +405 -0
  62. package/lib/Socket/usync.d.ts +36 -0
  63. package/lib/Socket/usync.js +70 -0
  64. package/lib/Store/index.d.ts +2 -0
  65. package/lib/Store/index.js +8 -0
  66. package/lib/Store/make-in-memory-store.d.ts +118 -0
  67. package/lib/Store/make-in-memory-store.js +429 -0
  68. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  69. package/lib/Store/make-ordered-dictionary.js +81 -0
  70. package/lib/Store/object-repository.d.ts +10 -0
  71. package/lib/Store/object-repository.js +27 -0
  72. package/lib/Types/Auth.d.ts +103 -0
  73. package/lib/Types/Auth.js +2 -0
  74. package/lib/Types/Call.d.ts +13 -0
  75. package/lib/Types/Call.js +2 -0
  76. package/lib/Types/Chat.d.ts +109 -0
  77. package/lib/Types/Chat.js +4 -0
  78. package/lib/Types/Contact.d.ts +23 -0
  79. package/lib/Types/Contact.js +2 -0
  80. package/lib/Types/Events.d.ts +199 -0
  81. package/lib/Types/Events.js +2 -0
  82. package/lib/Types/GroupMetadata.d.ts +64 -0
  83. package/lib/Types/GroupMetadata.js +2 -0
  84. package/lib/Types/Label.d.ts +35 -0
  85. package/lib/Types/Label.js +27 -0
  86. package/lib/Types/LabelAssociation.d.ts +29 -0
  87. package/lib/Types/LabelAssociation.js +9 -0
  88. package/lib/Types/Message.d.ts +400 -0
  89. package/lib/Types/Message.js +7 -0
  90. package/lib/Types/Newsletter.d.ts +79 -0
  91. package/lib/Types/Newsletter.js +18 -0
  92. package/lib/Types/Product.d.ts +78 -0
  93. package/lib/Types/Product.js +2 -0
  94. package/lib/Types/Signal.d.ts +57 -0
  95. package/lib/Types/Signal.js +2 -0
  96. package/lib/Types/Socket.d.ts +119 -0
  97. package/lib/Types/Socket.js +2 -0
  98. package/lib/Types/State.d.ts +27 -0
  99. package/lib/Types/State.js +2 -0
  100. package/lib/Types/USync.d.ts +25 -0
  101. package/lib/Types/USync.js +2 -0
  102. package/lib/Types/index.d.ts +64 -0
  103. package/lib/Types/index.js +42 -0
  104. package/lib/Utils/auth-utils.d.ts +18 -0
  105. package/lib/Utils/auth-utils.js +199 -0
  106. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  107. package/lib/Utils/baileys-event-stream.js +63 -0
  108. package/lib/Utils/browser-utils.js +35 -0
  109. package/lib/Utils/business.d.ts +22 -0
  110. package/lib/Utils/business.js +234 -0
  111. package/lib/Utils/chat-utils.d.ts +70 -0
  112. package/lib/Utils/chat-utils.js +730 -0
  113. package/lib/Utils/crypto.d.ts +40 -0
  114. package/lib/Utils/crypto.js +193 -0
  115. package/lib/Utils/decode-wa-message.d.ts +35 -0
  116. package/lib/Utils/decode-wa-message.js +207 -0
  117. package/lib/Utils/event-buffer.d.ts +35 -0
  118. package/lib/Utils/event-buffer.js +518 -0
  119. package/lib/Utils/generics.d.ts +89 -0
  120. package/lib/Utils/generics.js +445 -0
  121. package/lib/Utils/history.d.ts +19 -0
  122. package/lib/Utils/history.js +95 -0
  123. package/lib/Utils/index.d.ts +17 -0
  124. package/lib/Utils/index.js +33 -0
  125. package/lib/Utils/link-preview.d.ts +21 -0
  126. package/lib/Utils/link-preview.js +126 -0
  127. package/lib/Utils/logger.d.ts +11 -0
  128. package/lib/Utils/logger.js +7 -0
  129. package/lib/Utils/lt-hash.d.ts +12 -0
  130. package/lib/Utils/lt-hash.js +51 -0
  131. package/lib/Utils/make-mutex.d.ts +7 -0
  132. package/lib/Utils/make-mutex.js +43 -0
  133. package/lib/Utils/messages-media.d.ts +120 -0
  134. package/lib/Utils/messages-media.js +880 -0
  135. package/lib/Utils/messages.d.ts +75 -0
  136. package/lib/Utils/messages.js +1062 -0
  137. package/lib/Utils/noise-handler.d.ts +19 -0
  138. package/lib/Utils/noise-handler.js +150 -0
  139. package/lib/Utils/process-message.d.ts +42 -0
  140. package/lib/Utils/process-message.js +372 -0
  141. package/lib/Utils/signal.d.ts +33 -0
  142. package/lib/Utils/signal.js +153 -0
  143. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  144. package/lib/Utils/use-multi-file-auth-state.js +125 -0
  145. package/lib/Utils/validate-connection.d.ts +10 -0
  146. package/lib/Utils/validate-connection.js +173 -0
  147. package/lib/WABinary/constants.d.ts +27 -0
  148. package/lib/WABinary/constants.js +1303 -0
  149. package/lib/WABinary/decode.d.ts +6 -0
  150. package/lib/WABinary/decode.js +265 -0
  151. package/lib/WABinary/encode.d.ts +2 -0
  152. package/lib/WABinary/encode.js +250 -0
  153. package/lib/WABinary/generic-utils.d.ts +14 -0
  154. package/lib/WABinary/generic-utils.js +119 -0
  155. package/lib/WABinary/index.d.ts +5 -0
  156. package/lib/WABinary/index.js +21 -0
  157. package/lib/WABinary/jid-utils.d.ts +36 -0
  158. package/lib/WABinary/jid-utils.js +83 -0
  159. package/lib/WABinary/types.d.ts +18 -0
  160. package/lib/WABinary/types.js +2 -0
  161. package/lib/WAM/BinaryInfo.d.ts +8 -0
  162. package/lib/WAM/BinaryInfo.js +13 -0
  163. package/lib/WAM/constants.d.ts +38 -0
  164. package/lib/WAM/constants.js +15350 -0
  165. package/lib/WAM/encode.d.ts +2 -0
  166. package/lib/WAM/encode.js +155 -0
  167. package/lib/WAM/index.d.ts +3 -0
  168. package/lib/WAM/index.js +19 -0
  169. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  170. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  171. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  172. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  173. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  174. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  175. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  176. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  177. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  178. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  179. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  180. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  181. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  182. package/lib/WAUSync/Protocols/index.js +20 -0
  183. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  184. package/lib/WAUSync/USyncQuery.js +89 -0
  185. package/lib/WAUSync/USyncUser.d.ts +12 -0
  186. package/lib/WAUSync/USyncUser.js +26 -0
  187. package/lib/WAUSync/index.d.ts +3 -0
  188. package/lib/WAUSync/index.js +19 -0
  189. package/lib/index.d.ts +13 -0
  190. package/lib/index.js +41 -0
  191. package/package.json +126 -0
@@ -0,0 +1,253 @@
1
+ import { proto } from '../../WAProto';
2
+
3
+ declare namespace elrayyxml {
4
+ interface MediaUploadOptions {
5
+ fileEncSha256?: Buffer;
6
+ mediaType?: string;
7
+ newsletter?: boolean;
8
+ }
9
+
10
+ type WAMediaUploadFunction = (
11
+ stream: Buffer | NodeJS.ReadableStream,
12
+ options?: MediaUploadOptions
13
+ ) => Promise<{ url: string; directPath: string }>;
14
+
15
+ interface WAMessageContentGenerationOptions {
16
+ upload?: WAMediaUploadFunction;
17
+ mediaCache?: any;
18
+ options?: any;
19
+ logger?: any;
20
+ }
21
+
22
+ interface StickerMessage {
23
+ url: string;
24
+ fileSha256: Buffer | string;
25
+ fileEncSha256: Buffer | string;
26
+ mediaKey: Buffer | string;
27
+ mimetype: string;
28
+ directPath: string;
29
+ fileLength: number | string;
30
+ mediaKeyTimestamp: number | string;
31
+ isAnimated?: boolean;
32
+ stickerSentTs?: number | string;
33
+ isAvatar?: boolean;
34
+ isAiSticker?: boolean;
35
+ isLottie?: boolean;
36
+ }
37
+
38
+ interface PaymentMessage {
39
+ amount: number;
40
+ currency?: string;
41
+ from?: string;
42
+ expiry?: number;
43
+ sticker?: { stickerMessage: StickerMessage };
44
+ note?: string;
45
+ background?: {
46
+ id?: string;
47
+ fileLength?: string;
48
+ width?: number;
49
+ height?: number;
50
+ mimetype?: string;
51
+ placeholderArgb?: number;
52
+ textArgb?: number;
53
+ subtextArgb?: number;
54
+ };
55
+ }
56
+
57
+ interface ProductMessage {
58
+ title: string;
59
+ description: string;
60
+ thumbnail: Buffer | { url: string };
61
+ productId: string;
62
+ retailerId: string;
63
+ url: string;
64
+ body?: string;
65
+ footer?: string;
66
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
67
+ priceAmount1000?: number | null;
68
+ currencyCode?: string;
69
+ }
70
+
71
+ interface InteractiveMessage {
72
+ header?: string;
73
+ title: string;
74
+ footer?: string;
75
+ thumbnail?: string;
76
+ image?: string | Buffer | { url: string };
77
+ video?: string | Buffer | { url: string };
78
+ document?: string | Buffer | { url: string };
79
+ mimetype?: string;
80
+ fileName?: string;
81
+ jpegThumbnail?: string | Buffer | { url: string };
82
+ contextInfo?: {
83
+ mentionedJid?: string[];
84
+ forwardingScore?: number;
85
+ isForwarded?: boolean;
86
+ externalAdReply?: {
87
+ title?: string;
88
+ body?: string;
89
+ mediaType?: number;
90
+ thumbnailUrl?: string;
91
+ mediaUrl?: string;
92
+ sourceUrl?: string;
93
+ showAdAttribution?: boolean;
94
+ renderLargerThumbnail?: boolean;
95
+ [key: string]: any;
96
+ };
97
+ [key: string]: any;
98
+ };
99
+ externalAdReply?: {
100
+ title?: string;
101
+ body?: string;
102
+ mediaType?: number;
103
+ thumbnailUrl?: string;
104
+ mediaUrl?: string;
105
+ sourceUrl?: string;
106
+ showAdAttribution?: boolean;
107
+ renderLargerThumbnail?: boolean;
108
+ [key: string]: any;
109
+ };
110
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
111
+ nativeFlowMessage?: {
112
+ messageParamsJson?: string;
113
+ buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
114
+ [key: string]: any;
115
+ };
116
+ }
117
+
118
+ interface AlbumItem {
119
+ image?: string | Buffer | { url: string; caption?: string };
120
+ video?: string | Buffer | { url: string; caption?: string };
121
+ }
122
+
123
+ interface EventMessageLocation {
124
+ degreesLatitude: number;
125
+ degreesLongitude: number;
126
+ name: string;
127
+ }
128
+
129
+ interface EventMessage {
130
+ isCanceled?: boolean;
131
+ name: string;
132
+ description: string;
133
+ location?: EventMessageLocation;
134
+ joinLink?: string;
135
+ startTime?: string | number;
136
+ endTime?: string | number;
137
+ extraGuestsAllowed?: boolean;
138
+ }
139
+
140
+ interface PollVote {
141
+ optionName: string;
142
+ optionVoteCount: string | number;
143
+ }
144
+
145
+ interface PollResultMessage {
146
+ name: string;
147
+ pollVotes: PollVote[];
148
+ }
149
+
150
+ interface GroupStatusMessage {
151
+ message?: any;
152
+ image?: string | Buffer | { url: string };
153
+ video?: string | Buffer | { url: string };
154
+ text?: string;
155
+ caption?: string;
156
+ document?: string | Buffer | { url: string };
157
+ [key: string]: any;
158
+ }
159
+
160
+ interface MessageContent {
161
+ requestPaymentMessage?: PaymentMessage;
162
+ productMessage?: ProductMessage;
163
+ interactiveMessage?: InteractiveMessage;
164
+ albumMessage?: AlbumItem[];
165
+ eventMessage?: EventMessage;
166
+ pollResultMessage?: PollResultMessage;
167
+ groupStatusMessage?: GroupStatusMessage;
168
+ sender?: string;
169
+ }
170
+
171
+ interface MessageOptions {
172
+ quoted?: proto.IWebMessageInfo;
173
+ filter?: boolean;
174
+ }
175
+
176
+ interface Utils {
177
+ prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
178
+ generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
179
+ generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
180
+ generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
181
+ generateMessageID: () => string;
182
+ prepareMessageContent?: (content: any, options?: any) => Promise<any>;
183
+ }
184
+
185
+ interface BailUtils {
186
+ generateWAMessageContent?: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
187
+ generateMessageID: () => string;
188
+ getContentType: (msg: any) => string;
189
+ }
190
+ }
191
+
192
+ declare class elrayyxml {
193
+ constructor(
194
+ utils: elrayyxml.Utils,
195
+ waUploadToServer: elrayyxml.WAMediaUploadFunction,
196
+ relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
197
+ );
198
+
199
+ detectType(content: elrayyxml.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
200
+
201
+ handlePayment(
202
+ content: { requestPaymentMessage: elrayyxml.PaymentMessage },
203
+ quoted?: proto.IWebMessageInfo
204
+ ): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
205
+
206
+ handleProduct(
207
+ content: { productMessage: elrayyxml.ProductMessage },
208
+ jid: string,
209
+ quoted?: proto.IWebMessageInfo
210
+ ): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
211
+
212
+ handleInteractive(
213
+ content: { interactiveMessage: elrayyxml.InteractiveMessage },
214
+ jid: string,
215
+ quoted?: proto.IWebMessageInfo
216
+ ): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
217
+
218
+ handleAlbum(
219
+ content: { albumMessage: elrayyxml.AlbumItem[] },
220
+ jid: string,
221
+ quoted?: proto.IWebMessageInfo
222
+ ): Promise<any>;
223
+
224
+ handleEvent(
225
+ content: { eventMessage: elrayyxml.EventMessage },
226
+ jid: string,
227
+ quoted?: proto.IWebMessageInfo
228
+ ): Promise<any>;
229
+
230
+ handlePollResult(
231
+ content: { pollResultMessage: elrayyxml.PollResultMessage },
232
+ jid: string,
233
+ quoted?: proto.IWebMessageInfo
234
+ ): Promise<any>;
235
+
236
+ handleGroupStory(
237
+ content: { groupStatusMessage: elrayyxml.GroupStatusMessage },
238
+ jid: string,
239
+ quoted?: proto.IWebMessageInfo
240
+ ): Promise<any>;
241
+
242
+ buildMessageContent(
243
+ content: any,
244
+ opts?: elrayyxml.WAMessageContentGenerationOptions
245
+ ): Promise<any>;
246
+
247
+ utils: elrayyxml.Utils;
248
+ relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
249
+ waUploadToServer: elrayyxml.WAMediaUploadFunction;
250
+ bail: elrayyxml.BailUtils;
251
+ }
252
+
253
+ export = elrayyxml;
@@ -0,0 +1,405 @@
1
+ const WAProto = require('../../WAProto').proto;
2
+ const crypto = require('crypto');
3
+ const Utils_1 = require("../Utils");
4
+
5
+ class elrayyxml {
6
+ constructor(utils, waUploadToServer, relayMessageFn, authState) {
7
+ this.utils = utils;
8
+ this.relayMessage = relayMessageFn;
9
+ this.waUploadToServer = waUploadToServer;
10
+ this.authState = authState;
11
+ }
12
+
13
+ getUserJid() {
14
+ return this.authState?.creds?.me?.id;
15
+ }
16
+
17
+ detectType(content) {
18
+ if (content.requestPaymentMessage) return 'PAYMENT';
19
+ if (content.productMessage) return 'PRODUCT';
20
+ if (content.interactiveMessage) return 'INTERACTIVE';
21
+ if (content.albumMessage) return 'ALBUM';
22
+ if (content.eventMessage) return 'EVENT';
23
+ if (content.pollResultMessage) return 'POLL_RESULT';
24
+ if (content.groupStatusMessage) return 'GROUP_STORY';
25
+ return null;
26
+ }
27
+
28
+ async handlePayment(content, jid, quoted) {
29
+ const data = content.requestPaymentMessage;
30
+ let notes = {};
31
+
32
+ if (data.sticker?.stickerMessage) {
33
+ notes = {
34
+ stickerMessage: {
35
+ ...data.sticker.stickerMessage,
36
+ contextInfo: {
37
+ stanzaId: quoted?.key?.id,
38
+ participant: quoted?.key?.participant || this.getUserJid(),
39
+ quotedMessage: quoted?.message
40
+ }
41
+ }
42
+ };
43
+ } else if (data.note) {
44
+ notes = {
45
+ extendedTextMessage: {
46
+ text: data.note,
47
+ contextInfo: {
48
+ stanzaId: quoted?.key?.id,
49
+ participant: quoted?.key?.participant || this.getUserJid(),
50
+ quotedMessage: quoted?.message
51
+ }
52
+ }
53
+ };
54
+ }
55
+
56
+ const paymentContent = {
57
+ requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
58
+ expiryTimestamp: data.expiry || 0,
59
+ amount1000: data.amount || 0,
60
+ currencyCodeIso4217: data.currency || "IDR",
61
+ requestFrom: data.from || "0@s.whatsapp.net",
62
+ noteMessage: notes,
63
+ background: data.background ?? {
64
+ id: "DEFAULT",
65
+ placeholderArgb: 0xFFF0F0F0
66
+ }
67
+ })
68
+ };
69
+
70
+ const msg = await Utils_1.generateWAMessageFromContent(jid, paymentContent, {
71
+ quoted,
72
+ userJid: this.getUserJid()
73
+ });
74
+
75
+ await this.relayMessage(jid, msg.message, {
76
+ messageId: msg.key.id
77
+ });
78
+
79
+ return msg;
80
+ }
81
+
82
+ async handleProduct(content, jid, quoted) {
83
+ const {
84
+ title, description, thumbnail, productId, retailerId, url,
85
+ body = "", footer = "", buttons = [], priceAmount1000 = null, currencyCode = "IDR"
86
+ } = content.productMessage;
87
+
88
+ let productImage;
89
+ if (Buffer.isBuffer(thumbnail)) {
90
+ const { imageMessage } = await Utils_1.generateWAMessageContent(
91
+ { image: thumbnail },
92
+ { upload: this.waUploadToServer }
93
+ );
94
+ productImage = imageMessage;
95
+ } else if (typeof thumbnail === 'object' && thumbnail.url) {
96
+ const { imageMessage } = await Utils_1.generateWAMessageContent(
97
+ { image: { url: thumbnail.url }},
98
+ { upload: this.waUploadToServer }
99
+ );
100
+ productImage = imageMessage;
101
+ }
102
+
103
+ const productContent = {
104
+ viewOnceMessage: {
105
+ message: {
106
+ interactiveMessage: {
107
+ body: { text: body },
108
+ footer: { text: footer },
109
+ header: {
110
+ title,
111
+ hasMediaAttachment: true,
112
+ productMessage: {
113
+ product: {
114
+ productImage,
115
+ productId,
116
+ title,
117
+ description,
118
+ currencyCode,
119
+ priceAmount1000,
120
+ retailerId,
121
+ url,
122
+ productImageCount: 1
123
+ },
124
+ businessOwnerJid: "0@s.whatsapp.net"
125
+ }
126
+ },
127
+ nativeFlowMessage: { buttons }
128
+ }
129
+ }
130
+ }
131
+ };
132
+
133
+ const msg = await Utils_1.generateWAMessageFromContent(jid, productContent, {
134
+ quoted,
135
+ userJid: this.getUserJid()
136
+ });
137
+
138
+ await this.relayMessage(jid, msg.message, {
139
+ messageId: msg.key.id
140
+ });
141
+
142
+ return msg;
143
+ }
144
+
145
+ async handleInteractive(content, jid, quoted) {
146
+ const {
147
+ title, footer, thumbnail, image, video, document, mimetype, fileName,
148
+ jpegThumbnail, contextInfo, externalAdReply, buttons = [], nativeFlowMessage, header
149
+ } = content.interactiveMessage;
150
+
151
+ let media = null;
152
+ if (thumbnail) {
153
+ media = await this.utils.prepareWAMessageMedia(
154
+ { image: { url: thumbnail } },
155
+ { upload: this.waUploadToServer }
156
+ );
157
+ } else if (image) {
158
+ if (typeof image === 'object' && image.url) {
159
+ media = await this.utils.prepareWAMessageMedia(
160
+ { image: { url: image.url } },
161
+ { upload: this.waUploadToServer }
162
+ );
163
+ } else {
164
+ media = await this.utils.prepareWAMessageMedia(
165
+ { image: image },
166
+ { upload: this.waUploadToServer }
167
+ );
168
+ }
169
+ } else if (video) {
170
+ if (typeof video === 'object' && video.url) {
171
+ media = await this.utils.prepareWAMessageMedia(
172
+ { video: { url: video.url } },
173
+ { upload: this.waUploadToServer }
174
+ );
175
+ } else {
176
+ media = await this.utils.prepareWAMessageMedia(
177
+ { video: video },
178
+ { upload: this.waUploadToServer }
179
+ );
180
+ }
181
+ } else if (document) {
182
+ let documentPayload = { document: document };
183
+ if (jpegThumbnail) {
184
+ documentPayload.jpegThumbnail = jpegThumbnail;
185
+ }
186
+ media = await this.utils.prepareWAMessageMedia(
187
+ documentPayload,
188
+ { upload: this.waUploadToServer }
189
+ );
190
+ if (fileName) media.documentMessage.fileName = fileName;
191
+ if (mimetype) media.documentMessage.mimetype = mimetype;
192
+ }
193
+
194
+ let interactiveMessage = {
195
+ body: { text: title || "" },
196
+ footer: { text: footer || "" }
197
+ };
198
+
199
+ if (buttons && buttons.length > 0) {
200
+ interactiveMessage.nativeFlowMessage = { buttons: buttons };
201
+ }
202
+ if (nativeFlowMessage) {
203
+ interactiveMessage.nativeFlowMessage = {
204
+ ...interactiveMessage.nativeFlowMessage,
205
+ ...nativeFlowMessage
206
+ };
207
+ }
208
+
209
+ if (media) {
210
+ interactiveMessage.header = {
211
+ title: header || "",
212
+ hasMediaAttachment: true,
213
+ ...media
214
+ };
215
+ } else {
216
+ interactiveMessage.header = {
217
+ title: header || "",
218
+ hasMediaAttachment: false
219
+ };
220
+ }
221
+
222
+ let finalContextInfo = {};
223
+ if (contextInfo) {
224
+ finalContextInfo = {
225
+ mentionedJid: contextInfo.mentionedJid || [],
226
+ forwardingScore: contextInfo.forwardingScore || 0,
227
+ isForwarded: contextInfo.isForwarded || false,
228
+ ...contextInfo
229
+ };
230
+ }
231
+
232
+ if (externalAdReply) {
233
+ finalContextInfo.externalAdReply = externalAdReply;
234
+ }
235
+
236
+ if (Object.keys(finalContextInfo).length > 0) {
237
+ interactiveMessage.contextInfo = finalContextInfo;
238
+ }
239
+
240
+ const interactiveContent = { interactiveMessage: interactiveMessage };
241
+
242
+ const msg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, {
243
+ quoted,
244
+ userJid: this.getUserJid()
245
+ });
246
+
247
+ await this.relayMessage(jid, msg.message, {
248
+ messageId: msg.key.id
249
+ });
250
+
251
+ return msg;
252
+ }
253
+
254
+ async handleAlbum(content, jid, quoted) {
255
+ const array = content.albumMessage;
256
+
257
+ const albumContent = {
258
+ messageContextInfo: {
259
+ messageSecret: crypto.randomBytes(32),
260
+ },
261
+ albumMessage: {
262
+ expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
263
+ expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
264
+ },
265
+ };
266
+
267
+ const msg = await Utils_1.generateWAMessageFromContent(jid, albumContent, {
268
+ userJid: this.getUserJid(),
269
+ quoted,
270
+ upload: this.waUploadToServer
271
+ });
272
+
273
+ await this.relayMessage(jid, msg.message, {
274
+ messageId: msg.key.id,
275
+ });
276
+
277
+ for (let contentItem of array) {
278
+ const mediaMsg = await Utils_1.generateWAMessage(jid, contentItem, {
279
+ upload: this.waUploadToServer,
280
+ userJid: this.getUserJid()
281
+ });
282
+
283
+ mediaMsg.message.messageContextInfo = {
284
+ messageSecret: crypto.randomBytes(32),
285
+ messageAssociation: {
286
+ associationType: 1,
287
+ parentMessageKey: msg.key,
288
+ }
289
+ };
290
+
291
+ await this.relayMessage(jid, mediaMsg.message, {
292
+ messageId: mediaMsg.key.id,
293
+ quoted: {
294
+ key: msg.key,
295
+ message: msg.message,
296
+ },
297
+ });
298
+ }
299
+
300
+ return msg;
301
+ }
302
+
303
+ async handleEvent(content, jid, quoted) {
304
+ const eventData = content.eventMessage;
305
+
306
+ const eventContent = {
307
+ viewOnceMessage: {
308
+ message: {
309
+ messageContextInfo: {
310
+ deviceListMetadata: {},
311
+ deviceListMetadataVersion: 2,
312
+ messageSecret: crypto.randomBytes(32),
313
+ },
314
+ eventMessage: {
315
+ contextInfo: {
316
+ mentionedJid: [jid],
317
+ },
318
+ isCanceled: eventData.isCanceled || false,
319
+ name: eventData.name,
320
+ description: eventData.description,
321
+ location: eventData.location || {
322
+ degreesLatitude: 0,
323
+ degreesLongitude: 0,
324
+ name: "Location"
325
+ },
326
+ joinLink: eventData.joinLink || '',
327
+ startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
328
+ endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
329
+ extraGuestsAllowed: eventData.extraGuestsAllowed !== false
330
+ }
331
+ }
332
+ }
333
+ };
334
+
335
+ const msg = await Utils_1.generateWAMessageFromContent(jid, eventContent, {
336
+ quoted,
337
+ userJid: this.getUserJid()
338
+ });
339
+
340
+ await this.relayMessage(jid, msg.message, {
341
+ messageId: msg.key.id
342
+ });
343
+
344
+ return msg;
345
+ }
346
+
347
+ async handlePollResult(content, jid, quoted) {
348
+ const pollData = content.pollResultMessage;
349
+
350
+ const pollContent = {
351
+ pollResultSnapshotMessage: {
352
+ name: pollData.name,
353
+ pollVotes: pollData.pollVotes.map(vote => ({
354
+ optionName: vote.optionName,
355
+ optionVoteCount: typeof vote.optionVoteCount === 'number'
356
+ ? vote.optionVoteCount.toString()
357
+ : vote.optionVoteCount
358
+ }))
359
+ }
360
+ };
361
+
362
+ const msg = await Utils_1.generateWAMessageFromContent(jid, pollContent, {
363
+ userJid: this.getUserJid(),
364
+ quoted
365
+ });
366
+
367
+ await this.relayMessage(jid, msg.message, {
368
+ messageId: msg.key.id
369
+ });
370
+
371
+ return msg;
372
+ }
373
+
374
+ async handleGroupStory(content, jid, quoted) {
375
+ const storyData = content.groupStatusMessage;
376
+
377
+ let waMsgContent;
378
+ if (storyData.message) {
379
+ waMsgContent = storyData;
380
+ } else {
381
+ waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
382
+ upload: this.waUploadToServer
383
+ });
384
+ }
385
+
386
+ const groupStoryContent = {
387
+ groupStatusMessageV2: {
388
+ message: waMsgContent.message || waMsgContent
389
+ }
390
+ };
391
+
392
+ const msg = await Utils_1.generateWAMessageFromContent(jid, groupStoryContent, {
393
+ userJid: this.getUserJid(),
394
+ quoted
395
+ });
396
+
397
+ await this.relayMessage(jid, msg.message, {
398
+ messageId: msg.key.id
399
+ });
400
+
401
+ return msg;
402
+ }
403
+ }
404
+
405
+ module.exports = elrayyxml;
@@ -0,0 +1,36 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { SocketConfig } from '../Types';
3
+ import { BinaryNode } from '../WABinary';
4
+ import { USyncQuery } from '../WAUSync';
5
+ export declare const makeUSyncSocket: (config: SocketConfig) => {
6
+ executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
7
+ type: "md";
8
+ ws: import("./Client").WebSocketClient;
9
+ ev: import("../Types").BaileysEventEmitter & {
10
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
11
+ buffer(): void;
12
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
13
+ flush(force?: boolean): boolean;
14
+ isBuffering(): boolean;
15
+ };
16
+ authState: {
17
+ creds: import("../Types").AuthenticationCreds;
18
+ keys: import("../Types").SignalKeyStoreWithTransaction;
19
+ };
20
+ signalRepository: import("../Types").SignalRepository;
21
+ user: import("../Types").Contact | undefined;
22
+ generateMessageTag: () => string;
23
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
24
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
25
+ waitForSocketOpen: () => Promise<void>;
26
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
27
+ sendNode: (frame: BinaryNode) => Promise<void>;
28
+ logout: (msg?: string) => Promise<void>;
29
+ end: (error: Error | undefined) => void;
30
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
31
+ uploadPreKeys: (count?: number) => Promise<void>;
32
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
33
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
34
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
35
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
36
+ };