mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
chore: mark version v1.2.0
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta name="generator" content="JSDoc 3.6.3">
|
||||
<meta charset="utf-8">
|
||||
<title>whatsapp-web.js 1.1.0 » Source: Client.js</title>
|
||||
<title>whatsapp-web.js 1.2.0 » Source: Client.js</title>
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
|
||||
@@ -15,7 +15,7 @@
|
||||
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
|
||||
<div id="jsdoc-navbar-container">
|
||||
<div id="jsdoc-navbar-content">
|
||||
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>1.<wbr>0</a>
|
||||
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -41,11 +41,7 @@ const { WhatsWebURL, UserAgent, DefaultOptions, Events, WAState } = require
|
||||
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
||||
const ChatFactory = require('./factories/ChatFactory');
|
||||
const ContactFactory = require('./factories/ContactFactory');
|
||||
const ClientInfo = require('./structures/ClientInfo');
|
||||
const Message = require('./structures/Message');
|
||||
const MessageMedia = require('./structures/MessageMedia');
|
||||
const Location = require('./structures/Location');
|
||||
|
||||
const { ClientInfo, Message, MessageMedia, Location, GroupNotification } = require('./structures');
|
||||
/**
|
||||
* Starting point for interacting with the WhatsApp Web API
|
||||
* @extends {EventEmitter}
|
||||
@@ -54,9 +50,13 @@ const Location = require('./structures/Location');
|
||||
* @fires Client#auth_failure
|
||||
* @fires Client#ready
|
||||
* @fires Client#message
|
||||
* @fires Client#message_ack
|
||||
* @fires Client#message_create
|
||||
* @fires Client#message_revoke_me
|
||||
* @fires Client#message_revoke_everyone
|
||||
* @fires Client#group_join
|
||||
* @fires Client#group_leave
|
||||
* @fires Client#group_update
|
||||
* @fires Client#disconnected
|
||||
* @fires Client#change_state
|
||||
*/
|
||||
@@ -180,6 +180,33 @@ class Client extends EventEmitter {
|
||||
await page.exposeFunction('onAddMessageEvent', msg => {
|
||||
if (!msg.isNewMsg) return;
|
||||
|
||||
if (msg.type === 'gp2') {
|
||||
const notification = new GroupNotification(this, msg);
|
||||
if (msg.subtype === 'add' || msg.subtype === 'invite') {
|
||||
/**
|
||||
* Emitted when a user joins the chat via invite link or is added by an admin.
|
||||
* @event Client#group_join
|
||||
* @param {GroupNotification} notification GroupNotification with more information about the action
|
||||
*/
|
||||
this.emit(Events.GROUP_JOIN, notification);
|
||||
} else if (msg.subtype === 'remove' || msg.subtype === 'leave') {
|
||||
/**
|
||||
* Emitted when a user leaves the chat or is removed by an admin.
|
||||
* @event Client#group_leave
|
||||
* @param {GroupNotification} notification GroupNotification with more information about the action
|
||||
*/
|
||||
this.emit(Events.GROUP_LEAVE, notification);
|
||||
} else {
|
||||
/**
|
||||
* Emitted when group settings are updated, such as subject, description or picture.
|
||||
* @event Client#group_update
|
||||
* @param {GroupNotification} notification GroupNotification with more information about the action
|
||||
*/
|
||||
this.emit(Events.GROUP_UPDATE, notification);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const message = new Message(this, msg);
|
||||
|
||||
/**
|
||||
@@ -305,7 +332,19 @@ class Client extends EventEmitter {
|
||||
async destroy() {
|
||||
await this.pupBrowser.close();
|
||||
}
|
||||
/**
|
||||
* Mark as seen for the Chat
|
||||
* @param {string} chatId
|
||||
* @returns {Promise&lt;boolean>} result
|
||||
*
|
||||
*/
|
||||
async sendSeen(chatId) {
|
||||
const result = await this.pupPage.evaluate(async (chatId) => {
|
||||
return window.WWebJS.sendSeen(chatId);
|
||||
|
||||
}, chatId);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Send a message to a specific chatId
|
||||
* @param {string} chatId
|
||||
@@ -319,6 +358,8 @@ class Client extends EventEmitter {
|
||||
quotedMessageId: options.quotedMessageId,
|
||||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : []
|
||||
};
|
||||
|
||||
const sendSeen = typeof options.sendSeen === 'undefined' ? true : options.sendSeen;
|
||||
|
||||
if (content instanceof MessageMedia) {
|
||||
internalOptions.attachment = content;
|
||||
@@ -331,7 +372,7 @@ class Client extends EventEmitter {
|
||||
content = '';
|
||||
}
|
||||
|
||||
const newMessage = await this.pupPage.evaluate(async (chatId, message, options) => {
|
||||
const newMessage = await this.pupPage.evaluate(async (chatId, message, options, sendSeen) => {
|
||||
let chat = window.Store.Chat.get(chatId);
|
||||
let msg;
|
||||
if (!chat) { // The chat is not available in the previously chatted list
|
||||
@@ -341,16 +382,25 @@ class Client extends EventEmitter {
|
||||
//get the topmost chat object and assign the new chatId to it .
|
||||
//This is just a workaround.May cause problem if there are no chats at all. Need to dig in and emulate how whatsapp web does
|
||||
let chat = window.Store.Chat.models[0];
|
||||
if (!chat)
|
||||
throw 'Chat List empty! Need at least one open conversation with any of your contact';
|
||||
|
||||
let originalChatObjId = chat.id;
|
||||
chat.id = newChatId;
|
||||
|
||||
msg = await window.WWebJS.sendMessage(chat, message, options);
|
||||
chat.id = originalChatObjId; //replace the chat with its original id
|
||||
}
|
||||
}
|
||||
else
|
||||
msg = await window.WWebJS.sendMessage(chat, message, options);
|
||||
else {
|
||||
if(sendSeen) {
|
||||
window.WWebJS.sendSeen(chatId);
|
||||
}
|
||||
|
||||
msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen);
|
||||
}
|
||||
return msg.serialize();
|
||||
}, chatId, content, internalOptions);
|
||||
}, chatId, content, internalOptions, sendSeen);
|
||||
|
||||
return new Message(this, newMessage);
|
||||
}
|
||||
@@ -461,6 +511,15 @@ class Client extends EventEmitter {
|
||||
}, chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force reset of connection state for the client
|
||||
*/
|
||||
async resetState(){
|
||||
await this.pupPage.evaluate(() => {
|
||||
window.Store.AppState.phoneWatchdog.shiftTimer.forceRunNow();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
@@ -474,7 +533,7 @@ module.exports = Client;
|
||||
<footer id="jsdoc-footer" class="jsdoc-footer">
|
||||
<div id="jsdoc-footer-container">
|
||||
<p>
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on February 26, 2020.
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
Reference in New Issue
Block a user