@ryuhan/baileys 2.0.1 → 2.0.2

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.
@@ -75,6 +75,67 @@ type Contextable = {
75
75
  /** add contextInfo to the message */
76
76
  contextInfo?: proto.IContextInfo;
77
77
  };
78
+
79
+ type Listable = {
80
+ /** Sections of the List */
81
+ sections?: proto.Message.ListMessage.ISection[];
82
+ /** Title of a List Message only */
83
+ title?: string;
84
+ /** Text of the button on the list (required) */
85
+ buttonText?: string;
86
+ /** ListType of a List Message only */
87
+ listType?: proto.Message.ListMessage.ListType;
88
+ /** Description of the list */
89
+ text?: string;
90
+ /** Footer text */
91
+ footer?: string;
92
+ };
93
+
94
+ type ProductListable = {
95
+ /** Product list sections */
96
+ productList?: proto.Message.ListMessage.IProductSection[];
97
+ /** Thumbnail for product list */
98
+ thumbnail?: WAMediaUpload;
99
+ /** Business owner JID */
100
+ businessOwnerJid?: string;
101
+ /** Title of product list */
102
+ title?: string;
103
+ /** Button text */
104
+ buttonText?: string;
105
+ /** Footer text */
106
+ footer?: string;
107
+ /** Description */
108
+ text?: string;
109
+ };
110
+
111
+ type Buttonable = {
112
+ /** add buttons to the message */
113
+ buttons?: proto.Message.ButtonsMessage.IButton[];
114
+ /** Title for button message */
115
+ title?: string;
116
+ /** Footer text */
117
+ footer?: string;
118
+ };
119
+
120
+ type Templatable = {
121
+ /** add template buttons to the message */
122
+ templateButtons?: proto.IHydratedTemplateButton[];
123
+ /** Footer text */
124
+ footer?: string;
125
+ };
126
+
127
+ type Interactiveable = {
128
+ /** add interactive buttons to the message */
129
+ interactiveButtons?: proto.Message.InteractiveMessage.NativeFlowMessage.INativeFlowButton[];
130
+ /** Title */
131
+ title?: string;
132
+ /** Subtitle */
133
+ subtitle?: string;
134
+ /** Footer text */
135
+ footer?: string;
136
+ /** Has media attachment */
137
+ media?: boolean;
138
+ };
78
139
  type ViewOnce = {
79
140
  viewOnce?: boolean;
80
141
  };
@@ -105,6 +166,91 @@ export type EventMessageOptions = {
105
166
  extraGuestsAllowed?: boolean;
106
167
  messageSecret?: Uint8Array<ArrayBufferLike>;
107
168
  };
169
+
170
+ export type PollResultOptions = {
171
+ name: string;
172
+ values: [string, number][]; // [optionName, voteCount][]
173
+ };
174
+
175
+ export type AlbumMessage = {
176
+ image?: WAMediaUpload;
177
+ video?: WAMediaUpload;
178
+ caption?: string;
179
+ }[];
180
+
181
+ export type Sticker = {
182
+ data: WAMediaUpload;
183
+ emojis?: string[];
184
+ accessibilityLabel?: string;
185
+ isAnimated?: boolean;
186
+ isLottie?: boolean;
187
+ };
188
+
189
+ export type StickerPack = {
190
+ stickers: Sticker[];
191
+ cover: WAMediaUpload;
192
+ name: string;
193
+ publisher: string;
194
+ description?: string;
195
+ packId?: string;
196
+ };
197
+
198
+ export type AdminInviteInfo = {
199
+ jid: string;
200
+ name: string;
201
+ caption: string;
202
+ expiration: number;
203
+ jpegThumbnail?: string;
204
+ };
205
+
206
+ export type PaymentInfo = {
207
+ note: string;
208
+ currency?: string;
209
+ offset?: number;
210
+ amount?: number;
211
+ expiry?: number;
212
+ from?: string;
213
+ image?: {
214
+ placeholderArgb: number;
215
+ textArgb: number;
216
+ subtextArgb: number;
217
+ };
218
+ };
219
+
220
+ export type PaymentInviteInfo = {
221
+ type: number;
222
+ expiry: number;
223
+ };
224
+
225
+ export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
226
+ productImage: WAMediaUpload;
227
+ };
228
+
229
+ export type OrderMessage = proto.Message.IOrderMessage;
230
+
231
+ export type Carousel = {
232
+ image?: WAMediaUpload;
233
+ video?: WAMediaUpload;
234
+ product?: WASendableProduct;
235
+ title?: string;
236
+ body?: string;
237
+ footer?: string;
238
+ buttons?: proto.Message.InteractiveMessage.NativeFlowMessage.INativeFlowButton[];
239
+ };
240
+
241
+ export type ShopSurface = 'FB' | 'IG' | 'WA' | 'WA_WEB';
242
+
243
+ export type ShopInfo = {
244
+ surface: ShopSurface;
245
+ id: string;
246
+ };
247
+
248
+ export type CollectionInfo = {
249
+ bizJid: string;
250
+ id: string;
251
+ version?: number;
252
+ };
253
+
108
254
  type SharePhoneNumber = {
109
255
  sharePhoneNumber: boolean;
110
256
  };
