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

Conversation

alechkos
Copy link
Collaborator

@alechkos alechkos commented Jun 10, 2023

Important

breaking change Fix or feature that would cause existing functionality to change

Table of Contents

- Description

- Related Issues

- Usage Example

- I Want to Test this PR

- I Got an Error While Testing This PR ❌

- How Has the PR Been Tested (latest test on 01.05.2024)

- Types of Changes


Description

The PR introduces functionality that allows to forward media and attachment messages with their captions,
along with the ability to disable the Forwarded tag above a forwarded message.

❗ Breaking Changes:

  • Now media and attachment messages are forwarded with their captions by default
  • The method returns a boolean value that indicates the success of forwarding the message

You can forward a message without a caption by setting an optional property withCaption to false within Message.forward method.
Also you can turn off the Forwarded tag above a fowarded message by setting an optional property displayAsForwarded to false.


Related Issues

The PR closes #1650, closes #2426, closes #2435, closes #2629


Usage Example

client.on('message', async (message) => {
    if (message.author) {
        /**
         * Let's say the message was sent in a group
         * and you want to forward it to its author:
         */

        // 1. By default the message will be forwarded with a caption (if provided):
        await message.forward(message.author);

        // 2. To forward without a caption text, use { withCaption: false }:
        await message.forward(message.author, { withCaption: false });

        // 3. To forward without a 'Forwarded' title, use { displayAsForwarded: false }:
        await message.forward(message.author, { displayAsForwarded: false });
    }
});

To test this PR by yourself you should do two steps:

1. Install the PR by running one of the following commands:

  • NPM
npm install github:alechkos/whatsapp-web.js#forward-with-caption
  • YARN
yarn add github:alechkos/whatsapp-web.js#forward-with-caption

2. Lock your WWeb version on 2.2412.54:

const wwebVersion = '2.2412.54';

const client = new Client({
    authStrategy: new LocalAuth(), // your authstrategy here
    puppeteer: {
        // puppeteer args here
    },
    // locking the wweb version
    webVersionCache: {
        type: 'remote',
        remotePath: `https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/${wwebVersion}.html`,
    },
});

If you encounter any errors while testing this PR, please provide in a comment:

  1. The code you've used without any sensitive information (use syntax highlighting for more readability)
  2. The error you got
  3. The library version
  4. The WWeb version: console.log(await client.getWWebVersion());
  5. The browser (Chrome/Chromium)

Important

You have to reapply the PR each time it is changed (new commits were pushed since your last application)


How Has The PR Been Tested (latest test on 01.05.2024)

The functionality has been tested by sending different types of messages:

  • regular text messages
  • view once messages (are forwarded also)
  • messages with link preview
  • messages with mentions
  • media messages (photo/video/gif/sticker/animated sticker/audio/voice)
  • attachment messages (document)
  • messages with contact card/s
  • polls

Tested On:

Types of accounts:

  • Personal
  • Buisness

Environment:

  • Android 10:
    • WhatsApp: latest
    • WA Business: latest
  • Windows 10:
    • WWebJS: 1.23.1-alpha.6
    • WWeb: v2.2412.54
    • Puppeteer: v18.2.1
    • Node: v18.17.1
    • Chrome: latest

Types of Changes

  • Dependency change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • I have updated the usage example accordingly (example.js)
  • I have updated the documentation accordingly (index.d.ts)

ALΞX added 3 commits June 10, 2023 07:57
- added ability to forward messages with original caption text
@tuyuribr tuyuribr added the waiting for testers Waiting for other people test this PR in other envs label Jun 11, 2023
@tuyuribr
Copy link
Collaborator

I think if we change the default we should warn users about this before changing the default option. How would we inform them?

@alechkos
Copy link
Collaborator Author

I think if we change the default we should warn users about this before changing the default option. How would we inform them?

Yes i was considering keeping the old functionality as the default, but then Pedro pointed out that forwarding messages with a caption is the default functionality provided by wweb themselves, and it seemed appropriate to me to have message forwarding work the same way for us too. In any case i mentioned in the documentation and usage example that the default functionality has been changed. Please let me know if you think something more needs to be done.

@tuyuribr
Copy link
Collaborator

I think if we change the default we should warn users about this before changing the default option. How would we inform them?

Yes i was considering keeping the old functionality as the default, but then Pedro pointed out that forwarding messages with a caption is the default functionality provided by wweb themselves, and it seemed appropriate to me to have message forwarding work the same way for us too. In any case i mentioned in the documentation and usage example that the default functionality has been changed. Please let me know if you think something more needs to be done.

Excellent work alechkos, I think when we merge this to the main branch we should inform users in discord.

@alechkos alechkos marked this pull request as draft June 17, 2023 13:38
@alechkos alechkos changed the title feat: forward media messages with caption text feat: forward messages with caption text Jun 19, 2023
@alechkos alechkos marked this pull request as ready for review June 19, 2023 21:55
@tuyuribr tuyuribr added the breaking change Fix or feature that would cause existing functionality to change label Jun 21, 2023
@alechkos alechkos marked this pull request as draft June 22, 2023 19:34
@alechkos alechkos marked this pull request as ready for review June 28, 2023 23:02
@jrocha

This comment was marked as off-topic.

example.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@tuyuribr tuyuribr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to inform people of this (That the default now is fowarding with caption)

@alechkos
Copy link
Collaborator Author

alechkos commented Jan 7, 2024

This was referenced Feb 1, 2024
@jrocha

This comment was marked as off-topic.

@Matheus-Lima-Moreira

This comment was marked as off-topic.

@JuniorRibas

This comment was marked as off-topic.

@alechkos alechkos marked this pull request as draft April 16, 2024 02:51
Repository owner locked and limited conversation to collaborators Apr 16, 2024
Repository owner unlocked this conversation Apr 19, 2024
@alechkos alechkos marked this pull request as ready for review April 22, 2024 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Fix or feature that would cause existing functionality to change waiting for testers Waiting for other people test this PR in other envs
Projects
None yet
8 participants