feat: Get message delivery information (close #418)

This commit is contained in:
Pedro S. Lopez
2020-12-29 00:20:20 -04:00
parent 3e32fe27ea
commit f639c53f0a
2 changed files with 43 additions and 2 deletions

15
index.d.ts vendored
View File

@@ -433,6 +433,15 @@ declare namespace WAWebJS {
UNPAIRED_IDLE = 'UNPAIRED_IDLE',
}
export type MessageInfo = {
delivery: Array<{id: ContactId, t: number}>,
deliveryRemaining: number,
played: Array<{id: ContactId, t: number}>,
playedRemaining: number,
read: Array<{id: ContactId, t: number}>,
readRemaining: number
}
/**
* Represents a Message on WhatsApp
*
@@ -530,9 +539,11 @@ declare namespace WAWebJS {
*/
forward: (chat: Chat | string) => Promise<void>,
/** Star this message */
star: () => Promise<void>
star: () => Promise<void>,
/** Unstar this message */
unstar: () => Promise<void>
unstar: () => Promise<void>,
/** Get information about message delivery statuso */
getInfo: () => Promise<MessageInfo | null>
}
/** ID that represents a message */

View File

@@ -310,6 +310,36 @@ class Message extends Base {
}
}, this.id._serialized);
}
/**
* Message Info
* @typedef {Object} MessageInfo
* @property {Array<{id: ContactId, t: number}>} delivery Contacts to which the message has been delivered to
* @property {number} deliveryRemaining Amount of people to whom the message has not been delivered to
* @property {Array<{id: ContactId, t: number}>} played Contacts who have listened to the voice message
* @property {number} playedRemaining Amount of people who have not listened to the message
* @property {Array<{id: ContactId, t: number}>} read Contacts who have read the message
* @property {number} readRemaining Amount of people who have not read the message
*/
/**
* Get information about message delivery status. May return null if the message does not exist or is not sent by you.
* @returns {Promise<?MessageInfo>}
*/
async getInfo() {
const info = await this.client.pupPage.evaluate(async (msgId) => {
const msg = window.Store.Msg.get(msgId);
if(!msg) return null;
return await window.Store.Wap.queryMsgInfo(msg.id);
}, this.id._serialized);
if(info.status) {
return null;
}
return info;
}
}
module.exports = Message;