@@ -115,14 +261,14 @@ export type AnyMediaMessageContent = (({
115
261
  image: WAMediaUpload;
116
262
  caption?: string;
117
263
  jpegThumbnail?: string;
118
- } & Mentionable & Contextable & WithDimensions) | ({
264
+ } & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & WithDimensions) | ({
119
265
  video: WAMediaUpload;
120
266
  caption?: string;
121
267
  gifPlayback?: boolean;
122
268
  jpegThumbnail?: string;
123
269
  /** if set to true, will send as a `video note` */
124
270
  ptv?: boolean;
125
- } & Mentionable & Contextable & WithDimensions) | {
271
+ } & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & WithDimensions) | {
126
272
  audio: WAMediaUpload;
127
273
  /** if set to true, will send as a `voice note` */
128
274
  ptt?: boolean;
@@ -136,13 +282,21 @@ export type AnyMediaMessageContent = (({
136
282
  mimetype: string;
137
283
  fileName?: string;
138
284
  caption?: string;
139
- } & Contextable)) & {
285
+ } & Contextable & Buttonable & Templatable & Interactiveable)) & {
140
286
  mimetype?: string;
141
287
  } & Editable;
142
288
  export type ButtonReplyInfo = {
143
- displayText: string;
144
- id: string;
145
- index: number;
289
+ displayText?: string;
290
+ id?: string;
291
+ index?: number;
292
+ title?: string;
293
+ description?: string;
294
+ rowId?: string;
295
+ nativeFlows?: {
296
+ name?: string;
297
+ paramsJson?: string;
298
+ version?: number;
299
+ };
146
300
  };
