From f639c53f0ad1346aded0c8a649c9e1e27a34213b Mon Sep 17 00:00:00 2001 From: "Pedro S. Lopez" Date: Tue, 29 Dec 2020 00:20:20 -0400 Subject: [PATCH] feat: Get message delivery information (close #418) --- index.d.ts | 15 +++++++++++++-- src/structures/Message.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 5c24afb..6aaf9fe 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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, /** Star this message */ - star: () => Promise + star: () => Promise, /** Unstar this message */ - unstar: () => Promise + unstar: () => Promise, + /** Get information about message delivery statuso */ + getInfo: () => Promise } /** ID that represents a message */ diff --git a/src/structures/Message.js b/src/structures/Message.js index 669e3c1..efb6078 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -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} + */ + 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;