whatsapp-web.js 1.16.6 → 1.17.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.
- package/README.md +2 -1
- package/example.js +3 -1
- package/index.d.ts +10 -6
- package/package.json +1 -1
- package/src/Client.js +17 -10
- package/src/structures/Chat.js +3 -3
- package/src/structures/GroupChat.js +1 -1
- package/src/structures/Message.js +12 -0
- package/src/structures/index.js +1 -1
- package/src/util/Injected.js +5 -4
- package/src/util/Util.js +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765)  [](https://discord.gg/H7DqQs4)
|
|
2
2
|
|
|
3
3
|
# whatsapp-web.js
|
|
4
4
|
A WhatsApp API client that connects through the WhatsApp Web browser app
|
|
@@ -80,6 +80,7 @@ For more information on saving and restoring sessions, check out the available [
|
|
|
80
80
|
| Get contact info | ✅ |
|
|
81
81
|
| Get profile pictures | ✅ |
|
|
82
82
|
| Set user status message | ✅ |
|
|
83
|
+
| React to messages | ✅ |
|
|
83
84
|
|
|
84
85
|
Something missing? Make an issue and let us know!
|
|
85
86
|
|
package/example.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Client, Location, List, Buttons, LocalAuth
|
|
1
|
+
const { Client, Location, List, Buttons, LocalAuth} = require('./index');
|
|
2
2
|
|
|
3
3
|
const client = new Client({
|
|
4
4
|
authStrategy: new LocalAuth(),
|
|
@@ -191,6 +191,8 @@ client.on('message', async msg => {
|
|
|
191
191
|
let sections = [{title:'sectionTitle',rows:[{title:'ListItem1', description: 'desc'},{title:'ListItem2'}]}];
|
|
192
192
|
let list = new List('List body','btnText',sections,'Title','footer');
|
|
193
193
|
client.sendMessage(msg.from, list);
|
|
194
|
+
} else if (msg.body === '!reaction') {
|
|
195
|
+
msg.react('👍');
|
|
194
196
|
}
|
|
195
197
|
});
|
|
196
198
|
|
package/index.d.ts
CHANGED
|
@@ -114,7 +114,7 @@ declare namespace WAWebJS {
|
|
|
114
114
|
|
|
115
115
|
/** Send a message to a specific chatId */
|
|
116
116
|
sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message>
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
/** Searches for messages */
|
|
119
119
|
searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]>
|
|
120
120
|
|
|
@@ -141,7 +141,7 @@ declare namespace WAWebJS {
|
|
|
141
141
|
* @param displayName New display name
|
|
142
142
|
*/
|
|
143
143
|
setDisplayName(displayName: string): Promise<boolean>
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
/** Changes and returns the archive state of the Chat */
|
|
146
146
|
unarchiveChat(chatId: string): Promise<boolean>
|
|
147
147
|
|
|
@@ -604,6 +604,8 @@ declare namespace WAWebJS {
|
|
|
604
604
|
ack: MessageAck,
|
|
605
605
|
/** If the message was sent to a group, this field will contain the user that sent the message. */
|
|
606
606
|
author?: string,
|
|
607
|
+
/** String that represents from which device type the message was sent */
|
|
608
|
+
deviceType: string,
|
|
607
609
|
/** Message content */
|
|
608
610
|
body: string,
|
|
609
611
|
/** Indicates if the message was a broadcast */
|
|
@@ -687,7 +689,7 @@ declare namespace WAWebJS {
|
|
|
687
689
|
acceptGroupV4Invite: () => Promise<{status: number}>,
|
|
688
690
|
/** Deletes the message from the chat */
|
|
689
691
|
delete: (everyone?: boolean) => Promise<void>,
|
|
690
|
-
/** Downloads and returns the
|
|
692
|
+
/** Downloads and returns the attached message media */
|
|
691
693
|
downloadMedia: () => Promise<MessageMedia>,
|
|
692
694
|
/** Returns the Chat this message was sent in */
|
|
693
695
|
getChat: () => Promise<Chat>,
|
|
@@ -703,6 +705,8 @@ declare namespace WAWebJS {
|
|
|
703
705
|
* If not, it will send the message in the same Chat as the original message was sent.
|
|
704
706
|
*/
|
|
705
707
|
reply: (content: MessageContent, chatId?: string, options?: MessageSendOptions) => Promise<Message>,
|
|
708
|
+
/** React to this message with an emoji*/
|
|
709
|
+
react: (reaction: string) => Promise<void>,
|
|
706
710
|
/**
|
|
707
711
|
* Forwards this message to another chat
|
|
708
712
|
*/
|
|
@@ -711,7 +715,7 @@ declare namespace WAWebJS {
|
|
|
711
715
|
star: () => Promise<void>,
|
|
712
716
|
/** Unstar this message */
|
|
713
717
|
unstar: () => Promise<void>,
|
|
714
|
-
/** Get information about message delivery
|
|
718
|
+
/** Get information about message delivery status */
|
|
715
719
|
getInfo: () => Promise<MessageInfo | null>,
|
|
716
720
|
/**
|
|
717
721
|
* Gets the order associated with a given message
|
|
@@ -816,7 +820,7 @@ declare namespace WAWebJS {
|
|
|
816
820
|
static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia>
|
|
817
821
|
}
|
|
818
822
|
|
|
819
|
-
export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons
|
|
823
|
+
export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons
|
|
820
824
|
|
|
821
825
|
/**
|
|
822
826
|
* Represents a Contact on WhatsApp
|
|
@@ -1287,7 +1291,7 @@ declare namespace WAWebJS {
|
|
|
1287
1291
|
constructor(body: string, buttonText: string, sections: Array<any>, title?: string | null, footer?: string | null)
|
|
1288
1292
|
}
|
|
1289
1293
|
|
|
1290
|
-
/** Message type
|
|
1294
|
+
/** Message type Buttons */
|
|
1291
1295
|
export class Buttons {
|
|
1292
1296
|
body: string | MessageMedia
|
|
1293
1297
|
buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }>
|
package/package.json
CHANGED
package/src/Client.js
CHANGED
|
@@ -10,7 +10,7 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constan
|
|
|
10
10
|
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
|
11
11
|
const ChatFactory = require('./factories/ChatFactory');
|
|
12
12
|
const ContactFactory = require('./factories/ContactFactory');
|
|
13
|
-
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List
|
|
13
|
+
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List} = require('./structures');
|
|
14
14
|
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
|
|
15
15
|
const NoAuth = require('./authStrategies/NoAuth');
|
|
16
16
|
|
|
@@ -92,7 +92,12 @@ class Client extends EventEmitter {
|
|
|
92
92
|
browser = await puppeteer.connect(puppeteerOpts);
|
|
93
93
|
page = await browser.newPage();
|
|
94
94
|
} else {
|
|
95
|
-
|
|
95
|
+
const browserArgs = [...(puppeteerOpts.args || [])];
|
|
96
|
+
if(!browserArgs.find(arg => arg.includes('--user-agent'))) {
|
|
97
|
+
browserArgs.push(`--user-agent=${this.options.userAgent}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
browser = await puppeteer.launch({...puppeteerOpts, args: browserArgs});
|
|
96
101
|
page = (await browser.pages())[0];
|
|
97
102
|
}
|
|
98
103
|
|
|
@@ -127,7 +132,7 @@ class Client extends EventEmitter {
|
|
|
127
132
|
})
|
|
128
133
|
]);
|
|
129
134
|
|
|
130
|
-
// Checks if an error
|
|
135
|
+
// Checks if an error occurred on the first found selector. The second will be discarded and ignored by .race;
|
|
131
136
|
if (needAuthentication instanceof Error) throw needAuthentication;
|
|
132
137
|
|
|
133
138
|
// Scan-qrcode selector was found. Needs authentication
|
|
@@ -580,7 +585,7 @@ class Client extends EventEmitter {
|
|
|
580
585
|
internalOptions.list = content;
|
|
581
586
|
content = '';
|
|
582
587
|
}
|
|
583
|
-
|
|
588
|
+
|
|
584
589
|
if (internalOptions.sendMediaAsSticker && internalOptions.attachment) {
|
|
585
590
|
internalOptions.attachment = await Util.formatToWebpSticker(
|
|
586
591
|
internalOptions.attachment, {
|
|
@@ -744,7 +749,7 @@ class Client extends EventEmitter {
|
|
|
744
749
|
|
|
745
750
|
return couldSet;
|
|
746
751
|
}
|
|
747
|
-
|
|
752
|
+
|
|
748
753
|
/**
|
|
749
754
|
* Gets the current connection state for the client
|
|
750
755
|
* @returns {WAState}
|
|
@@ -809,8 +814,9 @@ class Client extends EventEmitter {
|
|
|
809
814
|
return true;
|
|
810
815
|
}
|
|
811
816
|
const MAX_PIN_COUNT = 3;
|
|
812
|
-
|
|
813
|
-
|
|
817
|
+
const chatModels = window.Store.Chat.getModelsArray();
|
|
818
|
+
if (chatModels.length > MAX_PIN_COUNT) {
|
|
819
|
+
let maxPinned = chatModels[MAX_PIN_COUNT - 1].pin;
|
|
814
820
|
if (maxPinned) {
|
|
815
821
|
return false;
|
|
816
822
|
}
|
|
@@ -943,7 +949,8 @@ class Client extends EventEmitter {
|
|
|
943
949
|
}
|
|
944
950
|
|
|
945
951
|
return await this.pupPage.evaluate(async number => {
|
|
946
|
-
const
|
|
952
|
+
const wid = window.Store.WidFactory.createWid(number);
|
|
953
|
+
const result = await window.Store.QueryExist(wid);
|
|
947
954
|
if (!result || result.wid === undefined) return null;
|
|
948
955
|
return result.wid;
|
|
949
956
|
}, number);
|
|
@@ -1056,7 +1063,7 @@ class Client extends EventEmitter {
|
|
|
1056
1063
|
async getChatsByLabelId(labelId) {
|
|
1057
1064
|
const chatIds = await this.pupPage.evaluate(async (labelId) => {
|
|
1058
1065
|
const label = window.Store.Label.get(labelId);
|
|
1059
|
-
const labelItems = label.labelItemCollection.
|
|
1066
|
+
const labelItems = label.labelItemCollection.getModelsArray();
|
|
1060
1067
|
return labelItems.reduce((result, item) => {
|
|
1061
1068
|
if (item.parentType === 'Chat') {
|
|
1062
1069
|
result.push(item.parentId);
|
|
@@ -1074,7 +1081,7 @@ class Client extends EventEmitter {
|
|
|
1074
1081
|
*/
|
|
1075
1082
|
async getBlockedContacts() {
|
|
1076
1083
|
const blockedContacts = await this.pupPage.evaluate(() => {
|
|
1077
|
-
let chatIds = window.Store.Blocklist.
|
|
1084
|
+
let chatIds = window.Store.Blocklist.getModelsArray().map(a => a.id._serialized);
|
|
1078
1085
|
return Promise.all(chatIds.map(id => window.WWebJS.getContact(id)));
|
|
1079
1086
|
});
|
|
1080
1087
|
|
package/src/structures/Chat.js
CHANGED
|
@@ -179,12 +179,12 @@ class Chat extends Base {
|
|
|
179
179
|
const msgFilter = m => !m.isNotification; // dont include notification messages
|
|
180
180
|
|
|
181
181
|
const chat = window.Store.Chat.get(chatId);
|
|
182
|
-
let msgs = chat.msgs.
|
|
182
|
+
let msgs = chat.msgs.getModelsArray().filter(msgFilter);
|
|
183
183
|
|
|
184
184
|
if (searchOptions && searchOptions.limit > 0) {
|
|
185
185
|
while (msgs.length < searchOptions.limit) {
|
|
186
|
-
const loadedMessages = await
|
|
187
|
-
if (!loadedMessages) break;
|
|
186
|
+
const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat);
|
|
187
|
+
if (!loadedMessages || !loadedMessages.length) break;
|
|
188
188
|
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -147,7 +147,7 @@ class GroupChat extends Chat {
|
|
|
147
147
|
this.groupMetadata.desc = description;
|
|
148
148
|
return true;
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
/**
|
|
152
152
|
* Updates the group settings to only allow admins to send messages.
|
|
153
153
|
* @param {boolean} [adminsOnly=true] Enable or disable this option
|
|
@@ -335,6 +335,18 @@ class Message extends Base {
|
|
|
335
335
|
return this.client.sendMessage(chatId, content, options);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
/**
|
|
339
|
+
* React to this message with an emoji
|
|
340
|
+
* @param {string} reaction - Emoji to react with. Send an empty string to remove the reaction.
|
|
341
|
+
* @return {Promise}
|
|
342
|
+
*/
|
|
343
|
+
async react(reaction){
|
|
344
|
+
await this.client.pupPage.evaluate(async (messageId, reaction) => {
|
|
345
|
+
const msg = await window.Store.Msg.get(messageId);
|
|
346
|
+
await window.Store.sendReactionToMsg(msg, reaction);
|
|
347
|
+
}, this.id._serialized, reaction);
|
|
348
|
+
}
|
|
349
|
+
|
|
338
350
|
/**
|
|
339
351
|
* Accept Group V4 Invite
|
|
340
352
|
* @returns {Promise<Object>}
|
package/src/structures/index.js
CHANGED
package/src/util/Injected.js
CHANGED
|
@@ -48,6 +48,8 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
48
48
|
window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0];
|
|
49
49
|
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
|
|
50
50
|
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
|
|
51
|
+
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
|
|
52
|
+
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
|
|
51
53
|
window.Store.StickerTools = {
|
|
52
54
|
...window.mR.findModule('toWebpSticker')[0],
|
|
53
55
|
...window.mR.findModule('addWebpMetadata')[0]
|
|
@@ -98,7 +100,6 @@ exports.LoadUtils = () => {
|
|
|
98
100
|
delete options.attachment;
|
|
99
101
|
delete options.sendMediaAsSticker;
|
|
100
102
|
}
|
|
101
|
-
|
|
102
103
|
let quotedMsgOptions = {};
|
|
103
104
|
if (options.quotedMessageId) {
|
|
104
105
|
let quotedMessage = window.Store.Msg.get(options.quotedMessageId);
|
|
@@ -416,7 +417,7 @@ exports.LoadUtils = () => {
|
|
|
416
417
|
};
|
|
417
418
|
|
|
418
419
|
window.WWebJS.getChats = async () => {
|
|
419
|
-
const chats = window.Store.Chat.
|
|
420
|
+
const chats = window.Store.Chat.getModelsArray();
|
|
420
421
|
|
|
421
422
|
const chatPromises = chats.map(chat => window.WWebJS.getChatModel(chat));
|
|
422
423
|
return await Promise.all(chatPromises);
|
|
@@ -448,7 +449,7 @@ exports.LoadUtils = () => {
|
|
|
448
449
|
};
|
|
449
450
|
|
|
450
451
|
window.WWebJS.getContacts = () => {
|
|
451
|
-
const contacts = window.Store.Contact.
|
|
452
|
+
const contacts = window.Store.Contact.getModelsArray();
|
|
452
453
|
return contacts.map(contact => window.WWebJS.getContactModel(contact));
|
|
453
454
|
};
|
|
454
455
|
|
|
@@ -541,7 +542,7 @@ exports.LoadUtils = () => {
|
|
|
541
542
|
};
|
|
542
543
|
|
|
543
544
|
window.WWebJS.getLabels = () => {
|
|
544
|
-
const labels = window.Store.Label.
|
|
545
|
+
const labels = window.Store.Label.getModelsArray();
|
|
545
546
|
return labels.map(label => window.WWebJS.getLabelModel(label));
|
|
546
547
|
};
|
|
547
548
|
|