147
301
  export type GroupInviteInfo = {
148
302
  inviteCode: string;
@@ -157,11 +311,47 @@ export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapsh
157
311
  export type AnyRegularMessageContent = (({
158
312
  text: string;
159
313
  linkPreview?: WAUrlInfo | null;
160
- } & Mentionable & Contextable & Editable) | AnyMediaMessageContent | {
314
+ } & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & Listable & ProductListable & Editable) | AnyMediaMessageContent | {
161
315
  event: EventMessageOptions;
162
316
  } | ({
163
317
  poll: PollMessageOptions;
164
- } & Mentionable & Contextable & Editable) | {
318
+ } & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & Listable & ProductListable & Editable) | {
319
+ pollResult: PollResultOptions;
320
+ } | {
321
+ album: AlbumMessage;
322
+ } | {
323
+ stickerPack: StickerPack;
324
+ } | {
325
+ order: OrderMessage;
326
+ } | {
327
+ payment: PaymentInfo;
328
+ } | {
329
+ paymentInvite: PaymentInviteInfo;
330
+ } | {
331
+ adminInvite: AdminInviteInfo;
332
+ } | {
333
+ shop: ShopInfo;
334
+ title?: string;
335
+ subtitle?: string;
336
+ footer?: string;
337
+ text?: string;
338
+ caption?: string;
339
+ media?: boolean;
340
+ } | {
341
+ collection: CollectionInfo;
342
+ title?: string;
343
+ subtitle?: string;
344
+ footer?: string;
345
+ text?: string;
346
+ caption?: string;
347
+ hasMediaAttachment?: boolean;
348
+ } | {
349
+ cards: Carousel[];
350
+ title?: string;
351
+ subtitle?: string;
352
+ footer?: string;
353
+ text?: string;
354
+ } | {
165
355
  contacts: {
166
356
  displayName?: string;
167
357
  contacts: proto.Message.IContactMessage[];
@@ -172,7 +362,7 @@ export type AnyRegularMessageContent = (({
172
362
  react: proto.Message.IReactionMessage;
173
363
  } | {
174
364
  buttonReply: ButtonReplyInfo;
175
- type: 'template' | 'plain';
365
+ type: 'template' | 'plain' | 'list' | 'interactive';
176
366
  } | {
177
367
  groupInvite: GroupInviteInfo;
178
368
  } | {
@@ -998,44 +998,46 @@ export const generateWAMessageContent = async (message, options) => {
998
998
  };
999
999
  if ('text' in message) {
1000
1000
  interactiveMessage.body = { text: message.text };
1001
+ interactiveMessage.header = {
1002
+ title: message.title,
1003
+ subtitle: message.subtitle,
1004
+ hasMediaAttachment: message?.media ?? false
1005
+ };
1001
1006
  }
1002
1007
  else if ('caption' in message) {
1003
1008
  interactiveMessage.body = { text: message.caption };
1004
1009
  interactiveMessage.header = {
1005
1010
  title: message.title,
1006
1011
  subtitle: message.subtitle,
1007
- hasMediaAttachment: message?.media ?? false,
1012
+ hasMediaAttachment: message?.media ?? false
1008
1013
  };
1009
1014
  Object.assign(interactiveMessage.header, m);
1010
1015
  }
1011
1016
  if ('footer' in message && !!message.footer) {
1012
1017
  interactiveMessage.footer = { text: message.footer };
1013
1018
  }
1014
- if ('title' in message && !!message.title) {
1015
- interactiveMessage.header = {
1016
- title: message.title,
1017
- subtitle: message.subtitle,
1018
- hasMediaAttachment: message?.media ?? false,
1019
- };
1020
- Object.assign(interactiveMessage.header, m);
1021
- }
1022
1019
  if ('contextInfo' in message && !!message.contextInfo) {
1023
1020
  interactiveMessage.contextInfo = message.contextInfo;
1024
1021
  }
1025
1022
  if ('mentions' in message && !!message.mentions) {
1026
- interactiveMessage.contextInfo = { mentionedJid: message.mentions };
1023
+ interactiveMessage.contextInfo = { ...interactiveMessage.contextInfo, mentionedJid: message.mentions };
1027
1024
  }
1028
1025
  m = { interactiveMessage };
1029
1026
  }
1030
1027
  else if ('shop' in message && !!message.shop) {
1031
1028
  const interactiveMessage = {
1032
1029
  shopStorefrontMessage: proto.Message.InteractiveMessage.ShopMessage.fromObject({
1033
- surface: message.shop,
1034
- id: message.id
1030
+ surface: message.shop.surface,
1031
+ id: message.shop.id
1035
1032
  })
1036
1033
  };
1037
1034
  if ('text' in message) {
1038
1035
  interactiveMessage.body = { text: message.text };
1036
+ interactiveMessage.header = {
1037
+ title: message.title,
1038
+ subtitle: message.subtitle,
1039
+ hasMediaAttachment: false
1040
+ };
1039
1041
  }
1040
1042
  else if ('caption' in message) {
1041
1043
  interactiveMessage.body = { text: message.caption };
@@ -1049,13 +1051,12 @@ export const generateWAMessageContent = async (message, options) => {
1049
1051
  if ('footer' in message && !!message.footer) {
1050
1052
  interactiveMessage.footer = { text: message.footer };
1051
1053
  }
1052
- if ('title' in message && !!message.title) {
1054
+ if ('title' in message && !!message.title && !interactiveMessage.header) {
1053
1055
  interactiveMessage.header = {
1054
1056
  title: message.title,
1055
1057
  subtitle: message.subtitle,
1056
- hasMediaAttachment: message?.media ?? false,
1058
+ hasMediaAttachment: message?.media ?? false
1057
1059
  };
1058
- Object.assign(interactiveMessage.header, m);
1059
1060
  }
1060
1061
  if ('contextInfo' in message && !!message.contextInfo) {
1061
1062
  interactiveMessage.contextInfo = message.contextInfo;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ryuhan/baileys",
3
3
  "type": "module",
4
- "version": "2.0.1",
4
+ "version": "2.0.2",
5
5
  "description": "💧 Rimuru Baileys - WhatsApp Multi-Device Library with intelligent @lid/@jid mapping",
6
6
  "keywords": [
7
7
  "whatsapp",