mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 20:49:14 +00:00
Implemented changes mentioned in SimiPrambos PR#28 (#52)
* Implemented changes mentioned in SimiPrambos PR#28 To reflect new code structure
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -273,13 +273,26 @@ 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
|
||||||
|
|
||||||
|
//todo : Check if the number is a whatsapp enabled. Whatsapp web sends query exists via ws.
|
||||||
|
chat = window.Store.Chat.models[0]; //get the topmost chat object and assign the new chatId to it
|
||||||
|
let originalChatObjId = chat.id;
|
||||||
|
chat.id = typeof originalChatObjId === 'string' ? chatId : new window.Store.UserConstructor(chatId, { intentionallyUsePrivateConstructor: true });
|
||||||
|
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>>}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
||||||
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
||||||
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 = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user