docs: add more documentation

This commit is contained in:
Pedro Lopez
2020-02-04 23:04:51 -04:00
parent a098d61b03
commit 2f0480c80e
9 changed files with 258 additions and 15 deletions

View File

@@ -15,17 +15,79 @@ class Message extends Base {
}
_patch(data) {
/**
* ID that represents the message
* @type {object}
*/
this.id = data.id;
/**
* Indicates if the message has media available for download
* @type {boolean}
*/
this.hasMedia = data.clientUrl ? true : false;
/**
* Message content
* @type {string}
*/
this.body = this.hasMedia ? data.caption || '' : data.body || '';
/**
* Message type
* @type {MessageTypes}
*/
this.type = data.type;
/**
* Unix timestamp for when the message was created
* @type {number}
*/
this.timestamp = data.t;
/**
* ID for the Chat that this message was sent to, except if the message was sent by the current user.
* @type {string}
*/
this.from = typeof (data.from) === 'object' ? data.from._serialized : data.from;
/**
* ID for who this message is for.
*
* If the message is sent by the current user, it will be the Chat to which the message is being sent.
* If the message is sent by another user, it will be the ID for the current user.
* @type {string}
*/
this.to = typeof (data.to) === 'object' ? data.to._serialized : data.to;
/**
* If the message was sent to a group, this field will contain the user that sent the message.
* @type {string}
*/
this.author = typeof (data.author) === 'object' ? data.author._serialized : data.author;
/**
* Indicates if the message was forwarded
* @type {boolean}
*/
this.isForwarded = data.isForwarded;
/**
* Indicates if the message was a broadcast
* @type {boolean}
*/
this.broadcast = data.broadcast;
/**
* Indicates if the message was sent by the current user
* @type {boolean}
*/
this.fromMe = data.id.fromMe;
/**
* Indicates if the message was sent as a reply to another message.
* @type {boolean}
*/
this.hasQuotedMsg = data.quotedMsg ? true : false;
return super._patch(data);
@@ -37,7 +99,7 @@ class Message extends Base {
/**
* Returns the Chat this message was sent in
* @returns {Chat}
* @returns {Promise<Chat>}
*/
getChat() {
return this.client.getChatById(this._getChatId());
@@ -45,7 +107,7 @@ class Message extends Base {
/**
* Returns the Contact this message was sent from
* @returns {Contact}
* @returns {Promise<Contact>}
*/
getContact() {
return this.client.getContactById(this._getChatId());
@@ -53,7 +115,7 @@ class Message extends Base {
/**
* Returns the quoted message, if any
* @returns {Message}
* @returns {Promise<Message>}
*/
async getQuotedMessage() {
if (!this.hasQuotedMsg) return undefined;
@@ -67,14 +129,14 @@ class Message extends Base {
}
/**
* Sends a message as a reply. If chatId is specified, it will be sent
* Sends a message as a reply to this message. If chatId is specified, it will be sent
* through the specified Chat. If not, it will send the message
* in the same Chat as the original message was sent.
*
* @param {string|MessageMedia} content
* @param {?string} chatId
* @param {object} options
* @returns {Message}
* @returns {Promise<Message>}
*/
async reply(content, chatId, options={}) {
if (!chatId) {
@@ -91,7 +153,7 @@ class Message extends Base {
/**
* Downloads and returns the attatched message media
* @returns {MessageMedia}
* @returns {Promise<MessageMedia>}
*/
async downloadMedia() {
if (!this.hasMedia) {