whatsapp-web.js 1.28.0 → 1.29.0

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.
package/example.js CHANGED
@@ -470,6 +470,10 @@ client.on('message', async msg => {
470
470
  console.log(statuses);
471
471
  const chat = await statuses[0]?.getChat(); // Get user chat of a first status
472
472
  console.log(chat);
473
+ } else if (msg.body === '!changeSync') {
474
+ // NOTE: this action will take effect after you restart the client.
475
+ const backgroundSync = await client.setBackgroundSync(true);
476
+ console.log(backgroundSync);
473
477
  }
474
478
  });
475
479
 
package/index.d.ts CHANGED
@@ -24,6 +24,15 @@ declare namespace WAWebJS {
24
24
  /**Accepts an invitation to join a group */
25
25
  acceptInvite(inviteCode: string): Promise<string>
26
26
 
27
+ /** Accepts a channel admin invitation and promotes the current user to a channel admin */
28
+ acceptChannelAdminInvite(channelId: string): Promise<boolean>
29
+
30
+ /** Revokes a channel admin invitation sent to a user by a channel owner */
31
+ revokeChannelAdminInvite(channelId: string, userId: string): Promise<boolean>
32
+
33
+ /** Demotes a channel admin to a regular subscriber (can be used also for self-demotion) */
34
+ demoteChannelAdmin(channelId: string, userId: string): Promise<boolean>
35
+
27
36
  /** Accepts a private invitation to join a group (v4 invite) */
28
37
  acceptGroupV4Invite: (inviteV4: InviteV4Data) => Promise<{status: number}>
29
38
 
@@ -42,6 +51,27 @@ declare namespace WAWebJS {
42
51
  /** Creates a new group */
43
52
  createGroup(title: string, participants?: string | Contact | Contact[] | string[], options?: CreateGroupOptions): Promise<CreateGroupResult|string>
44
53
 
54
+ /** Creates a new channel */
55
+ createChannel(title: string, options?: CreateChannelOptions): Promise<CreateChannelResult | string>
56
+
57
+ /** Deletes the channel you created */
58
+ deleteChannel(channelId: string): Promise<boolean>;
59
+
60
+ /** Subscribe to channel */
61
+ subscribeToChannel(channelId: string): Promise<boolean>
62
+
63
+ /** Unsubscribe from channel */
64
+ unsubscribeFromChannel(channelId: string, options?: UnsubscribeOptions): Promise<boolean>
65
+
66
+ /**
67
+ * Searches for channels based on search criteria, there are some notes:
68
+ * 1. The method finds only channels you are not subscribed to currently
69
+ * 2. If you have never been subscribed to a found channel
70
+ * or you have unsubscribed from it with {@link UnsubscribeOptions.deleteLocalModels} set to 'true',
71
+ * the lastMessage property of a found channel will be 'null'
72
+ */
73
+ searchChannels(searchOptions: SearchChannelsOptions): Promise<Array<Channel> | []>
74
+
45
75
  /** Closes the client */
46
76
  destroy(): Promise<void>
47
77
 
@@ -51,12 +81,18 @@ declare namespace WAWebJS {
51
81
  /** Get all blocked contacts by host account */
52
82
  getBlockedContacts(): Promise<Contact[]>
53
83
 
54
- /** Get chat instance by ID */
84
+ /** Gets chat or channel instance by ID */
55
85
  getChatById(chatId: string): Promise<Chat>
56
86
 
87
+ /** Gets a {@link Channel} instance by invite code */
88
+ getChannelByInviteCode(inviteCode: string): Promise<Channel>
89
+
57
90
  /** Get all current chat instances */
58
91
  getChats(): Promise<Chat[]>
59
92
 
93
+ /** Gets all cached {@link Channel} instances */
94
+ getChannels(): Promise<Channel[]>
95
+
60
96
  /** Get contact instance by ID */
61
97
  getContactById(contactId: string): Promise<Contact>
62
98
 
@@ -116,7 +152,7 @@ declare namespace WAWebJS {
116
152
  * @param chatId ID of the chat that will be muted
117
153
  * @param unmuteDate Date when the chat will be unmuted, leave as is to mute forever
118
154
  */
119
- muteChat(chatId: string, unmuteDate?: Date): Promise<void>
155
+ muteChat(chatId: string, unmuteDate?: Date): Promise<{ isMuted: boolean, muteExpiration: number }>
120
156
 
121
157
  /**
122
158
  * Request authentication via pairing code instead of QR code
@@ -131,6 +167,9 @@ declare namespace WAWebJS {
131
167
 
132
168
  /** Send a message to a specific chatId */
133
169
  sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message>
170
+
171
+ /** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */
172
+ sendChannelAdminInvite(chatId: string, channelId: string, options?: { comment?: string }): Promise<boolean>
134
173
 
135
174
  /** Searches for messages */
136
175
  searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]>
@@ -180,6 +219,13 @@ declare namespace WAWebJS {
180
219
  */
181
220
  setAutoDownloadVideos(flag: boolean): Promise<void>
182
221
 
222
+ /**
223
+ * Changing the background synchronization setting.
224
+ * NOTE: this action will take effect after you restart the client.
225
+ * @param flag true/false on or off
226
+ */
227
+ setBackgroundSync(flag: boolean): Promise<void>
228
+
183
229
  /**
184
230
  * Get user device count by ID
185
231
  * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
@@ -190,12 +236,18 @@ declare namespace WAWebJS {
190
236
 
191
237
  /** Sync history conversation of the Chat */
192
238
  syncHistory(chatId: string): Promise<boolean>
239
+
240
+ /** Save new contact to user's addressbook or edit the existing one */
241
+ saveOrEditAddressbookContact(phoneNumber: string, firstName: string, lastName: string, syncToAddressbook?: boolean): Promise<ChatId>
242
+
243
+ /** Deletes the contact from user's addressbook */
244
+ deleteAddressbookContact(honeNumber: string): Promise<void>
193
245
 
194
246
  /** Changes and returns the archive state of the Chat */
195
247
  unarchiveChat(chatId: string): Promise<boolean>
196
248
 
197
249
  /** Unmutes the Chat */
198
- unmuteChat(chatId: string): Promise<void>
250
+ unmuteChat(chatId: string): Promise<{ isMuted: boolean, muteExpiration: number }>
199
251
 
200
252
  /** Sets the current user's profile picture */
201
253
  setProfilePicture(media: MessageMedia): Promise<boolean>
@@ -204,13 +256,19 @@ declare namespace WAWebJS {
204
256
  deleteProfilePicture(): Promise<boolean>
205
257
 
206
258
  /** Gets an array of membership requests */
207
- getGroupMembershipRequests: (groupId: string) => Promise<Array<GroupMembershipRequest>>
259
+ getGroupMembershipRequests(groupId: string): Promise<Array<GroupMembershipRequest>>
208
260
 
209
261
  /** Approves membership requests if any */
210
- approveGroupMembershipRequests: (groupId: string, options: MembershipRequestActionOptions) => Promise<Array<MembershipRequestActionResult>>;
262
+ approveGroupMembershipRequests(groupId: string, options: MembershipRequestActionOptions): Promise<Array<MembershipRequestActionResult>>;
211
263
 
212
264
  /** Rejects membership requests if any */
213
- rejectGroupMembershipRequests: (groupId: string, options: MembershipRequestActionOptions) => Promise<Array<MembershipRequestActionResult>>;
265
+ rejectGroupMembershipRequests(groupId: string, options: MembershipRequestActionOptions): Promise<Array<MembershipRequestActionResult>>;
266
+
267
+ /**
268
+ * Transfers a channel ownership to another user.
269
+ * Note: the user you are transferring the channel ownership to must be a channel admin.
270
+ */
271
+ transferChannelOwnership(channelId: string, newOwnerId: string, options?: TransferChannelOwnershipOptions): Promise<boolean>;
214
272
 
215
273
  /** Generic event */
216
274
  on(event: string, listener: (...args: any) => void): this
@@ -642,6 +700,46 @@ declare namespace WAWebJS {
642
700
  };
643
701
  }
644
702
 
703
+ /** An object that handles options for channel creation */
704
+ export interface CreateChannelOptions {
705
+ /** The channel description */
706
+ description?: string,
707
+ /** The channel profile picture */
708
+ picture?: MessageMedia
709
+ }
710
+
711
+ /** An object that handles the result for createGroup method */
712
+ export interface CreateChannelResult {
713
+ /** A channel title */
714
+ title: string,
715
+ /** An object that handles the newly created channel ID */
716
+ nid: ChatId,
717
+ /** The channel invite link, starts with 'https://whatsapp.com/channel/' */
718
+ inviteLink: string,
719
+ /** The timestamp the channel was created at */
720
+ createdAtTs: number
721
+ }
722
+
723
+ /** Options for unsubscribe from a channel */
724
+ export interface UnsubscribeOptions {
725
+ /**
726
+ * If true, after an unsubscription, it will completely remove a channel from the channel collection
727
+ * making it seem like the current user have never interacted with it.
728
+ * Otherwise it will only remove a channel from the list of channels the current user is subscribed to
729
+ * and will set the membership type for that channel to GUEST
730
+ */
731
+ deleteLocalModels?: boolean
732
+ }
733
+
734
+ /** Options for searching for channels */
735
+ export interface SearchChannelsOptions {
736
+ searchText?: string;
737
+ countryCodes?: string[];
738
+ skipSubscribedNewsletters?: boolean;
739
+ view?: number;
740
+ limit?: number;
741
+ }
742
+
645
743
  export interface GroupNotification {
646
744
  /** ContactId for the user that produced the GroupNotification */
647
745
  author: string,
@@ -953,7 +1051,7 @@ declare namespace WAWebJS {
953
1051
  /** Accept the Group V4 Invite in message */
954
1052
  acceptGroupV4Invite: () => Promise<{status: number}>,
955
1053
  /** Deletes the message from the chat */
956
- delete: (everyone?: boolean) => Promise<void>,
1054
+ delete: (everyone?: boolean, clearMedia?: boolean) => Promise<void>,
957
1055
  /** Downloads and returns the attached message media */
958
1056
  downloadMedia: () => Promise<MessageMedia>,
959
1057
  /** Returns the Chat this message was sent in */
@@ -1026,7 +1124,10 @@ declare namespace WAWebJS {
1026
1124
  export class Location {
1027
1125
  latitude: string;
1028
1126
  longitude: string;
1029
- options?: LocationSendOptions;
1127
+ name?: string;
1128
+ address?: string;
1129
+ url?: string;
1130
+ description?: string;
1030
1131
 
1031
1132
  constructor(latitude: number, longitude: number, options?: LocationSendOptions)
1032
1133
  }
@@ -1452,11 +1553,11 @@ declare namespace WAWebJS {
1452
1553
  /** Loads chat messages, sorted from earliest to latest. */
1453
1554
  fetchMessages: (searchOptions: MessageSearchOptions) => Promise<Message[]>,
1454
1555
  /** Mutes this chat forever, unless a date is specified */
1455
- mute: (unmuteDate?: Date) => Promise<void>,
1556
+ mute: (unmuteDate?: Date) => Promise<{ isMuted: boolean, muteExpiration: number }>,
1456
1557
  /** Send a message to this chat */
1457
1558
  sendMessage: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
1458
- /** Set the message as seen */
1459
- sendSeen: () => Promise<void>,
1559
+ /** Sets the chat as seen */
1560
+ sendSeen: () => Promise<boolean>,
1460
1561
  /** Simulate recording audio in chat. This will last for 25 seconds */
1461
1562
  sendStateRecording: () => Promise<void>,
1462
1563
  /** Simulate typing in chat. This will last for 25 seconds. */
@@ -1464,7 +1565,7 @@ declare namespace WAWebJS {
1464
1565
  /** un-archives this chat */
1465
1566
  unarchive: () => Promise<void>,
1466
1567
  /** Unmutes this chat */
1467
- unmute: () => Promise<void>,
1568
+ unmute: () => Promise<{ isMuted: boolean, muteExpiration: number }>,
1468
1569
  /** Returns the Contact that corresponds to this Chat. */
1469
1570
  getContact: () => Promise<Contact>,
1470
1571
  /** Marks this Chat as unread */
@@ -1477,6 +1578,99 @@ declare namespace WAWebJS {
1477
1578
  syncHistory: () => Promise<boolean>
1478
1579
  }
1479
1580
 
1581
+ export interface Channel {
1582
+ /** ID that represents the channel */
1583
+ id: {
1584
+ server: string;
1585
+ user: string;
1586
+ _serialized: string;
1587
+ };
1588
+ /** Title of the channel */
1589
+ name: string;
1590
+ /** The channel description */
1591
+ description: string;
1592
+ /** Indicates if it is a Channel */
1593
+ isChannel: boolean;
1594
+ /** Indicates if it is a Group */
1595
+ isGroup: boolean;
1596
+ /** Indicates if the channel is readonly */
1597
+ isReadOnly: boolean;
1598
+ /** Amount of messages unread */
1599
+ unreadCount: number;
1600
+ /** Unix timestamp for when the last activity occurred */
1601
+ timestamp: number;
1602
+ /** Indicates if the channel is muted or not */
1603
+ isMuted: boolean;
1604
+ /** Unix timestamp for when the mute expires */
1605
+ muteExpiration: number;
1606
+ /** Last message in the channel */
1607
+ lastMessage: Message | undefined;
1608
+
1609
+ /** Gets the subscribers of the channel (only those who are in your contact list) */
1610
+ getSubscribers(limit?: number): Promise<{contact: Contact, role: string}[]>;
1611
+ /** Updates the channel subject */
1612
+ setSubject(newSubject: string): Promise<boolean>;
1613
+ /** Updates the channel description */
1614
+ setDescription(newDescription: string): Promise<boolean>;
1615
+ /** Updates the channel profile picture */
1616
+ setProfilePicture(newProfilePicture: MessageMedia): Promise<boolean>;
1617
+ /**
1618
+ * Updates available reactions to use in the channel
1619
+ *
1620
+ * Valid values for passing to the method are:
1621
+ * 0 for NONE reactions to be avaliable
1622
+ * 1 for BASIC reactions to be available: 👍, ❤️, 😂, 😮, 😢, 🙏
1623
+ * 2 for ALL reactions to be available
1624
+ */
1625
+ setReactionSetting(reactionCode: number): Promise<boolean>;
1626
+ /** Mutes the channel */
1627
+ mute(): Promise<boolean>;
1628
+ /** Unmutes the channel */
1629
+ unmute(): Promise<boolean>;
1630
+ /** Sends a message to this channel */
1631
+ sendMessage(content: string|MessageMedia, options?: MessageSendChannelOptions): Promise<Message>;
1632
+ /** Sets the channel as seen */
1633
+ sendSeen(): Promise<boolean>;
1634
+ /** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */
1635
+ sendChannelAdminInvite(chatId: string, options?: { comment?: string }): Promise<boolean>;
1636
+ /** Accepts a channel admin invitation and promotes the current user to a channel admin */
1637
+ acceptChannelAdminInvite(): Promise<boolean>;
1638
+ /** Revokes a channel admin invitation sent to a user by a channel owner */
1639
+ revokeChannelAdminInvite(userId: string): Promise<boolean>;
1640
+ /** Demotes a channel admin to a regular subscriber (can be used also for self-demotion) */
1641
+ demoteChannelAdmin(userId: string): Promise<boolean>;
1642
+ /** Loads channel messages, sorted from earliest to latest */
1643
+ fetchMessages: (searchOptions: MessageSearchOptions) => Promise<Message[]>;
1644
+ /**
1645
+ * Transfers a channel ownership to another user.
1646
+ * Note: the user you are transferring the channel ownership to must be a channel admin.
1647
+ */
1648
+ transferChannelOwnership(newOwnerId: string, options?: TransferChannelOwnershipOptions): Promise<boolean>;
1649
+ /** Deletes the channel you created */
1650
+ deleteChannel(): Promise<boolean>;
1651
+ }
1652
+
1653
+ /** Options for transferring a channel ownership to another user */
1654
+ export interface TransferChannelOwnershipOptions {
1655
+ /**
1656
+ * If true, after the channel ownership is being transferred to another user,
1657
+ * the current user will be dismissed as a channel admin and will become to a channel subscriber.
1658
+ */
1659
+ shouldDismissSelfAsAdmin?: boolean
1660
+ }
1661
+
1662
+ /** Options for sending a message */
1663
+ export interface MessageSendChannelOptions {
1664
+ /** Image or videos caption */
1665
+ caption?: string
1666
+ /** User IDs of user that will be mentioned in the message */
1667
+ mentions?: string[]
1668
+ /** Image or video to be sent */
1669
+ media?: MessageMedia
1670
+ /** Extra options */
1671
+ extra?: any
1672
+ }
1673
+
1480
1674
  export interface MessageSearchOptions {
1481
1675
  /**
1482
1676
  * The amount of messages to return. If no limit is specified, the available messages will be returned.
package/index.js CHANGED
@@ -11,6 +11,7 @@ module.exports = {
11
11
  Chat: require('./src/structures/Chat'),
12
12
  PrivateChat: require('./src/structures/PrivateChat'),
13
13
  GroupChat: require('./src/structures/GroupChat'),
14
+ Channel: require('./src/structures/Channel'),
14
15
  Message: require('./src/structures/Message'),
15
16
  MessageMedia: require('./src/structures/MessageMedia'),
16
17
  Contact: require('./src/structures/Contact'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.28.0",
3
+ "version": "1.29.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",