Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forward messages with caption text #2272

Open
wants to merge 76 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
565015c
extended Message.forward
Jun 10, 2023
eaf5072
docs updated accordingly
Jun 10, 2023
9456c65
added usage example
Jun 10, 2023
677079c
ESLint fixes
Jun 10, 2023
c227b33
Merge branch 'main' into forward-with-caption
Jun 16, 2023
5f1ca95
withCaption value is changed to true by default
Jun 16, 2023
a90b02d
fix: forwarded message is a first message in the chat history
Jun 16, 2023
924fd35
added support for forwarding attachments with caption
Jun 19, 2023
3c3a629
example updated
Jun 19, 2023
7e62a02
ESLint fixes
Jun 19, 2023
bd17e61
docs clarification
Jun 21, 2023
255da5b
code refactoring
Jun 21, 2023
d58ee28
_forwardMessageAndSendToChat simplified for text msgs
Jun 22, 2023
261633f
Merge branch 'main' into forward-with-caption
Jun 27, 2023
025f289
code refactoring
Jun 28, 2023
9f4ea84
example clarification
Jun 28, 2023
5dfaf31
recommendation to use chrome for full functionality
Jun 28, 2023
fed8cfb
docs clarification
Jun 29, 2023
189ba49
Merge branch 'main' into forward-with-caption
Jul 31, 2023
3f456e8
fix: ESLint
Jul 31, 2023
8c43d22
Merge branch 'main' into forward-with-caption
Jul 31, 2023
895ebfb
Merge branch 'main' into forward-with-caption
Aug 7, 2023
8f65cc7
Merge branch 'main' into forward-with-caption
Aug 7, 2023
be4d168
Merge branch 'main' into forward-with-caption
alechkos Aug 7, 2023
01cb40f
Merge branch 'main' into forward-with-caption
alechkos Aug 8, 2023
6c6a61e
Merge branch 'main' into forward-with-caption
alechkos Aug 8, 2023
897ad27
Merge branch 'main' into forward-with-caption
alechkos Aug 9, 2023
02f173e
Merge branch 'main' into forward-with-caption
alechkos Aug 10, 2023
a038a56
Merge branch 'main' into forward-with-caption
Aug 12, 2023
dd363a7
Merge branch 'main' into forward-with-caption
alechkos Aug 26, 2023
6d84b34
small update to improve the performance of findImpl fix
Aug 26, 2023
0d1d4a4
window.compareWwebVersions fixed
Aug 26, 2023
dc9014f
getForwardedMessageFields fixed
Aug 27, 2023
d65603d
Merge branch 'main' into forward-with-caption
alechkos Sep 14, 2023
66322ad
Merge branch 'main' into forward-with-caption
alechkos Sep 20, 2023
79c1dd8
Merge branch 'main' into forward-with-caption
Sep 21, 2023
7225a97
Merge branch 'main' into forward-with-caption
Oct 10, 2023
492b81c
Merge branch 'main' into forward-with-caption
Oct 11, 2023
f6de7ba
Merge branch 'main' into forward-with-caption
Oct 11, 2023
d65dda3
Merge branch 'main' into forward-with-caption
alechkos Oct 18, 2023
572b9ee
Merge branch 'main' into forward-with-caption
alechkos Nov 24, 2023
780c5e7
window.injectToFunction clarifications
alechkos Nov 1, 2023
393bd6b
[BUG] fixed Message.forward method
alechkos Nov 24, 2023
08dfcc4
Merge branch 'main' into forward-with-caption
alechkos Nov 24, 2023
4e7af64
[CHG] usage example updated
alechkos Nov 24, 2023
7ce66e2
[BUG] added missing module
alechkos Nov 24, 2023
18c3574
Merge branch 'main' into forward-with-caption
alechkos Nov 26, 2023
651b244
Merge branch 'main' into forward-with-caption
alechkos Dec 1, 2023
181c5e9
fix: method updated to be compatible with wweb v2.2353.0
alechkos Dec 1, 2023
f064155
fix: typo
alechkos Dec 1, 2023
5c34e31
Merge branch 'main' into forward-with-caption
alechkos Dec 1, 2023
63e0c6f
Merge branch 'main' into forward-with-caption
alechkos Dec 5, 2023
6399dce
Merge branch 'main' into forward-with-caption
alechkos Dec 7, 2023
cf2a356
fix: forward to unknown previously users
alechkos Dec 8, 2023
b11544d
fix: async function proper handling
alechkos Dec 8, 2023
84f0003
Merge branch 'main' into forward-with-caption
alechkos Dec 12, 2023
53f0855
Merge branch 'main' into forward-with-caption
alechkos Dec 12, 2023
49d34cd
Merge branch 'main' into forward-with-caption
alechkos Dec 16, 2023
164c2ca
Merge branch 'main' into forward-with-caption
alechkos Dec 17, 2023
9bbd5e9
Merge branch 'main' into forward-with-caption
alechkos Jan 2, 2024
13d4a7b
refactor: revert 'headless: true'
alechkos Jan 6, 2024
b1e2922
style: fix some minor flaws
alechkos Jan 6, 2024
355eeaa
fix: correct the check if a user is blocked
alechkos Jan 6, 2024
02f0e5d
Merge branch 'main' into forward-with-caption
alechkos Jan 11, 2024
dba3a33
Merge branch 'main' into forward-with-caption
alechkos Jan 11, 2024
b56b69e
Merge branch 'main' into forward-with-caption
alechkos Jan 14, 2024
e6c293b
Merge branch 'main' into forward-with-caption
alechkos Jan 18, 2024
8741ba9
Merge branch 'main' into forward-with-caption
alechkos Mar 1, 2024
3da3995
Merge branch 'main' into forward-with-caption
alechkos Apr 3, 2024
af6cdb7
Merge branch 'main' into forward-with-caption
alechkos Apr 22, 2024
ee192c2
style: fix broken link in readme file
alechkos Apr 22, 2024
42d7371
Merge branch 'main' into forward-with-caption
alechkos Apr 27, 2024
dcc9eea
Merge branch 'main' into forward-with-caption
alechkos Apr 28, 2024
37bdbfb
Merge branch 'main' into forward-with-caption
alechkos Apr 30, 2024
f6c07de
Merge branch 'main' into forward-with-caption
alechkos Apr 30, 2024
34dcf2d
Merge branch 'main' into forward-with-caption
alechkos May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions example.js
Expand Up @@ -211,6 +211,20 @@ client.on('message', async msg => {
}
}
}
else if (msg.author) {
/** Note: forwarding with caption is available for media messages (photo/video) only. */

/**
* Let's say the message was sent in a group
* and I want to forward it to its author.
*/

// 1. By default it will be forwarded without a caption text (even if provided):
await msg.forward(msg.author);

// 2. To forward with a caption text of original message (if provided) do:
await msg.forward(msg.author, { withCaption: true });
}
});

