From 502b22f6d700110fcaa323d857686219ea0db9b6 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Tue, 25 Aug 2020 23:00:35 -0400 Subject: [PATCH] feat: forward messages close #316 --- index.d.ts | 4 ++++ src/structures/Message.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/index.d.ts b/index.d.ts index b9e5a1c..4001695 100644 --- a/index.d.ts +++ b/index.d.ts @@ -485,6 +485,10 @@ declare namespace WAWebJS { * If not, it will send the message in the same Chat as the original message was sent. */ reply: (content: MessageContent, chatId?: string, options?: MessageSendOptions) => Promise, + /** + * Forwards this message to another chat + */ + forward: (chat: Chat | string) => Promise, } /** ID that represents a message */ diff --git a/src/structures/Message.js b/src/structures/Message.js index 7175880..7ee8012 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -190,6 +190,23 @@ class Message extends Base { return this.client.sendMessage(chatId, content, options); } + /** + * 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 = typeof chat === 'string' ? chat : chat.id._serialized; + + await this.client.pupPage.evaluate(async (msgId, chatId) => { + let msg = window.Store.Msg.get(msgId); + let chat = window.Store.Chat.get(chatId); + + return await chat.forwardMessages([msg]); + }, this.id._serialized, chatId); + } + /** * Downloads and returns the attatched message media * @returns {Promise}