mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 20:49:14 +00:00
Merge branch 'master' of https://github.com/pedroslopez/whatsapp-web.js
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[](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) 
|
||||||
|
|
||||||
# whatsapp-web.js
|
# whatsapp-web.js
|
||||||
A WhatsApp API client that connects through the WhatsApp Web browser app
|
A WhatsApp API client that connects through the WhatsApp Web browser app
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ client.on('message', async msg => {
|
|||||||
// Send a new message to the same chat
|
// Send a new message to the same chat
|
||||||
client.sendMessage(msg.from, 'pong');
|
client.sendMessage(msg.from, 'pong');
|
||||||
|
|
||||||
|
} else if (msg.body.startsWith('!sendto ')) {
|
||||||
|
// Direct send a new message to specific id
|
||||||
|
let number = msg.body.split(' ')[1];
|
||||||
|
let messageIndex = msg.body.indexOf(number) + number.length;
|
||||||
|
let message = msg.body.slice(messageIndex, msg.body.length);
|
||||||
|
number = number.includes('@c.us') ? number : `${number}@c.us`;
|
||||||
|
|
||||||
|
client.sendMessage(number, message);
|
||||||
|
|
||||||
} else if (msg.body.startsWith('!subject ')) {
|
} else if (msg.body.startsWith('!subject ')) {
|
||||||
// Change the group subject
|
// Change the group subject
|
||||||
let chat = await msg.getChat();
|
let chat = await msg.getChat();
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "whatsapp-web.js",
|
"name": "whatsapp-web.js",
|
||||||
"version": "0.3.2-post",
|
"version": "1.0.2-post",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -273,13 +273,30 @@ class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newMessage = await this.pupPage.evaluate(async (chatId, message, options) => {
|
const newMessage = await this.pupPage.evaluate(async (chatId, message, options) => {
|
||||||
const msg = await window.WWebJS.sendMessage(window.Store.Chat.get(chatId), message, options);
|
let chat = window.Store.Chat.get(chatId);
|
||||||
|
let msg;
|
||||||
|
if (!chat) { // The chat is not available in the previously chatted list
|
||||||
|
|
||||||
|
let newChatId = await window.WWebJS.getNumberId(chatId);
|
||||||
|
if (newChatId) {
|
||||||
|
//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];
|
||||||
|
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);
|
||||||
return msg.serialize();
|
return msg.serialize();
|
||||||
}, chatId, content, internalOptions);
|
}, chatId, content, internalOptions);
|
||||||
|
|
||||||
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>>}
|
||||||
|
|||||||
@@ -20,11 +20,19 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
||||||
window.Store.Cmd = window.mR.findModule('Cmd')[0].default;
|
window.Store.Cmd = window.mR.findModule('Cmd')[0].default;
|
||||||
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
|
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
|
||||||
|
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.LoadUtils = () => {
|
exports.LoadUtils = () => {
|
||||||
window.WWebJS = {};
|
window.WWebJS = {};
|
||||||
|
window.WWebJS.getNumberId = async (id) => {
|
||||||
|
|
||||||
|
let result = await window.Store.Wap.queryExist(id);
|
||||||
|
if (result.jid === undefined)
|
||||||
|
throw 'The number provided is not a registered whatsapp user';
|
||||||
|
return result.jid;
|
||||||
|
};
|
||||||
window.WWebJS.sendMessage = async (chat, content, options = {}) => {
|
window.WWebJS.sendMessage = async (chat, content, options = {}) => {
|
||||||
let attOptions = {};
|
let attOptions = {};
|
||||||
if (options.attachment) {
|
if (options.attachment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user