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: pin/unpin messages #2692

Merged
merged 7 commits into from
Jan 11, 2024
Merged

Conversation

alechkos
Copy link
Collaborator

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 15.12.2023)

- Types of Changes


Description

The PR adds functionality to pin and unpin messages in chats, groups and communities.
While pinning a message, the user has to provide a value in seconds for that message to be pinned in a chat.


Related Issues

The PR closes #2690


Usage Example

client.on('message', async (msg) => {
    const result = await msg.pin(60); // Will pin a message for 1 minute
    console.log(result); // True if the operation completed successfully, false otherwise
});

client.on('message_create', async (msg) => {
    if (msg.fromMe && msg.body.startsWith('!unpin')) {
        const pinnedMsg = await msg.getQuotedMessage();
        if (pinnedMsg) {
            // Will unpin a message
            const result = await pinnedMsg.unpin();
            console.log(result); // True if the operation completed successfully, false otherwise
        }
    }
});

To test this PR by yourself you can run one of the following commands:

  • NPM
npm install github:alechkos/whatsapp-web.js#pin-unpin-msgs
  • YARN
yarn add github:alechkos/whatsapp-web.js#pin-unpin-msgs

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 15.12.2023)

Tested with all possible scenarious.
In the case provided in usage example can be seen the scenario where the current user, possibly acting as a group admin, pins a message sent by another group member. Following this, the current user sends a message '!unpin' that quotes the previously pinned message, thus unpinning that pinned message.

Tested On:

Types of accounts:

  • Personal
  • Buisness

Environment:

  • Android 10:
    • WhatsApp: latest
    • WA Business: latest
  • Windows 10:
    • WWebJS: v1.23.1-alpha.1
    • WWeb: v2.2353.56
    • 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 (fix/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)

@alechkos alechkos mentioned this pull request Dec 15, 2023
1 task
example.js Outdated Show resolved Hide resolved
@diegofemello
Copy link

Worked here

@alechkos alechkos requested a review from aliyss December 16, 2023 16:11
Copy link
Collaborator

@shirser121 shirser121 left a comment

Choose a reason for hiding this comment

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

LGTM

@shirser121 shirser121 merged commit 8d683a6 into pedroslopez:main Jan 11, 2024
1 check passed
@Eraxorice
Copy link

Eraxorice commented Apr 4, 2024

Applying this seems to cause an issue if you have already installed #2596 (Poll voting feature).
Fix for me was to first apply this one and then re-install the #ext-poll.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PIN Messages on groups
5 participants