forked from WhiskeySockets/Baileys
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMessage.ts
More file actions
1053 lines (976 loc) · 26.1 KB
/
Message.ts
File metadata and controls
1053 lines (976 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { Readable } from 'stream'
import type { URL } from 'url'
import { proto } from '../../WAProto/index.js'
import type { MediaType } from '../Defaults'
import type { BinaryNode } from '../WABinary'
import type { GroupMetadata } from './GroupMetadata'
import type { CacheStore } from './Socket'
// export the WAMessage Prototypes
export { proto as WAProto }
export type WAMessage = proto.IWebMessageInfo & {
key: WAMessageKey
messageStubParameters?: any
category?: string
retryCount?: number
}
export type WAMessageContent = proto.IMessage
export type WAContactMessage = proto.Message.IContactMessage
export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage
export type WAMessageKey = proto.IMessageKey & {
remoteJidAlt?: string
remoteJidUsername?: string
participantAlt?: string
participantUsername?: string
server_id?: string
addressingMode?: string
isViewOnce?: boolean // TODO: remove out of the message key, place in WebMessageInfo
}
/** Metadata cached for CTWA placeholder resend to preserve original message details */
export type PlaceholderMessageData = {
key: WAMessageKey
pushName?: string | null
messageTimestamp?: WAMessage['messageTimestamp']
participant?: string | null
participantAlt?: string | null
}
export type WATextMessage = proto.Message.IExtendedTextMessage
export type WAContextInfo = proto.IContextInfo
export type WALocationMessage = proto.Message.ILocationMessage
export type WAGenericMediaMessage =
| proto.Message.IVideoMessage
| proto.Message.IImageMessage
| proto.Message.IAudioMessage
| proto.Message.IDocumentMessage
| proto.Message.IStickerMessage
export const WAMessageStubType = proto.WebMessageInfo.StubType
export const WAMessageStatus = proto.WebMessageInfo.Status
import type { ILogger } from '../Utils/logger'
export type WAMediaPayloadURL = { url: URL | string }
export type WAMediaPayloadStream = { stream: Readable }
export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL
/**
* Individual sticker in a sticker pack
*/
export type Sticker = {
/** Buffer, Stream or URL of the sticker image (WebP or Lottie/WAS format) */
data: WAMediaUpload
/** Array of emojis associated with this sticker (max 3 recommended per WhatsApp standards) */
emojis?: string[]
/** Accessibility label for screen readers (max 125 chars for static, 255 for animated) */
accessibilityLabel?: string
/** Force Lottie format detection (auto-detected if omitted) */
isLottie?: boolean
}
/**
* Sticker Pack message - send a complete pack of stickers
*
* Follows WhatsApp official specifications:
* - 3-30 stickers per pack (enforced)
* - WebP format (auto-converted)
* - Max 100KB per static sticker, 500KB per animated (recommended, not enforced)
* - Either all static OR all animated (recommended)
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* stickerPack: {
* name: 'My Awesome Pack',
* publisher: 'Your Name',
* description: 'Cool stickers collection',
* cover: Buffer.from(...), // or URL or Stream
* stickers: [
* { data: Buffer.from(...), emojis: ['😀', '😃'] },
* { data: 'https://example.com/sticker.webp', emojis: ['😎'] }
* ]
* }
* })
* ```
*/
export type StickerPack = {
/** Array of stickers (minimum 3, maximum 30 per WhatsApp official spec) */
stickers: Sticker[]
/** Cover/tray icon for the pack (will be auto-resized to 252x252 JPEG) */
cover: WAMediaUpload
/** Pack name (max 128 characters) */
name: string
/** Publisher/author name (max 128 characters) */
publisher: string
/** Optional pack description */
description?: string
/** Optional custom pack ID (auto-generated if omitted) */
packId?: string
}
/** Set of message types that are supported by the library */
export type MessageType = keyof proto.Message
export enum WAMessageAddressingMode {
PN = 'pn',
LID = 'lid'
}
export type MessageWithContextInfo =
| 'imageMessage'
| 'contactMessage'
| 'locationMessage'
| 'extendedTextMessage'
| 'documentMessage'
| 'audioMessage'
| 'videoMessage'
| 'call'
| 'contactsArrayMessage'
| 'liveLocationMessage'
| 'templateMessage'
| 'stickerMessage'
| 'groupInviteMessage'
| 'templateButtonReplyMessage'
| 'productMessage'
| 'listMessage'
| 'orderMessage'
| 'listResponseMessage'
| 'buttonsMessage'
| 'buttonsResponseMessage'
| 'interactiveMessage'
| 'interactiveResponseMessage'
| 'pollCreationMessage'
| 'requestPhoneNumberMessage'
| 'messageHistoryBundle'
| 'eventMessage'
| 'newsletterAdminInviteMessage'
| 'albumMessage'
| 'stickerPackMessage'
| 'pollResultSnapshotMessage'
| 'messageHistoryNotice'
export type DownloadableMessage = { mediaKey?: Uint8Array | null; directPath?: string | null; url?: string | null }
export type MessageReceiptType =
| 'read'
| 'read-self'
| 'hist_sync'
| 'peer_msg'
| 'sender'
| 'inactive'
| 'played'
| 'view_once_read'
| undefined
export type MediaConnInfo = {
auth: string
ttl: number
hosts: { hostname: string; maxContentLengthBytes: number }[]
fetchDate: Date
}
export interface WAUrlInfo {
'canonical-url': string
'matched-text': string
title: string
description?: string
jpegThumbnail?: Buffer
highQualityThumbnail?: proto.Message.IImageMessage
originalThumbnailUrl?: string
}
// types to generate WA messages
type Mentionable = {
/** list of jids that are mentioned in the accompanying text */
mentions?: string[]
/** mention all participants in the group */
mentionAll?: boolean
}
type Contextable = {
/** add contextInfo to the message */
contextInfo?: proto.IContextInfo
}
type ViewOnce = {
viewOnce?: boolean
}
type Editable = {
edit?: WAMessageKey
}
type WithDimensions = {
width?: number
height?: number
}
export type PollMessageOptions = {
name: string
selectableCount?: number
values: string[]
/** 32 byte message secret to encrypt poll selections */
messageSecret?: Uint8Array
toAnnouncementGroup?: boolean
}
export type EventMessageOptions = {
name: string
description?: string
startDate: Date
endDate?: Date
location?: WALocationMessage
call?: 'audio' | 'video'
isCancelled?: boolean
isScheduleCall?: boolean
extraGuestsAllowed?: boolean
messageSecret?: Uint8Array<ArrayBufferLike>
}
type SharePhoneNumber = {
sharePhoneNumber: boolean
}
type RequestPhoneNumber = {
requestPhoneNumber: boolean
}
export type AnyMediaMessageContent = (
| ({
image: WAMediaUpload
caption?: string
jpegThumbnail?: string
} & Mentionable &
Contextable &
WithDimensions)
| ({
video: WAMediaUpload
caption?: string
gifPlayback?: boolean
jpegThumbnail?: string
/** if set to true, will send as a `video note` */
ptv?: boolean
} & Mentionable &
Contextable &
WithDimensions)
| {
audio: WAMediaUpload
/** if set to true, will send as a `voice note` */
ptt?: boolean
/** optionally tell the duration of the audio */
seconds?: number
}
| ({
sticker: WAMediaUpload
isAnimated?: boolean
} & WithDimensions)
| ({
document: WAMediaUpload
mimetype: string
fileName?: string
caption?: string
} & Contextable)
) & { mimetype?: string } & Editable &
Partial<Buttonable> &
Partial<Templatable>
export type ButtonReplyInfo = {
displayText: string
id: string
index: number
}
export type GroupInviteInfo = {
inviteCode: string
inviteExpiration: number
text: string
jid: string
subject: string
}
export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
productImage: WAMediaUpload
}
// Interactive message types
export type ButtonInfo = {
buttonId: string
buttonText: { displayText: string }
type?: proto.Message.ButtonsMessage.Button.Type
}
export type Buttonable = {
buttons: ButtonInfo[]
headerType?: proto.Message.ButtonsMessage.HeaderType
footerText?: string
}
export type TemplateButton =
| { index: number; quickReplyButton: { displayText: string; id: string } }
| { index: number; urlButton: { displayText: string; url: string } }
| { index: number; callButton: { displayText: string; phoneNumber: string } }
export type Templatable = {
templateButtons: TemplateButton[]
footer?: string
}
export type ListSection = {
title: string
rows: Array<{
rowId: string
title: string
description?: string
}>
}
export type Listable = {
sections: ListSection[]
title?: string
buttonText?: string
}
// ========== Native Flow Button Types ==========
/**
* Button types supported by WhatsApp Native Flow
* - cta_url: Opens a URL
* - cta_copy: Copies text to clipboard
* - cta_call: Initiates a phone call
* - quick_reply: Sends a quick reply with ID
* - single_select: Opens a list selection
*/
export type NativeFlowButtonType = 'cta_url' | 'cta_copy' | 'cta_call' | 'quick_reply' | 'single_select'
/**
* URL button - opens a link when clicked
*/
export type UrlButton = {
type: 'url'
text: string
url: string
/** Optional merchant URL for tracking */
merchantUrl?: string
}
/**
* Copy button - copies text to clipboard when clicked
*/
export type CopyButton = {
type: 'copy'
text: string
copyText: string
}
/**
* Quick reply button - sends a reply with an ID
*/
export type QuickReplyButton = {
type: 'reply'
text: string
id: string
}
/**
* Call button - initiates a phone call when clicked
*/
export type CallButton = {
type: 'call'
text: string
phoneNumber: string
}
/**
* Union type for all button types
*/
export type NativeButton = UrlButton | CopyButton | QuickReplyButton | CallButton
/**
* Formatted button for Native Flow (internal use)
*/
export type NativeFlowButton = {
name: string
buttonParamsJson: string
}
/**
* Row item in a list section
*/
export type ListRow = {
/** Unique ID returned when selected */
id: string
/** Display title */
title: string
/** Optional description */
description?: string
}
/**
* Section in a native list message (uses ListRow with id)
*/
export type NativeListSection = {
/** Section title */
title: string
/** Rows in this section */
rows: ListRow[]
}
/**
* Options for generating a list message
*/
export type ListMessageOptions = {
/** Button text to open the list */
buttonText: string
/** Sections with selectable items */
sections: NativeListSection[]
/** Main text/body of the message */
text: string
/** Title shown in header */
title?: string
/** Footer text */
footer?: string
}
/**
* Options for generating a button message
*/
export type ButtonMessageOptions = {
/** Array of buttons (2-3 recommended) */
buttons: NativeButton[]
/** Main text/body of the message */
text: string
/** Footer text (optional) */
footer?: string
/** Header title (optional, used if no media) */
headerTitle?: string
/** Header image (optional) */
headerImage?: WAMediaUpload
/** Header video (optional) */
headerVideo?: WAMediaUpload
/** Message version (default: 2) */
messageVersion?: number
}
/**
* Single card in a carousel message
*/
export type CarouselCardInput = {
/** Card title in header */
title: string
/** Card body text */
body: string
/** Card footer text (optional) */
footer?: string
/** Card image (optional) */
image?: WAMediaUpload
/** Card video (optional) */
video?: WAMediaUpload
/** Buttons for this card */
buttons: NativeButton[]
}
/**
* Options for generating a carousel message
*/
export type CarouselMessageOptions = {
/** Cards in the carousel (2-10 recommended) */
cards: CarouselCardInput[]
/** Header title (displayed once above the carousel) */
title?: string
/** Main body text */
text?: string
/** Footer text */
footer?: string
}
export type CarouselCard = {
header: {
title: string
imageMessage?: {
url: string
mimetype: string
}
videoMessage?: {
url: string
mimetype: string
}
hasMediaAttachment: boolean
}
body: { text: string }
footer?: { text: string }
nativeFlowMessage?: {
buttons: Array<{
name: string
buttonParamsJson: string
}>
}
}
export type Carouselable = {
carousel: {
cards: CarouselCard[]
messageVersion?: number
}
}
// ========== Product List Message Types ==========
/**
* Product reference in a product list
* Uses the product ID from the WhatsApp Business catalog
*/
export type ProductItem = {
/** Product ID from the catalog */
productId: string
}
/**
* Section containing products in a product list message
*/
export type ProductSection = {
/** Section title */
title: string
/** Products in this section */
products: ProductItem[]
}
/**
* Header image configuration for product list
* Can reference a product's image from the catalog
*/
export type ProductListHeaderImage = {
/** Product ID whose image to use as header */
productId: string
/** Optional JPEG thumbnail */
jpegThumbnail?: Buffer
}
/**
* Options for generating a product list message (multi-product)
* Allows sending multiple products from the catalog in a single message
*
* @example
* ```typescript
* const msg = generateProductListMessage({
* title: 'Our Best Sellers',
* description: 'Check out our most popular products!',
* buttonText: 'View Products',
* footerText: 'Tap to browse',
* businessOwnerJid: '5511999999999@s.whatsapp.net',
* productSections: [
* {
* title: 'Electronics',
* products: [
* { productId: 'prod_001' },
* { productId: 'prod_002' }
* ]
* },
* {
* title: 'Accessories',
* products: [
* { productId: 'prod_003' }
* ]
* }
* ],
* headerImage: { productId: 'prod_001' }
* })
* await sock.sendMessage(jid, msg)
* ```
*/
export type ProductListMessageOptions = {
/** Message title */
title: string
/** Message description/body text */
description: string
/** Button text to open the product list */
buttonText: string
/** Footer text (optional) */
footerText?: string
/** Business owner JID (the catalog owner) */
businessOwnerJid: string
/** Sections with products */
productSections: ProductSection[]
/** Header image configuration (optional) */
headerImage?: ProductListHeaderImage
}
// ========== Album Message Types ==========
/**
* Single media item in an album (image or video)
* Each item can have its own caption, thumbnail, and metadata
*/
export type AlbumMediaItem =
| ({
image: WAMediaUpload
caption?: string
jpegThumbnail?: string
} & Mentionable &
Contextable &
WithDimensions)
| ({
video: WAMediaUpload
caption?: string
gifPlayback?: boolean
jpegThumbnail?: string
/** Duration in seconds */
seconds?: number
} & Mentionable &
Contextable &
WithDimensions)
/**
* Configuration for album message sending
*/
export type AlbumMessageOptions = {
/** Array of media items (images/videos) - min 2, max 10 */
medias: AlbumMediaItem[]
/**
* Delay strategy between media sends
* - 'adaptive': Calculates delay based on media type (videos get 2x delay),
* position in album, and random jitter (recommended)
* - number: Fixed delay in milliseconds
* @default 'adaptive'
*/
delay?: 'adaptive' | number
/**
* Number of retry attempts for failed media items
* @default 3
*/
retryCount?: number
/**
* Whether to continue sending remaining items if one fails
* @default true
*/
continueOnFailure?: boolean
}
/**
* Result of a single media item send attempt
*/
export type AlbumMediaResult = {
/** Index in the original medias array */
index: number
/** Whether this item was sent successfully */
success: boolean
/** The sent message (if successful) */
message?: WAMessage
/** Error details (if failed) */
error?: Error
/** Total number of attempts made (1 = success on first try, >1 = retries occurred) */
retryAttempts: number
/** Time taken to send this item in ms */
latencyMs: number
}
/**
* Complete result of album message sending
*/
export type AlbumSendResult = {
/** Key of the album root message */
albumKey: WAMessageKey
/** Results for each media item */
results: AlbumMediaResult[]
/** Total number of items in the album */
totalItems: number
/** Number of items that were actually attempted (may be < totalItems if stoppedEarly) */
attemptedItems: number
/** Number of successfully sent items */
successCount: number
/** Number of failed items */
failedCount: number
/** Indices of failed items (for potential retry) */
failedIndices: number[]
/** Overall success (all items sent) */
success: boolean
/** Whether the send was interrupted early due to continueOnFailure=false */
stoppedEarly: boolean
/** Total time taken in ms */
totalLatencyMs: number
}
// ========== Product Carousel Message Types ==========
/**
* Single product card in a product carousel
* References a product from WhatsApp Business catalog
*/
export type ProductCarouselCard = {
/** Product retailer ID from the catalog */
productId: string
}
/**
* Options for generating a product carousel message
* Uses products from WhatsApp Business catalog
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* productCarousel: {
* businessOwnerJid: '5511999999999@s.whatsapp.net',
* products: [
* { productId: 'iphone_15' },
* { productId: 'macbook_air' },
* { productId: 'apple_watch' }
* ]
* },
* body: 'Check out our featured products!'
* })
* ```
*/
export type ProductCarouselMessageOptions = {
/** JID of the business owner (who owns the catalog) */
businessOwnerJid: string
/** Products to display (2-10 cards required) */
products: ProductCarouselCard[]
/** Body text for the message */
body?: string
}
export type AnyRegularMessageContent = (
| ({
text: string
linkPreview?: WAUrlInfo | null
} & Mentionable &
Contextable &
Editable &
Partial<Buttonable> &
Partial<Templatable> &
Partial<Listable> &
Partial<Carouselable>)
| AnyMediaMessageContent
| { event: EventMessageOptions }
| ({
poll: PollMessageOptions
} & Mentionable &
Contextable &
Editable)
| {
contacts: {
displayName?: string
contacts: proto.Message.IContactMessage[]
}
}
| {
location: WALocationMessage
}
| { react: proto.Message.IReactionMessage }
| {
buttonReply: ButtonReplyInfo
type: 'template' | 'plain'
}
| {
groupInvite: GroupInviteInfo
}
| {
listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>
}
| {
pin: WAMessageKey
type: proto.PinInChat.Type
/**
* 24 hours, 7 days, 30 days
*/
time?: 86400 | 604800 | 2592000
}
| {
product: WASendableProduct
businessOwnerJid?: string
body?: string
footer?: string
}
| {
/**
* Native Flow Buttons - Modern button message format
* Works reliably on iOS and Android with viewOnceMessage wrapper
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* text: 'Choose an option:',
* nativeButtons: [
* { type: 'url', text: 'Visit Site', url: 'https://example.com' },
* { type: 'copy', text: 'Copy Code', copyText: 'ABC123' },
* { type: 'reply', text: 'Contact Us', id: 'btn_contact' }
* ],
* footer: 'Powered by InfiniteAPI'
* })
* ```
*/
nativeButtons: NativeButton[]
text?: string
footer?: string
headerTitle?: string
headerImage?: WAMediaUpload
headerVideo?: WAMediaUpload
}
| {
/**
* Native Carousel Message - Multiple swipeable cards with buttons
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* text: 'Our Products',
* nativeCarousel: {
* cards: [
* { title: 'Item 1', body: 'Description', buttons: [...] },
* { title: 'Item 2', body: 'Description', buttons: [...] }
* ]
* },
* footer: 'Swipe for more'
* })
* ```
*/
nativeCarousel: {
cards: CarouselCardInput[]
}
text?: string
footer?: string
}
| {
/**
* Product Carousel Message - Swipeable product cards from WhatsApp Business catalog
* Requires: WhatsApp Business account with configured catalog
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* productCarousel: {
* businessOwnerJid: '5511999999999@s.whatsapp.net',
* products: [
* { productId: 'produto_001' },
* { productId: 'produto_002' },
* { productId: 'produto_003' }
* ]
* },
* body: 'Confira nossos produtos em destaque!'
* })
* ```
*/
productCarousel: ProductCarouselMessageOptions
body?: string
}
| {
/**
* Native List Message - Interactive list with sections
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* text: 'Choose an option:',
* title: 'Menu',
* nativeList: {
* buttonText: 'View Options',
* sections: [
* {
* title: 'Category 1',
* rows: [
* { id: 'opt1', title: 'Option 1', description: 'Desc' },
* { id: 'opt2', title: 'Option 2' }
* ]
* }
* ]
* },
* footer: 'Select one'
* })
* ```
*/
nativeList: {
buttonText: string
sections: NativeListSection[]
}
text?: string
title?: string
footer?: string
}
| {
/**
* Album message - send multiple images/videos grouped together
* ⚠️ WARNING: Do NOT use with sendMessage() - use sendAlbumMessage() instead!
* sendMessage only relays the root message and won't send individual media items
* @internal Used internally by generateWAMessage
*/
album: AlbumMessageOptions
}
| {
/**
* Sticker Pack - Send a complete pack of stickers (3-30 stickers)
*
* The pack will appear in the recipient's sticker tray, similar to official sticker packs.
* All stickers are automatically converted to WebP format if needed.
*
* @example
* ```typescript
* import { readFileSync } from 'fs'
*
* await sock.sendMessage(jid, {
* stickerPack: {
* name: 'Emoji Pack',
* publisher: 'InfiniteAPI',
* description: 'Fun emoji stickers',
* cover: readFileSync('./pack-cover.png'),
* stickers: [
* { data: readFileSync('./sticker1.webp'), emojis: ['😀'] },
* { data: readFileSync('./sticker2.png'), emojis: ['😎', '🔥'] },
* { data: { url: 'https://example.com/sticker3.webp' }, emojis: ['🎉'] }
* ]
* }
* })
* ```
*
* **Requirements:**
* - `fflate` package (installed automatically)
* - `sharp` package for image processing: `yarn add sharp`
*
* **Specifications (WhatsApp Official):**
* - Minimum 3 stickers, maximum 30 per pack
* - Recommended: 100KB per static sticker, 500KB per animated
* - WebP format (auto-converted from PNG/JPG/etc)
* - Best practice: All stickers either static OR animated, not mixed
*/
stickerPack: StickerPack
}
| SharePhoneNumber
| RequestPhoneNumber
) &
ViewOnce
export type AnyMessageContent =
| AnyRegularMessageContent
| {
forward: WAMessage
force?: boolean
}
| {
/** Delete your message or anyone's message in a group (admin required) */
delete: WAMessageKey
}
| {
disappearingMessagesInChat: boolean | number
}
| {
limitSharing: boolean
}
export type GroupMetadataParticipants = Pick<GroupMetadata, 'participants'>
type MinimalRelayOptions = {
/** override the message ID with a custom provided string */
messageId?: string
/** should we use group metadata cache, or fetch afresh from the server; default assumed to be "true" */
useCachedGroupMetadata?: boolean
}
export type MessageRelayOptions = MinimalRelayOptions & {
/** only send to a specific participant; used when a message decryption fails for a single user */
participant?: { jid: string; count: number }
/** additional attributes to add to the WA binary node */
additionalAttributes?: { [_: string]: string }
additionalNodes?: BinaryNode[]
/** should we use the devices cache, or fetch afresh from the server; default assumed to be "true" */
useUserDevicesCache?: boolean
/** jid list of participants for status@broadcast */
statusJidList?: string[]
}
export type MiscMessageGenerationOptions = MinimalRelayOptions & {
/** optional, if you want to manually set the timestamp of the message */
timestamp?: Date
/** the message you want to quote */
quoted?: WAMessage
/** disappearing messages settings */
ephemeralExpiration?: number | string
/** timeout for media upload to WA server */
mediaUploadTimeoutMs?: number
/** jid list of participants for status@broadcast */
statusJidList?: string[]
/** backgroundcolor for status */
backgroundColor?: string
/** font type for status */
font?: number
/** if it is broadcast */
broadcast?: boolean
}
export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
userJid: string
}
export type WAMediaUploadFunction = (
encFilePath: string,
opts: { fileEncSha256B64: string; mediaType: MediaType; timeoutMs?: number; newsletter?: boolean }
) => Promise<{
mediaUrl: string | undefined