client.on('message_create', (msg) => {
Expand Down
9 changes: 8 additions & 1 deletion index.d.ts
Expand Up @@ -842,7 +842,7 @@ declare namespace WAWebJS {
/**
* Forwards this message to another chat (that you chatted before, otherwise it will fail)
*/
forward: (chat: Chat | string) => Promise<void>,
forward: (chat: Chat | string, options?: MessageForwardOptions) => Promise<void>,
/** Star this message */
star: () => Promise<void>,
/** Unstar this message */
Expand Down Expand Up @@ -928,6 +928,13 @@ declare namespace WAWebJS {
stickerCategories?: string[]
}

/** Options for forwarding a message */
export interface MessageForwardOptions {
multicast?: boolean
/** Adds caption text to forwarded message (if provided), if withCaption is true */
withCaption?: boolean
}

/** Options for editing a message */
export interface MessageEditOptions {
/** Show links preview. Has no effect on multi-device accounts. */
Expand Down
21 changes: 17 additions & 4 deletions src/structures/Message.js
Expand Up @@ -374,22 +374,35 @@ class Message extends Base {
async acceptGroupV4Invite() {
return await this.client.acceptGroupV4Invite(this.inviteV4);
}

/**
* Forward options:
*
* @typedef {Object} MessageForwardOptions
* @property {boolean} [multicast=false]
* @property {boolean} [withCaption=false] Forwards this message with the caption text of the original message if provided.
*/

/**
* Forwards this message to another chat (that you chatted before, otherwise it will fail)
*
* @param {string|Chat} chat Chat model or chat ID to which the message will be forwarded
* @param {MessageForwardOptions} [options] Options used when forwarding the message
* @returns {Promise}
*/
async forward(chat) {
async forward(chat, options = {}) {
const chatId = typeof chat === 'string' ? chat : chat.id._serialized;
let internalOptions = {
multicast: options.multicast || false,
withCaption: options.withCaption || false
alechkos marked this conversation as resolved.
Show resolved Hide resolved
};

await this.client.pupPage.evaluate(async (msgId, chatId) => {
await this.client.pupPage.evaluate(async (msgId, chatId, options) => {
let msg = window.Store.Msg.get(msgId);
let chat = window.Store.Chat.get(chatId);

return await chat.forwardMessages([msg]);
}, this.id._serialized, chatId);
return await chat.forwardMessages([msg], ...Object.values(options));
}, this.id._serialized, chatId, internalOptions);
}

/**
Expand Down