UNPKG

bot_genshin

Version:
497 lines (424 loc) 16.4 kB
<!doctype html> <html> <head> <meta name="generator" content="JSDoc 3.6.7"> <meta charset="utf-8"> <title>whatsapp-web.js 1.14.0 &raquo; Source: structures/Message.js</title> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css"> <link href="css/baseline.css" rel="stylesheet"> </head> <body onload="prettyPrint()"> <nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar"> <div id="jsdoc-navbar-container"> <div id="jsdoc-navbar-content"> <a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>14.<wbr>0</a> </div> </div> </nav> <div id="jsdoc-body-container"> <div id="jsdoc-content"> <div id="jsdoc-content-container"> <div id="jsdoc-banner" role="banner"> </div> <div id="jsdoc-main" role="main"> <header class="page-header"> <h1>Source: structures/Message.js</h1> </header> <article> <pre class="prettyprint linenums"><code>&#x27;use strict&#x27;; const Base &#x3D; require(&#x27;./Base&#x27;); const MessageMedia &#x3D; require(&#x27;./MessageMedia&#x27;); const Location &#x3D; require(&#x27;./Location&#x27;); const Order &#x3D; require(&#x27;./Order&#x27;); const { MessageTypes } &#x3D; require(&#x27;../util/Constants&#x27;); /** * Represents a Message on WhatsApp * @extends {Base} */ class Message extends Base { constructor(client, data) { super(client); if (data) this._patch(data); } _patch(data) { /** * MediaKey that represents the sticker &#x27;ID&#x27; * @type {string} */ this.mediaKey &#x3D; data.mediaKey; /** * ID that represents the message * @type {object} */ this.id &#x3D; data.id; /** * ACK status for the message * @type {MessageAck} */ this.ack &#x3D; data.ack; /** * Indicates if the message has media available for download * @type {boolean} */ this.hasMedia &#x3D; Boolean(data.mediaKey &amp;amp;&amp;amp; data.directPath); /** * Message content * @type {string} */ this.body &#x3D; this.hasMedia ? data.caption || &#x27;&#x27; : data.body || &#x27;&#x27;; /** * Message type * @type {MessageTypes} */ this.type &#x3D; data.type; /** * Unix timestamp for when the message was created * @type {number} */ this.timestamp &#x3D; 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 &#x3D; (typeof (data.from) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; &amp;amp;&amp;amp; data.from !&#x3D;&#x3D; null) ? 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 &#x3D; (typeof (data.to) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; &amp;amp;&amp;amp; data.to !&#x3D;&#x3D; null) ? 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 &#x3D; (typeof (data.author) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; &amp;amp;&amp;amp; data.author !&#x3D;&#x3D; null) ? data.author._serialized : data.author; /** * String that represents from which device type the message was sent * @type {string} */ this.deviceType &#x3D; data.id.id.length &gt; 21 ? &#x27;android&#x27; : data.id.id.substring(0,2) &#x3D;&#x3D;&#x27;3A&#x27; ? &#x27;ios&#x27; : &#x27;web&#x27;; /** * Indicates if the message was forwarded * @type {boolean} */ this.isForwarded &#x3D; data.isForwarded; /** * Indicates how many times the message was forwarded. * * The maximum value is 127. * @type {number} */ this.forwardingScore &#x3D; data.forwardingScore || 0; /** * Indicates if the message is a status update * @type {boolean} */ this.isStatus &#x3D; data.isStatusV3; /** * Indicates if the message was starred * @type {boolean} */ this.isStarred &#x3D; data.star; /** * Indicates if the message was a broadcast * @type {boolean} */ this.broadcast &#x3D; data.broadcast; /** * Indicates if the message was sent by the current user * @type {boolean} */ this.fromMe &#x3D; data.id.fromMe; /** * Indicates if the message was sent as a reply to another message. * @type {boolean} */ this.hasQuotedMsg &#x3D; data.quotedMsg ? true : false; /** * Location information contained in the message, if the message is type &quot;location&quot; * @type {Location} */ this.location &#x3D; data.type &#x3D;&#x3D;&#x3D; MessageTypes.LOCATION ? new Location(data.lat, data.lng, data.loc) : undefined; /** * List of vCards contained in the message. * @type {Array&amp;lt;string&gt;} */ this.vCards &#x3D; data.type &#x3D;&#x3D;&#x3D; MessageTypes.CONTACT_CARD_MULTI ? data.vcardList.map((c) &#x3D;&gt; c.vcard) : data.type &#x3D;&#x3D;&#x3D; MessageTypes.CONTACT_CARD ? [data.body] : []; /** * Group Invite Data * @type {object} */ this.inviteV4 &#x3D; data.type &#x3D;&#x3D;&#x3D; MessageTypes.GROUP_INVITE ? { inviteCode: data.inviteCode, inviteCodeExp: data.inviteCodeExp, groupId: data.inviteGrp, groupName: data.inviteGrpName, fromId: data.from._serialized, toId: data.to._serialized } : undefined; /** * Indicates the mentions in the message body. * @type {Array&amp;lt;string&gt;} */ this.mentionedIds &#x3D; []; if (data.mentionedJidList) { this.mentionedIds &#x3D; data.mentionedJidList; } /** * Order ID for message type ORDER * @type {string} */ this.orderId &#x3D; data.orderId ? data.orderId : undefined; /** * Order Token for message type ORDER * @type {string} */ this.token &#x3D; data.token ? data.token : undefined; /** Title */ if (data.title) { this.title &#x3D; data.title; } /** Description */ if (data.description) { this.description &#x3D; data.description; } /** Business Owner JID */ if (data.businessOwnerJid) { this.businessOwnerJid &#x3D; data.businessOwnerJid; } /** Product ID */ if (data.productId) { this.productId &#x3D; data.productId; } /** * Links included in the message. * @type {Array&amp;lt;{link: string, isSuspicious: boolean}&gt;} * */ this.links &#x3D; data.links; return super._patch(data); } _getChatId() { return this.fromMe ? this.to : this.from; } /** * Returns the Chat this message was sent in * @returns {Promise&amp;lt;Chat&gt;} */ getChat() { return this.client.getChatById(this._getChatId()); } /** * Returns the Contact this message was sent from * @returns {Promise&amp;lt;Contact&gt;} */ getContact() { return this.client.getContactById(this.author || this.from); } /** * Returns the Contacts mentioned in this message * @returns {Promise&amp;lt;Array&amp;lt;Contact&gt;&gt;} */ async getMentions() { return await Promise.all(this.mentionedIds.map(async m &#x3D;&gt; await this.client.getContactById(m))); } /** * Returns the quoted message, if any * @returns {Promise&amp;lt;Message&gt;} */ async getQuotedMessage() { if (!this.hasQuotedMsg) return undefined; const quotedMsg &#x3D; await this.client.pupPage.evaluate((msgId) &#x3D;&gt; { let msg &#x3D; window.Store.Msg.get(msgId); return msg.quotedMsgObj().serialize(); }, this.id._serialized); return new Message(this.client, quotedMsg); } /** * 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|Location} content * @param {string} [chatId] * @param {MessageSendOptions} [options] * @returns {Promise&amp;lt;Message&gt;} */ async reply(content, chatId, options &#x3D; {}) { if (!chatId) { chatId &#x3D; this._getChatId(); } options &#x3D; { ...options, quotedMessageId: this.id._serialized }; return this.client.sendMessage(chatId, content, options); } /** * Accept Group V4 Invite * @returns {Promise&amp;lt;Object&gt;} */ async acceptGroupV4Invite() { return await this.client.acceptGroupV4Invite(this.inviteV4); } /** * Forwards this message to another chat * * @param {string|Chat} chat Chat model or chat ID to which the message will be forwarded * @returns {Promise} */ async forward(chat) { const chatId &#x3D; typeof chat &#x3D;&#x3D;&#x3D; &#x27;string&#x27; ? chat : chat.id._serialized; await this.client.pupPage.evaluate(async (msgId, chatId) &#x3D;&gt; { let msg &#x3D; window.Store.Msg.get(msgId); let chat &#x3D; window.Store.Chat.get(chatId); return await chat.forwardMessages([msg]); }, this.id._serialized, chatId); } /** * Downloads and returns the attatched message media * @returns {Promise&amp;lt;MessageMedia&gt;} */ async downloadMedia() { if (!this.hasMedia) { return undefined; } const result &#x3D; await this.client.pupPage.evaluate(async (msgId) &#x3D;&gt; { const msg &#x3D; window.Store.Msg.get(msgId); if (msg.mediaData.mediaStage !&#x3D; &#x27;RESOLVED&#x27;) { // try to resolve media await msg.downloadMedia({ downloadEvenIfExpensive: true, rmrReason: 1 }); } if (msg.mediaData.mediaStage.includes(&#x27;ERROR&#x27;) || msg.mediaData.mediaStage &#x3D;&#x3D;&#x3D; &#x27;FETCHING&#x27;) { // media could not be downloaded return undefined; } try { const decryptedMedia &#x3D; await window.Store.DownloadManager.downloadAndDecrypt({ directPath: msg.directPath, encFilehash: msg.encFilehash, filehash: msg.filehash, mediaKey: msg.mediaKey, mediaKeyTimestamp: msg.mediaKeyTimestamp, type: msg.type, signal: (new AbortController).signal }); const data &#x3D; window.WWebJS.arrayBufferToBase64(decryptedMedia); return { data, mimetype: msg.mimetype, filename: msg.filename }; } catch (e) { if(e.status &amp;amp;&amp;amp; e.status &#x3D;&#x3D;&#x3D; 404) return undefined; throw e; } }, this.id._serialized); if (!result) return undefined; return new MessageMedia(result.mimetype, result.data, result.filename); } /** * Deletes a message from the chat * @param {?boolean} everyone If true and the message is sent by the current user, will delete it for everyone in the chat. */ async delete(everyone) { await this.client.pupPage.evaluate((msgId, everyone) &#x3D;&gt; { let msg &#x3D; window.Store.Msg.get(msgId); if (everyone &amp;amp;&amp;amp; msg.id.fromMe &amp;amp;&amp;amp; msg.canRevoke()) { return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], true); } return window.Store.Cmd.sendDeleteMsgs(msg.chat, [msg], true); }, this.id._serialized, everyone); } /** * Stars this message */ async star() { await this.client.pupPage.evaluate((msgId) &#x3D;&gt; { let msg &#x3D; window.Store.Msg.get(msgId); if (msg.canStar()) { return msg.chat.sendStarMsgs([msg], true); } }, this.id._serialized); } /** * Unstars this message */ async unstar() { await this.client.pupPage.evaluate((msgId) &#x3D;&gt; { let msg &#x3D; window.Store.Msg.get(msgId); if (msg.canStar()) { return msg.chat.sendStarMsgs([msg], false); } }, this.id._serialized); } /** * Message Info * @typedef {Object} MessageInfo * @property {Array&amp;lt;{id: ContactId, t: number}&gt;} 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&amp;lt;{id: ContactId, t: number}&gt;} played Contacts who have listened to the voice message * @property {number} playedRemaining Amount of people who have not listened to the message * @property {Array&amp;lt;{id: ContactId, t: number}&gt;} 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&amp;lt;?MessageInfo&gt;} */ async getInfo() { const info &#x3D; await this.client.pupPage.evaluate(async (msgId) &#x3D;&gt; { const msg &#x3D; 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; } /** * Gets the order associated with a given message * @return {Promise&amp;lt;Order&gt;} */ async getOrder() { if (this.type &#x3D;&#x3D;&#x3D; MessageTypes.ORDER) { const result &#x3D; await this.client.pupPage.evaluate((orderId, token) &#x3D;&gt; { return window.WWebJS.getOrderDetail(orderId, token); }, this.orderId, this.token); if (!result) return undefined; return new Order(this.client, result); } return undefined; } } module.exports &#x3D; Message; </code></pre> </article> </div> </div> <nav id="jsdoc-toc-nav" role="navigation"></nav> </div> </div> <footer id="jsdoc-footer" class="jsdoc-footer"> <div id="jsdoc-footer-container"> <p> Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on August 1, 2021. </p> </div> </footer> <script src="scripts/jquery.min.js"></script> <script src="scripts/tree.jquery.js"></script> <script src="scripts/prettify.js"></script> <script src="scripts/jsdoc-toc.js"></script> <script src="scripts/linenumber.js"></script> <script src="scripts/scrollanchor.js"></script> </body> </html>