From 7c7851f4d471185ab3216a3ec6ca775206c52423 Mon Sep 17 00:00:00 2001 From: BenyFilho <168232825+BenyFilho@users.noreply.github.com> Date: Tue, 7 Oct 2025 16:24:05 -0300 Subject: [PATCH] feat: getPollVotes (#3807) * Add required module * Add getPollVotes function * Add getPollVotes function * Add getPollVotes function * Add Message.getPollVotes * Add Message.getPollVotes --- index.d.ts | 7 +++++++ src/Client.js | 26 ++++++++++++++++++++++++++ src/structures/Message.js | 7 +++++++ src/util/Injected/Store.js | 1 + 4 files changed, 41 insertions(+) diff --git a/index.d.ts b/index.d.ts index f46308e..07e9527 100644 --- a/index.d.ts +++ b/index.d.ts @@ -306,6 +306,9 @@ declare namespace WAWebJS { */ transferChannelOwnership(channelId: string, newOwnerId: string, options?: TransferChannelOwnershipOptions): Promise; + /** Get Poll Votes */ + getPollVotes(messageId: string): Promise + /** Generic event */ on(event: string, listener: (...args: any) => void): this @@ -1192,6 +1195,10 @@ declare namespace WAWebJS { * Gets the payment details associated with a given message */ getPayment: () => Promise, + /** + * Get Poll Votes associated with the given message + */ + getPollVotes: () => Promise, /** * Gets the reactions associated with the given message */ diff --git a/src/Client.js b/src/Client.js index 4ae134e..fce4f1a 100644 --- a/src/Client.js +++ b/src/Client.js @@ -2414,6 +2414,32 @@ class Client extends EventEmitter { return serialized; }, userId); } + + /** + * Get Poll Votes + * @param {string} messageId + * @return {Promise>} + */ + async getPollVotes(messageId) { + const msg = await this.getMessageById(messageId); + if (!msg) return []; + if (msg.type != 'poll_creation') throw 'Invalid usage! Can only be used with a pollCreation message'; + + const pollVotes = await this.pupPage.evaluate( async (msg) => { + const msgKey = window.Store.MsgKey.fromString(msg.id._serialized); + let pollVotes = await window.Store.PollsVotesSchema.getTable().equals(['parentMsgKey'], msgKey.toString()); + + return pollVotes.map(item => { + const typedArray = new Uint8Array(item.selectedOptionLocalIds); + return { + ...item, + selectedOptionLocalIds: Array.from(typedArray) + }; + }); + }, msg); + + return pollVotes.map((pollVote) => new PollVote(this.client, {...pollVote, parentMessage: msg})); + } } module.exports = Client; diff --git a/src/structures/Message.js b/src/structures/Message.js index f6ecc7a..4c43aee 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -742,6 +742,13 @@ class Message extends Base { return edittedEventMsg && new Message(this.client, edittedEventMsg); } + /** + * Returns the PollVote this poll message + * @returns {Promise} + */ + async getPollVotes() { + return await this.client.getPollVotes(this.id._serialized); + } } module.exports = Message; diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 73217b5..6d1a0c8 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -103,6 +103,7 @@ exports.ExposeStore = () => { window.Store.FindOrCreateChat = window.require('WAWebFindChatAction'); window.Store.CustomerNoteUtils = window.require('WAWebNoteAction'); window.Store.BusinessGatingUtils = window.require('WAWebBizGatingUtils'); + window.Store.PollsVotesSchema = require('WAWebPollsVotesSchema'); window.Store.Settings = { ...window.require('WAWebUserPrefsGeneral'),