mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-19 03:59:16 +00:00
[+] Get quoted message
[FIX] Properly reply to messages sent by the current user
This commit is contained in:
10
example.js
10
example.js
@@ -98,6 +98,16 @@ client.on('message', async msg => {
|
|||||||
Filename: ${attachmentData.filename}
|
Filename: ${attachmentData.filename}
|
||||||
Data (length): ${attachmentData.data.length}
|
Data (length): ${attachmentData.data.length}
|
||||||
`);
|
`);
|
||||||
|
} else if(msg.body == '!quoteinfo' && msg.hasQuotedMsg) {
|
||||||
|
const quotedMsg = await msg.getQuotedMessage();
|
||||||
|
|
||||||
|
quotedMsg.reply(`
|
||||||
|
ID: ${quotedMsg.id._serialized}
|
||||||
|
Type: ${quotedMsg.type}
|
||||||
|
Author: ${(quotedMsg.author || quotedMsg.from)._serialized}
|
||||||
|
Timestamp: ${quotedMsg.timestamp}
|
||||||
|
Has Media? ${quotedMsg.hasMedia}
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -19,21 +19,40 @@ class Message extends Base {
|
|||||||
this.body = this.hasMedia ? data.caption || '' : data.body || '';
|
this.body = this.hasMedia ? data.caption || '' : data.body || '';
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
this.timestamp = data.t;
|
this.timestamp = data.t;
|
||||||
this.from = data.from;
|
this.from = typeof (data.from) === "object" ? data.from._serialized : data.from;
|
||||||
this.to = data.to;
|
this.to = typeof (data.to) === "object" ? data.to._serialized : data.to;
|
||||||
this.author = data.author;
|
this.author = typeof (data.author) === "object" ? data.author._serialized : data.author;
|
||||||
this.isForwarded = data.isForwarded;
|
this.isForwarded = data.isForwarded;
|
||||||
this.broadcast = data.broadcast;
|
this.broadcast = data.broadcast;
|
||||||
this.fromMe = data.id.fromMe;
|
this.fromMe = data.id.fromMe;
|
||||||
|
this.hasQuotedMsg = data.quotedMsg ? true : false;
|
||||||
|
|
||||||
return super._patch(data);
|
return super._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getChatId() {
|
||||||
|
return this.fromMe ? this.to : this.from;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Chat this message was sent in
|
* Returns the Chat this message was sent in
|
||||||
*/
|
*/
|
||||||
getChat() {
|
getChat() {
|
||||||
return this.client.getChatById(this.from);
|
return this.client.getChatById(this._getChatId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the quoted message, if any
|
||||||
|
*/
|
||||||
|
async getQuotedMessage() {
|
||||||
|
if (!this.hasQuotedMsg) return undefined;
|
||||||
|
|
||||||
|
const quotedMsg = await this.client.pupPage.evaluate((msgId) => {
|
||||||
|
let msg = Store.Msg.get(msgId);
|
||||||
|
return msg.quotedMsgObj().serialize();
|
||||||
|
}, this.id._serialized);
|
||||||
|
|
||||||
|
return new Message(this.client, quotedMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +64,7 @@ class Message extends Base {
|
|||||||
*/
|
*/
|
||||||
async reply(message, chatId) {
|
async reply(message, chatId) {
|
||||||
if (!chatId) {
|
if (!chatId) {
|
||||||
chatId = this.from;
|
chatId = this._getChatId();
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMessage = await this.client.pupPage.evaluate(async (chatId, quotedMessageId, message) => {
|
const newMessage = await this.client.pupPage.evaluate(async (chatId, quotedMessageId, message) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user