mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Return new message after sending
This commit is contained in:
@@ -138,9 +138,12 @@ class Client extends EventEmitter {
|
||||
* @param {string} message
|
||||
*/
|
||||
async sendMessage(chatId, message) {
|
||||
await this.pupPage.evaluate((chatId, message) => {
|
||||
Store.SendMessage(Store.Chat.get(chatId), message);
|
||||
}, chatId, message)
|
||||
const newMessage = await this.pupPage.evaluate(async (chatId, message) => {
|
||||
const msg = await WWebJS.sendMessage(Store.Chat.get(chatId), message);
|
||||
return msg.serialize();
|
||||
}, chatId, message);
|
||||
|
||||
return new Message(this, newMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,11 @@ class Chat extends Base {
|
||||
return super._patch(data);
|
||||
}
|
||||
|
||||
sendMessage(message) {
|
||||
/**
|
||||
* Sends a message to this chat.
|
||||
* @param {string} message
|
||||
*/
|
||||
async sendMessage(message) {
|
||||
return this.client.sendMessage(this.id._serialized, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,18 +48,18 @@ class Message extends Base {
|
||||
chatId = this.from;
|
||||
}
|
||||
|
||||
return await this.client.pupPage.evaluate((chatId, quotedMessageId, message) => {
|
||||
const newMessage = await this.client.pupPage.evaluate(async (chatId, quotedMessageId, message) => {
|
||||
let quotedMessage = Store.Msg.get(quotedMessageId);
|
||||
if(quotedMessage.canReply()) {
|
||||
const chat = Store.Chat.get(chatId);
|
||||
chat.composeQuotedMsg = quotedMessage;
|
||||
window.Store.SendMessage(chat, message, {quotedMsg: quotedMessage});
|
||||
chat.composeQuotedMsg = null;
|
||||
const newMessage = await WWebJS.sendMessage(chat, message, quotedMessage.msgContextInfo(chat));
|
||||
return newMessage.serialize();
|
||||
} else {
|
||||
throw new Error('This message cannot be replied to.');
|
||||
}
|
||||
|
||||
}, chatId, this.id._serialized, message);
|
||||
|
||||
return new Message(this.client, newMessage);
|
||||
}
|
||||
|
||||
async downloadMedia() {
|
||||
|
||||
@@ -8,14 +8,41 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
window.mR = moduleRaid();
|
||||
window.Store = window.mR.findModule("Chat")[1].default;
|
||||
window.Store.AppState = window.mR.findModule("STREAM")[0].default;
|
||||
window.Store.Conn = window.mR.findModule("Conn")[0].default;
|
||||
window.Store.CryptoLib = window.mR.findModule("decryptE2EMedia")[0];
|
||||
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
|
||||
window.Store.SendMessage = window.mR.findModule("sendTextMsgToChat")[0].sendTextMsgToChat;
|
||||
window.Store.SendMessage = window.mR.findModule("addAndSendMsgToChat")[0];
|
||||
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
|
||||
}
|
||||
|
||||
exports.LoadUtils = () => {
|
||||
window.WWebJS = {};
|
||||
|
||||
window.WWebJS.sendMessage = async (chat, content, options) => {
|
||||
const newMsgId = new Store.MsgKey({
|
||||
from: Store.Conn.me,
|
||||
to: chat.id,
|
||||
id: Store.genId(),
|
||||
});
|
||||
|
||||
const message = {
|
||||
id: newMsgId,
|
||||
ack: 0,
|
||||
body: content,
|
||||
from: Store.Conn.me,
|
||||
to: chat.id,
|
||||
local: true,
|
||||
self: 'out',
|
||||
t: parseInt(new Date().getTime() / 1000),
|
||||
isNewMsg: true,
|
||||
type: 'chat',
|
||||
...options
|
||||
}
|
||||
|
||||
await Store.SendMessage.addAndSendMsgToChat(chat, message);
|
||||
return Store.Msg.get(newMsgId._serialized);
|
||||
}
|
||||
|
||||
window.WWebJS.getChatModel = chat => {
|
||||
let res = chat.serialize();
|
||||
res.isGroup = chat.isGroup;
|
||||
|
||||
Reference in New Issue
Block a user