mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 04:29:15 +00:00
Merge branch 'master' of https://github.com/pedroslopez/whatsapp-web.js
This commit is contained in:
@@ -146,7 +146,6 @@ client.on('message', async msg => {
|
|||||||
const attachmentData = await quotedMsg.downloadMedia();
|
const attachmentData = await quotedMsg.downloadMedia();
|
||||||
client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' });
|
client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (msg.body == '!location') {
|
} else if (msg.body == '!location') {
|
||||||
msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters'));
|
msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters'));
|
||||||
} else if (msg.location) {
|
} else if (msg.location) {
|
||||||
@@ -168,6 +167,9 @@ client.on('message', async msg => {
|
|||||||
} else {
|
} else {
|
||||||
msg.reply('I can only delete my own messages');
|
msg.reply('I can only delete my own messages');
|
||||||
}
|
}
|
||||||
|
} else if (msg.body === '!archive') {
|
||||||
|
const chat = await msg.getChat();
|
||||||
|
chat.archive();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -83,21 +83,34 @@ class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
const getQrCode = async () => {
|
||||||
|
// Check if retry button is present
|
||||||
|
var QR_RETRY_SELECTOR = 'div[data-ref] > span > div';
|
||||||
|
var qrRetry = await page.$(QR_RETRY_SELECTOR);
|
||||||
|
if (qrRetry) {
|
||||||
|
await qrRetry.click();
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for QR Code
|
// Wait for QR Code
|
||||||
|
|
||||||
const QR_CANVAS_SELECTOR = 'canvas';
|
const QR_CANVAS_SELECTOR = 'canvas';
|
||||||
await page.waitForSelector(QR_CANVAS_SELECTOR);
|
await page.waitForSelector(QR_CANVAS_SELECTOR);
|
||||||
const qrImgData = await page.$eval(QR_CANVAS_SELECTOR, canvas => [].slice.call(canvas.getContext('2d').getImageData(0, 0, 264, 264).data));
|
const qrImgData = await page.$eval(QR_CANVAS_SELECTOR, canvas => [].slice.call(canvas.getContext('2d').getImageData(0, 0, 264, 264).data));
|
||||||
const qr = jsQR(qrImgData, 264, 264).data;
|
const qr = jsQR(qrImgData, 264, 264).data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when the QR code is received
|
* Emitted when the QR code is received
|
||||||
* @event Client#qr
|
* @event Client#qr
|
||||||
* @param {string} qr QR Code
|
* @param {string} qr QR Code
|
||||||
*/
|
*/
|
||||||
this.emit(Events.QR_RECEIVED, qr);
|
this.emit(Events.QR_RECEIVED, qr);
|
||||||
|
};
|
||||||
|
getQrCode();
|
||||||
|
let retryInterval = setInterval(getQrCode, 20000); // check for qr code every 20 seconds
|
||||||
|
|
||||||
// Wait for code scan
|
// Wait for code scan
|
||||||
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 });
|
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 });
|
||||||
|
clearInterval(retryInterval);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.evaluate(ExposeStore, moduleRaid.toString());
|
await page.evaluate(ExposeStore, moduleRaid.toString());
|
||||||
@@ -296,7 +309,6 @@ class Client extends EventEmitter {
|
|||||||
return new Message(this, newMessage);
|
return new Message(this, newMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all current chat instances
|
* Get all current chat instances
|
||||||
* @returns {Promise<Array<Chat>>}
|
* @returns {Promise<Array<Chat>>}
|
||||||
@@ -379,6 +391,30 @@ class Client extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables and returns the archive state of the Chat
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
async archiveChat(chatId) {
|
||||||
|
return await this.pupPage.evaluate(async chatId => {
|
||||||
|
let chat = await window.Store.Chat.get(chatId);
|
||||||
|
await window.Store.Cmd.archiveChat(chat, true);
|
||||||
|
return chat.archive;
|
||||||
|
}, chatId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes and returns the archive state of the Chat
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
async unarchiveChat(chatId) {
|
||||||
|
return await this.pupPage.evaluate(async chatId => {
|
||||||
|
let chat = await window.Store.Chat.get(chatId);
|
||||||
|
await window.Store.Cmd.archiveChat(chat, false);
|
||||||
|
return chat.archive;
|
||||||
|
}, chatId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ class Chat extends Base {
|
|||||||
*/
|
*/
|
||||||
this.timestamp = data.t;
|
this.timestamp = data.t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the Chat is archived
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.archived = data.archive;
|
||||||
|
|
||||||
return super._patch(data);
|
return super._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +88,21 @@ class Chat extends Base {
|
|||||||
return window.WWebJS.sendDeleteChat(chatId);
|
return window.WWebJS.sendDeleteChat(chatId);
|
||||||
}, this.id._serialized);
|
}, this.id._serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Archives this chat
|
||||||
|
*/
|
||||||
|
async archive() {
|
||||||
|
return this.client.archiveChat(this.id._serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* un-archives this chat
|
||||||
|
*/
|
||||||
|
async unarchive() {
|
||||||
|
return this.client.unarchiveChat(this.id._serialized);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Chat;
|
module.exports = Chat;
|
||||||
Reference in New Issue
Block a user