Skip to content

Commit

Permalink
feat: Get message delivery information (close #418)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroslopez committed Dec 29, 2020
1 parent 3e32fe2 commit f639c53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 */
Expand Down
30 changes: 30 additions & 0 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit f639c53

Please sign in to comment.