whatsapp-web.js 1.28.1-alpha.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/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
 
@@ -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[]>
@@ -217,13 +256,19 @@ declare namespace WAWebJS {
217
256
  deleteProfilePicture(): Promise<boolean>
218
257
 
219
258
  /** Gets an array of membership requests */
220
- getGroupMembershipRequests: (groupId: string) => Promise<Array<GroupMembershipRequest>>
259
+ getGroupMembershipRequests(groupId: string): Promise<Array<GroupMembershipRequest>>
221
260
 
222
261
  /** Approves membership requests if any */
223
- approveGroupMembershipRequests: (groupId: string, options: MembershipRequestActionOptions) => Promise<Array<MembershipRequestActionResult>>;
262
+ approveGroupMembershipRequests(groupId: string, options: MembershipRequestActionOptions): Promise<Array<MembershipRequestActionResult>>;
224
263
 
225
264
  /** Rejects membership requests if any */
226
- 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>;
227
272
 
228
273
  /** Generic event */
229
274
  on(event: string, listener: (...args: any) => void): this
@@ -655,6 +700,46 @@ declare namespace WAWebJS {
655
700
  };
656
701
  }
657
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
+
658
743
  export interface GroupNotification {
659
744
  /** ContactId for the user that produced the GroupNotification */
660
745
  author: string,
@@ -1471,8 +1556,8 @@ declare namespace WAWebJS {
1471
1556
  mute: (unmuteDate?: Date) => Promise<{ isMuted: boolean, muteExpiration: number }>,
1472
1557
  /** Send a message to this chat */
1473
1558
  sendMessage: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
1474
- /** Set the chat as seen */
1475
- sendSeen: () => Promise<void>,
1559
+ /** Sets the chat as seen */
1560
+ sendSeen: () => Promise<boolean>,
1476
1561
  /** Simulate recording audio in chat. This will last for 25 seconds */
1477
1562
  sendStateRecording: () => Promise<void>,
1478
1563
  /** Simulate typing in chat. This will last for 25 seconds. */
@@ -1493,6 +1578,99 @@ declare namespace WAWebJS {
1493
1578
  syncHistory: () => Promise<boolean>
1494
1579
  }
1495
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
+
1496
1674
  export interface MessageSearchOptions {
1497
1675
  /**
1498
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.1-alpha.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",