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: vote_update event #2596

Merged
merged 48 commits into from Apr 30, 2024
Merged

feat: vote_update event #2596

merged 48 commits into from Apr 30, 2024

Conversation

alechkos
Copy link
Collaborator

@alechkos alechkos commented Oct 23, 2023

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

- Types of Changes


Special thanks to @tuyuribr for his help


Description

The PR adds an event that will be triggered when users vote or unvote in a poll.
Each time the event is fired, it shows a user's current selected option(s) on the poll.


Related Issues

The PR closes #2494, closes #2626


Usage Example

client.on('vote_update', (vote) => {
    /**
     * The {@link vote} that was affected:
     * 
     * {
     *   voter: '[email protected]',
     *   selectedOptions: [ { name: 'B', localId: 1 } ],
     *   interractedAtTs: 1698195555555,
     *   parentMessage: {
     *     ...,
     *     pollName: 'PollName',
     *     pollOptions: [
     *       { name: 'A', localId: 0 },
     *       { name: 'B', localId: 1 }
     *     ],
     *     allowMultipleAnswers: true,
     *     messageSecret: [
     *        1, 2, 3, 0, 0, 0, 0, 0,
     *        0, 0, 0, 0, 0, 0, 0, 0,
     *        0, 0, 0, 0, 0, 0, 0, 0,
     *        0, 0, 0, 0, 0, 0, 0, 0
     *     ]
     *   }
     * }
     */
    console.log(vote);
});

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#polls-ext
  • YARN
yarn add github:alechkos/whatsapp-web.js#polls-ext

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

Tested by selecting and deselecting poll options in both single-option and multiple-option polls.

Tested On:

Types of accounts:

  • Personal
  • Buisness

Environment:

  • Android 10:
    • WhatsApp: latest
    • WA Business: latest
  • Windows 10:
    • WWebJS: v1.23.1-alpha.5
    • 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 (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 changed the title feat: poll vote event feat: poll_update event Oct 25, 2023
@alechkos alechkos marked this pull request as ready for review October 25, 2023 02:47
This was referenced Nov 11, 2023
@alechkos alechkos changed the title feat: poll_update event feat: vote_update event Nov 14, 2023
Repository owner deleted a comment from abimtekno Apr 4, 2024
@Eraxorice Eraxorice mentioned this pull request Apr 4, 2024
7 tasks
@alechkos alechkos marked this pull request as draft April 16, 2024 02:52
auto-merge was automatically disabled April 16, 2024 02:52

Pull request was converted to draft

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:10
@seowzhenjun0126
Copy link

Will this work for WhatsApp web 2.3x for now / future? Thanks!

@alechkos
Copy link
Collaborator Author

@seowzhenjun0126

Will this work for WhatsApp web 2.3x for now / future? Thanks!

As soon as the patch is a part of main, I will add required changes to support wweb 2.3xxx

@seowzhenjun0126
Copy link

Got it. Thanks for your help!

@felipeaffonsobsi
Copy link

Não consigo utilizar e ler o voto do usuário. Alguém pode me ajudar?

@alechkos
Copy link
Collaborator Author

alechkos commented Apr 24, 2024

@felipeaffonsobsi

Não consigo utilizar e ler o voto do usuário. Alguém pode me ajudar?

#2596 (comment)

@felipeaffonsobsi
Copy link

@felipeaffonsobsi

Não consigo utilizar e ler o voto do usuário. Alguém pode me ajudar?

#2596 (comentário)

você reenviou essa página, desculpa mas isso não me ajudou.

@alechkos alechkos requested review from PurpShell and shirser121 and removed request for aliyss and shirser121 April 29, 2024 10:13
@alechkos alechkos enabled auto-merge (squash) April 29, 2024 10:20
@alechkos alechkos merged commit 01714fe into pedroslopez:main Apr 30, 2024
1 check passed
ninajika pushed a commit to KDevRev/whatsapp-web.js that referenced this pull request May 2, 2024
* Merge branch 'add-polls' into polls-ext

* added listener to poll votes

* added isUnvote property

* added option for custom message secret

* usage example updated

* added logic for catching removed votes

* usage example updated

* fixed logic for poll vote events

* temp usage example

* No more `isCurrentState`

* messageSecret converted to array

Co-authored-by: tuyuribr <[email protected]>

* docs updated

* we already have messageSecret in vote.parentMessage

* PollVote.selectedOptions changed to be similar to pollOptions

* docs fixed

* window.injectToFunction clarifications

* minor clarifications

* fix: typo

* style: fix broken link in readme file

---------

Co-authored-by: tuyuribr <[email protected]>
seowzhenjun0126 added a commit to seowzhenjun0126/whatsapp-web.js that referenced this pull request May 6, 2024
ninajika added a commit to KDevRev/whatsapp-web.js that referenced this pull request May 7, 2024
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.

Receive poll message voting How to trigger polls ??
7 participants